Skip to content

Commit 62e55f4

Browse files
committed
Add Python landing function for primitive double return value.
1 parent acc1215 commit 62e55f4

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void* handle_exception(void* val);
9898
#define PY_TRUFFLE_LANDING ((PyObject*(*)(void *rcv, void* name, ...))polyglot_get_member(PY_TRUFFLE_CEXT, polyglot_from_string("PyTruffle_Upcall", SRC_CS)))
9999
#define PY_TRUFFLE_CEXT_LANDING ((PyObject*(*)(void* name, ...))polyglot_get_member(PY_TRUFFLE_CEXT, polyglot_from_string("PyTruffle_Cext_Upcall", SRC_CS)))
100100
#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)))
101+
#define PY_TRUFFLE_CEXT_LANDING_D ((double (*)(void* name, ...))polyglot_get_member(PY_TRUFFLE_CEXT, polyglot_from_string("PyTruffle_Cext_Upcall_d", SRC_CS)))
102102
#define UPCALL_O(__recv__, __name__, ...) handle_exception_and_cast(PY_TRUFFLE_LANDING((__recv__), polyglot_from_string((__name__), SRC_CS), __VA_ARGS__))
103103
#define UPCALL_CEXT_O(__name__, ...) handle_exception_and_cast(PY_TRUFFLE_CEXT_LANDING(polyglot_from_string((__name__), SRC_CS), ##__VA_ARGS__))
104104
#define UPCALL_CEXT_VOID(__name__, ...) (PY_TRUFFLE_CEXT_LANDING(polyglot_from_string((__name__), SRC_CS), ##__VA_ARGS__))

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/TruffleCextBuiltins.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,9 @@ long run(double value) {
214214
}
215215

216216
@Specialization
217-
@TruffleBoundary
218217
long run(PInt value) {
219-
return value.getValue().longValue();
218+
// TODO(fa) longValueExact ?
219+
return value.longValue();
220220
}
221221

222222
@Specialization
@@ -227,9 +227,16 @@ long run(PFloat value) {
227227
@Specialization
228228
Object run(PythonNativeWrapper value,
229229
@Cached("create()") AsLong recursive) {
230+
// TODO(fa) this specialization should eventually go away
230231
return recursive.executeWith(value.getDelegate());
231232
}
232233

234+
@Fallback
235+
Object runGeneric(Object value) {
236+
// TODO(fa) force primitive
237+
return getIntNode().executeWith(getCore().lookupType(Integer.class), value, PNone.NONE);
238+
}
239+
233240
private BuiltinConstructors.IntNode getIntNode() {
234241
if (intNode == null) {
235242
CompilerDirectives.transferToInterpreterAndInvalidate();
@@ -238,11 +245,6 @@ private BuiltinConstructors.IntNode getIntNode() {
238245
return intNode;
239246
}
240247

241-
@Fallback
242-
Object runGeneric(Object value) {
243-
return getIntNode().executeWith(getCore().lookupType(Integer.class), value, PNone.NONE);
244-
}
245-
246248
static AsLong create() {
247249
return TruffleCextBuiltinsFactory.AsLongFactory.create(null);
248250
}
@@ -274,9 +276,8 @@ abstract static class AsDouble extends PythonBuiltinNode {
274276
}
275277

276278
@Specialization
277-
@TruffleBoundary
278279
double run(PInt value) {
279-
return value.getValue().doubleValue();
280+
return value.doubleValue();
280281
}
281282

282283
@Specialization

graalpython/lib-graalpython/python_cext.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1178,4 +1178,12 @@ def PyTruffle_Cext_Upcall_l(name, *args):
11781178
converted = [None] * nargs
11791179
for i in range(nargs):
11801180
converted[i] = to_java(args[i])
1181-
return globals()[name](*converted)
1181+
return to_long(globals()[name](*converted))
1182+
1183+
1184+
def PyTruffle_Cext_Upcall_d(name, *args):
1185+
nargs = len(args)
1186+
converted = [None] * nargs
1187+
for i in range(nargs):
1188+
converted[i] = to_java(args[i])
1189+
return to_double(globals()[name](*converted))

0 commit comments

Comments
 (0)