File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
graalpython/com.oracle.graal.python.test/src/tests/cpyext Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -204,6 +204,32 @@ def test_new(self):
204
204
tester = TestNew ()
205
205
assert tester .get_none () is None
206
206
207
+ def test_init (self ):
208
+ TestInit = CPyExtType ("TestInit" ,
209
+ '''static PyObject* testnew_new(PyTypeObject* cls, PyObject* a, PyObject* b) {
210
+ PyObject* obj;
211
+ TestInitObject* typedObj;
212
+ obj = PyBaseObject_Type.tp_new(cls, a, b);
213
+
214
+ typedObj = ((TestInitObject*)obj);
215
+ typedObj->dict = (PyDictObject*) PyDict_Type.tp_new(&PyDict_Type, a, b);
216
+ PyDict_Type.tp_init((PyObject*) typedObj->dict, a, b);
217
+ PyDict_SetItemString((PyObject*) typedObj->dict, "test", PyLong_FromLong(42));
218
+
219
+ Py_XINCREF(obj);
220
+ return obj;
221
+ }
222
+ static PyObject* get_dict_item(PyObject* self) {
223
+ return PyDict_GetItemString((PyObject*) ((TestInitObject*)self)->dict, "test");
224
+ }
225
+ ''' ,
226
+ cmembers = "PyDictObject *dict;" ,
227
+ tp_new = "testnew_new" ,
228
+ tp_methods = '{"get_dict_item", (PyCFunction)get_dict_item, METH_NOARGS, ""}'
229
+ )
230
+ tester = TestInit ()
231
+ assert tester .get_dict_item () == 42
232
+
207
233
def test_slots (self ):
208
234
TestSlots = CPyExtType ("TestSlots" ,
209
235
'''
You can’t perform that action at this time.
0 commit comments