Skip to content

Commit f8b4d55

Browse files
committed
[GR-47888] Add missing tp_alloc to type class
PullRequest: graalpython/2912
2 parents b9c5641 + dcb02e9 commit f8b4d55

File tree

2 files changed

+13
-1
lines changed
  • graalpython

2 files changed

+13
-1
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
@@ -800,7 +800,7 @@ extern size_t PyTruffle_NativeMemoryGCBarrier;
800800
#undef bool // may be defined as "_Bool"
801801
// alphabetical, but base types first
802802
#define PY_TYPE_OBJECTS \
803-
PY_TRUFFLE_TYPE_WITH_ITEMSIZE(PyType_Type, type, &PyType_Type, sizeof(PyHeapTypeObject), sizeof(PyMemberDef)) \
803+
PY_TRUFFLE_TYPE_GENERIC(PyType_Type, type, &PyType_Type, sizeof(PyHeapTypeObject), sizeof(PyMemberDef), PyType_GenericAlloc, object_dealloc, PyObject_GC_Del, 0) \
804804
PY_TRUFFLE_TYPE_WITH_ALLOC(PyBaseObject_Type, object, &PyType_Type, sizeof(PyObject), PyType_GenericAlloc, object_dealloc, PyObject_Del) \
805805
PY_TRUFFLE_TYPE(PyCFunction_Type, builtin_function_or_method, &PyType_Type, sizeof(PyCFunctionObject)) \
806806
PY_TRUFFLE_TYPE(_PyBytesIOBuffer_Type, _BytesIOBuffer, &PyType_Type, 0) \

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_object.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,18 @@ class MyClass:
587587
assert tester.get_tp_name(int) == 'int'
588588
assert tester.get_tp_name(type(tester)) == 'TestTpName.TestTpName'
589589

590+
def test_tp_alloc(self):
591+
TestTpAlloc = CPyExtType("TestTpAlloc",
592+
'''
593+
static PyObject* testslots_tp_alloc(PyObject* self) {
594+
return (PyObject*) PyType_Type.tp_alloc(&PyType_Type, 0);
595+
}
596+
''',
597+
tp_methods='{"get_tp_alloc", (PyCFunction)testslots_tp_alloc, METH_NOARGS, ""}',
598+
)
599+
tester = TestTpAlloc()
600+
assert tester.get_tp_alloc() != None
601+
590602
def test_slots_initialized(self):
591603
TestSlotsInitialized = CPyExtType("TestSlotsInitialized",
592604
'''

0 commit comments

Comments
 (0)