Author: Sam Edwards <[email protected]>
Branch:
Changeset: r97994:c5b62ebd9ccd
Date: 2019-11-06 16:51 -0700
http://bitbucket.org/pypy/pypy/changeset/c5b62ebd9ccd/
Log: cpyext: Respect tp_dict on PyType_Ready
diff --git a/pypy/module/cpyext/test/test_typeobject.py
b/pypy/module/cpyext/test/test_typeobject.py
--- a/pypy/module/cpyext/test/test_typeobject.py
+++ b/pypy/module/cpyext/test/test_typeobject.py
@@ -452,6 +452,30 @@
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",
diff --git a/pypy/module/cpyext/typeobject.py b/pypy/module/cpyext/typeobject.py
--- a/pypy/module/cpyext/typeobject.py
+++ b/pypy/module/cpyext/typeobject.py
@@ -538,6 +538,13 @@
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:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit