Skip to content

Commit 93ed162

Browse files
committed
Add missing polyglot typecasts.
1 parent 7d79596 commit 93ed162

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@ void* to_java_type(PyTypeObject* cls) {
148148

149149
__attribute__((always_inline))
150150
static inline PyObject* PyTruffle_Explicit_Cast(PyObject* cobj, unsigned long flags) {
151-
if (PyTruffle_FastSubclass(flags, Py_TPFLAGS_TUPLE_SUBCLASS)) {
151+
if (PyTruffle_FastSubclass(flags, Py_TPFLAGS_TYPE_SUBCLASS)) {
152+
return (PyObject*)polyglot_as__typeobject(cobj);
153+
} else if (PyTruffle_FastSubclass(flags, Py_TPFLAGS_TUPLE_SUBCLASS)) {
152154
return (PyObject*)polyglot_as_PyTupleObject(cobj);
153155
} else if (PyTruffle_FastSubclass(flags, Py_TPFLAGS_LIST_SUBCLASS)) {
154156
return (PyObject*)polyglot_as_PyListObject(cobj);
@@ -158,6 +160,10 @@ static inline PyObject* PyTruffle_Explicit_Cast(PyObject* cobj, unsigned long fl
158160
return (PyObject*)polyglot_as_PyUnicodeObject(cobj);
159161
} else if (PyTruffle_FastSubclass(flags, Py_TPFLAGS_BYTES_SUBCLASS)) {
160162
return (PyObject*)polyglot_as_PyBytesObject(cobj);
163+
} else if (PyTruffle_FastSubclass(flags, Py_TPFLAGS_LONG_SUBCLASS)) {
164+
return (PyObject*)polyglot_as__longobject(cobj);
165+
} else if (PyTruffle_FastSubclass(flags, Py_TPFLAGS_BASE_EXC_SUBCLASS)) {
166+
return (PyObject*)polyglot_as_PyBaseExceptionObject(cobj);
161167
}
162168
return (PyObject*)polyglot_as_PyVarObject(cobj);
163169
}
@@ -490,23 +496,23 @@ PyObject *wrap_direct(PyCFunction fun, ...) {
490496
}
491497

492498
PyObject *wrap_varargs(PyCFunction fun, PyObject *module, PyObject *varargs) {
493-
return fun(module, _explicit_cast(varargs));
499+
return fun(_explicit_cast(module), _explicit_cast(varargs));
494500
}
495501

496502
PyObject *wrap_keywords(PyCFunctionWithKeywords fun, PyObject *module, PyObject *varargs, PyObject *kwargs) {
497-
return fun(module, _explicit_cast(varargs), _explicit_cast(kwargs));
503+
return fun(_explicit_cast(module), _explicit_cast(varargs), _explicit_cast(kwargs));
498504
}
499505

500506
PyObject *wrap_noargs(PyCFunction fun, PyObject *module, PyObject *pnone) {
501-
return fun(module, pnone);
507+
return fun(_explicit_cast(module), _explicit_cast(pnone));
502508
}
503509

504510
PyObject *wrap_fastcall(_PyCFunctionFast fun, PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) {
505511
Py_ssize_t i;
506512
for (i=0; i < nargs; i++) {
507513
args[i] = _explicit_cast(args[i]);
508514
}
509-
return fun(self, args, nargs, _explicit_cast(kwnames));
515+
return fun(_explicit_cast(self), args, nargs, _explicit_cast(kwnames));
510516
}
511517

512518
PyObject *wrap_unsupported(void *fun, ...) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ typedef struct {
6565
/* Declare Python structs/types for explicit polyglot typecasts. */
6666
/* NOTE: Also add an appropriate case in 'PyTruffle_Explicit_Cast' ! */
6767
POLYGLOT_DECLARE_STRUCT(_object);
68+
POLYGLOT_DECLARE_TYPE(PyBaseExceptionObject);
6869
POLYGLOT_DECLARE_TYPE(PyModuleObject);
6970
POLYGLOT_DECLARE_TYPE(PyVarObject);
7071
POLYGLOT_DECLARE_STRUCT(_typeobject);

0 commit comments

Comments
 (0)