Skip to content

Commit 707bfc2

Browse files
committed
Add test case for using a type without calling PyType_Ready
1 parent 7c554c5 commit 707bfc2

File tree

1 file changed

+28
-0
lines changed
  • graalpython/com.oracle.graal.python.test/src/tests/cpyext

1 file changed

+28
-0
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,34 @@ def test_inheret_numbers_slots(self):
305305
assert X.B_has_add_slot()
306306
assert Y.E_has_add_slot()
307307

308+
def test_managed_class_with_native_base(self):
309+
NativeModule = CPyExtType("NativeModule_",
310+
'''
311+
PyTypeObject NativeBase_Type = {
312+
PyVarObject_HEAD_INIT(&PyType_Type, 0)
313+
.tp_name = "NativeModule_.NativeBase",
314+
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
315+
.tp_base = &PyModule_Type,
316+
};
317+
318+
static PyObject* get_NativeBase_type(PyObject* cls) {
319+
return (PyObject*) &NativeBase_Type;
320+
}
321+
322+
''',
323+
tp_methods='''{"get_NativeBase_type", (PyCFunction)get_NativeBase_type, METH_NOARGS | METH_CLASS, ""}''',
324+
ready_code='''
325+
/* testing lazy type initialization */
326+
// if (PyType_Ready(&NativeBase_Type) < 0)
327+
// return NULL;
328+
''',
329+
)
330+
NativeBase = NativeModule.get_NativeBase_type()
331+
assert NativeBase
332+
class ManagedType(NativeBase):
333+
def __init__(self):
334+
super(ManagedType, self).__init__("DummyModuleName")
335+
assert ManagedType()
308336

309337
def test_index(self):
310338
TestIndex = CPyExtType("TestIndex",

0 commit comments

Comments
 (0)