Read about our upcoming Code of Conduct on this issue

Commit 2d849e81 authored by Sam Edwards's avatar Sam Edwards
Browse files

cpyext: Respect tp_dict on PyType_Ready

parent d6cb99c41e47
......@@ -452,6 +452,30 @@ class AppTestTypeObject(AppTestCpythonExtensionBase):
assert module.hack_tp_dict(obj, "b") == 2
def test_tp_dict_ready(self):
module = self.import_extension('foo', [
("new_obj", "METH_NOARGS",
'''
PyObject *obj;
obj = PyObject_New(PyObject, &Foo_Type);
return obj;
'''
)], prologue='''
static PyTypeObject Foo_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
"foo.foo",
};
''', more_init = '''
Foo_Type.tp_flags = Py_TPFLAGS_DEFAULT;
Foo_Type.tp_dict = PyDict_New();
PyDict_SetItemString(Foo_Type.tp_dict, "inserted", Py_True);
if (PyType_Ready(&Foo_Type) < 0) INITERROR;
''')
obj = module.new_obj()
assert type(obj).inserted is True
def test_tp_descr_get(self):
module = self.import_extension('foo', [
("tp_descr_get", "METH_O",
......
......@@ -538,6 +538,13 @@ class W_PyCTypeObject(W_TypeObject):
convert_getset_defs(space, dict_w, pto.c_tp_getset, self)
convert_member_defs(space, dict_w, pto.c_tp_members, self)
w_dict = from_ref(space, pto.c_tp_dict)
if w_dict is not None:
dictkeys_w = space.listview(w_dict)
for w_key in dictkeys_w:
key = space.text_w(w_key)
dict_w[key] = space.getitem(w_dict, w_key)
name = rffi.charp2str(cts.cast('char*', pto.c_tp_name))
flag_heaptype = pto.c_tp_flags & Py_TPFLAGS_HEAPTYPE
if flag_heaptype:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment