Skip to content

Commit 15cfe01

Browse files
committed
rebase fix
1 parent 87485e2 commit 15cfe01

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

graalpython/com.oracle.graal.python.jni/src/capi_native.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,12 +446,17 @@ void Py_IncRef(PyObject *a) {
446446
/*
447447
This is a workaround for C++ modules, namely PyTorch, that declare global/static variables with destructors that call
448448
_Py_DECREF. The destructors get called by libc during exit during which we cannot make upcalls as that would segfault.
449-
So we rebind them to no-ops when exitting.
449+
So we rebind them to no-ops when exiting.
450450
*/
451-
static void nop_Py_DecRef(PyObject* obj) {}
451+
Py_ssize_t nop_GraalPy_get_PyObject_ob_refcnt(PyObject* obj) {
452+
return 100; // large dummy refcount
453+
}
454+
void nop_GraalPy_set_PyObject_ob_refcnt(PyObject* obj, Py_ssize_t refcnt) {
455+
// do nothing
456+
}
452457
void finalizeCAPI() {
453-
__target___Py_DecRef = nop_Py_DecRef;
454-
__target__Py_DecRef = nop_Py_DecRef;
458+
GraalPy_get_PyObject_ob_refcnt = nop_GraalPy_get_PyObject_ob_refcnt;
459+
GraalPy_set_PyObject_ob_refcnt = nop_GraalPy_set_PyObject_ob_refcnt;
455460
}
456461

457462
PyObject* PyTuple_Pack(Py_ssize_t n, ...) {

0 commit comments

Comments
 (0)