Skip to content

Commit f0854a8

Browse files
committed
Refactor 'floatobject.c'.
1 parent 8fff8bf commit f0854a8

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

graalpython/com.oracle.graal.python.cext/src/capi.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ POLYGLOT_DECLARE_TYPE(PyCapsule);
8888
POLYGLOT_DECLARE_TYPE(PyMemoryViewObject);
8989
POLYGLOT_DECLARE_TYPE(PySetObject);
9090
POLYGLOT_DECLARE_TYPE(PyBufferDecorator);
91+
POLYGLOT_DECLARE_TYPE(PyFloatObject);
92+
9193

9294
PyObject* handle_exception_and_cast(void* val);
9395
void* handle_exception(void* val);
@@ -96,13 +98,15 @@ void* handle_exception(void* val);
9698
#define PY_TRUFFLE_LANDING ((PyObject*(*)(void *rcv, void* name, ...))polyglot_get_member(PY_TRUFFLE_CEXT, polyglot_from_string("PyTruffle_Upcall", SRC_CS)))
9799
#define PY_TRUFFLE_CEXT_LANDING ((PyObject*(*)(void* name, ...))polyglot_get_member(PY_TRUFFLE_CEXT, polyglot_from_string("PyTruffle_Cext_Upcall", SRC_CS)))
98100
#define PY_TRUFFLE_CEXT_LANDING_L ((uint64_t (*)(void* name, ...))polyglot_get_member(PY_TRUFFLE_CEXT, polyglot_from_string("PyTruffle_Cext_Upcall_l", SRC_CS)))
101+
#define PY_TRUFFLE_CEXT_LANDING_D ((double (*)(void* name, ...))polyglot_get_member(PY_TRUFFLE_CEXT, polyglot_from_string("PyTruffle_Cext_Upcall_l", SRC_CS)))
99102
#define UPCALL_O(__recv__, __name__, ...) handle_exception_and_cast(PY_TRUFFLE_LANDING((__recv__), polyglot_from_string((__name__), SRC_CS), __VA_ARGS__))
100103
#define UPCALL_CEXT_O(__name__, ...) handle_exception_and_cast(PY_TRUFFLE_CEXT_LANDING(polyglot_from_string((__name__), SRC_CS), ##__VA_ARGS__))
101104
#define UPCALL_CEXT_VOID(__name__, ...) (PY_TRUFFLE_CEXT_LANDING(polyglot_from_string((__name__), SRC_CS), ##__VA_ARGS__))
102105
#define UPCALL_CEXT_PTR(__name__, ...) handle_exception(PY_TRUFFLE_CEXT_LANDING(polyglot_from_string((__name__), SRC_CS), ##__VA_ARGS__))
103106
#define UPCALL_CEXT_P(__name__, ...) (PY_TRUFFLE_CEXT_LANDING_L(polyglot_from_string((__name__), SRC_CS), ##__VA_ARGS__))
104107
#define UPCALL_CEXT_I(__name__, ...) UPCALL_CEXT_P(__name__, ##__VA_ARGS__)
105108
#define UPCALL_CEXT_L(__name__, ...) UPCALL_CEXT_P(__name__, ##__VA_ARGS__)
109+
#define UPCALL_CEXT_D(__name__, ...) (PY_TRUFFLE_CEXT_LANDING_D(polyglot_from_string((__name__), SRC_CS), ##__VA_ARGS__))
106110

107111
void* native_to_java(PyObject* obj);
108112
extern void* to_java(PyObject* obj);

graalpython/com.oracle.graal.python.cext/src/floatobject.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,9 @@ double PyFloat_AsDouble(PyObject *op) {
4646
PyErr_BadArgument();
4747
return -1.0;
4848
}
49-
50-
return truffle_invoke_d(PY_TRUFFLE_CEXT, "PyFloat_AsPrimitive", to_java(op));
49+
return UPCALL_CEXT_D("PyFloat_AsPrimitive", native_to_java(op));
5150
}
5251

5352
PyObject* PyFloat_FromDouble(double fval) {
54-
PyObject *result = truffle_invoke(PY_TRUFFLE_CEXT, "PyFloat_FromDouble", fval);
55-
if (result == ERROR_MARKER) {
56-
return NULL;
57-
}
58-
return to_sulong(result);
53+
return polyglot_as_PyFloatObject(UPCALL_CEXT_O("PyFloat_FromDouble", fval));
5954
}

0 commit comments

Comments
 (0)