Skip to content

Commit 3c53f43

Browse files
committed
avoid native_to_java for get_ob_type and use the local knowledge we have
1 parent 1a0f46c commit 3c53f43

File tree

1 file changed

+13
-1
lines changed
  • graalpython/com.oracle.graal.python.cext/src

1 file changed

+13
-1
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,19 @@ PyObject* to_sulong(void *o) {
226226

227227
/** to be used from Java code only; reads native 'ob_type' field */
228228
void* get_ob_type(PyObject* obj) {
229-
return native_to_java((PyObject*)(obj->ob_type));
229+
PyTypeObject* type = obj->ob_type;
230+
if (truffle_is_handle_to_managed(type)) {
231+
return truffle_managed_from_handle(type);
232+
} else {
233+
// we have stored a handle to the Java class in ob_refcnt
234+
void* handle = (void*)type->ob_refcnt;
235+
if (truffle_is_handle_to_managed(handle)) {
236+
return truffle_managed_from_handle(handle);
237+
} else {
238+
// assume handle is a TruffleObject
239+
return handle;
240+
}
241+
}
230242
}
231243

232244
/** to be used from Java code only; returns the type ID for a byte array */

0 commit comments

Comments
 (0)