Skip to content

Commit a94e3cc

Browse files
committed
Set tp_free for managed objects to PyObject_GC_Del
1 parent 04e0fe3 commit a94e3cc

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CExtNodes.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@
4343
import static com.oracle.graal.python.builtins.objects.PNone.NO_VALUE;
4444
import static com.oracle.graal.python.builtins.objects.cext.capi.NativeCAPISymbol.FUN_PTR_ADD;
4545
import static com.oracle.graal.python.builtins.objects.cext.capi.NativeCAPISymbol.FUN_PTR_COMPARE;
46+
import static com.oracle.graal.python.builtins.objects.cext.capi.NativeCAPISymbol.FUN_PY_OBJECT_GC_DEL;
4647
import static com.oracle.graal.python.builtins.objects.cext.capi.NativeCAPISymbol.FUN_PY_TRUFFLE_MEMORYVIEW_FROM_OBJECT;
48+
import static com.oracle.graal.python.builtins.objects.cext.capi.NativeCAPISymbol.FUN_PY_TYPE_GENERIC_ALLOC;
4749
import static com.oracle.graal.python.builtins.objects.cext.structs.CConstants.PYLONG_BITS_IN_DIGIT;
4850
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyFloatObject__ob_fval;
4951
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyMethodDef__ml_doc;
@@ -872,16 +874,19 @@ public static PCallCapiFunction getUncached() {
872874
*/
873875
@TruffleBoundary
874876
public static Object lookupNativeMemberInMRO(PythonManagedClass cls, @SuppressWarnings("unused") CFields nativeMemberName, HiddenAttr managedMemberName) {
875-
if (cls instanceof PythonClass && (managedMemberName == HiddenAttr.ALLOC || managedMemberName == HiddenAttr.DEL)) {
877+
if (cls instanceof PythonClass && (managedMemberName == HiddenAttr.ALLOC || managedMemberName == HiddenAttr.FREE)) {
876878
Object func = HiddenAttr.ReadNode.executeUncached(cls, managedMemberName, null);
877879
if (func != null) {
878880
return func;
879881
}
880-
PythonObject object = PythonContext.get(null).lookupType(PythonBuiltinClassType.PythonObject);
881882
// We need to point to PyType_GenericAlloc or PyObject_GC_Del
882-
func = HiddenAttr.ReadNode.executeUncached(object, managedMemberName, NO_VALUE);
883-
HiddenAttr.WriteNode.executeUncached(cls, managedMemberName, func);
884-
return func;
883+
NativeCAPISymbol symbol;
884+
if (managedMemberName == HiddenAttr.ALLOC) {
885+
symbol = FUN_PY_TYPE_GENERIC_ALLOC;
886+
} else {
887+
symbol = FUN_PY_OBJECT_GC_DEL;
888+
}
889+
return CApiContext.getNativeSymbol(null, symbol);
885890
}
886891
MroSequenceStorage mroStorage = GetMroStorageNode.executeUncached(cls);
887892
int n = mroStorage.length();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/NativeCAPISymbol.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ public enum NativeCAPISymbol implements NativeCExtSymbol {
129129
FUN_PY_OBJECT_GENERIC_SET_DICT("PyObject_GenericSetDict", Int, PyObject, PyObject, Pointer),
130130
FUN_PY_OBJECT_NEW("PyTruffle_Object_New", PyObject, PyTypeObject),
131131
FUN_PY_TYPE_READY("PyType_Ready", Int, PyTypeObject),
132+
FUN_PY_TYPE_GENERIC_ALLOC("PyType_GenericAlloc", PyObject, PyTypeObject, Py_ssize_t),
133+
FUN_PY_OBJECT_GC_DEL("PyObject_GC_Del", Void, Pointer),
132134
FUN_GET_BUFFER_R("get_buffer_r", Int, PyObject, Pointer),
133135
FUN_GET_BUFFER_RW("get_buffer_rw", Int, PyObject, Pointer),
134136
FUN_CONVERTBUFFER("convertbuffer", Py_ssize_t, PyObject, Pointer),

0 commit comments

Comments
 (0)