Author: Matti Picus <[email protected]>
Branch:
Changeset: r88960:c95db94fc6a8
Date: 2016-12-07 23:26 +0200
http://bitbucket.org/pypy/pypy/changeset/c95db94fc6a8/
Log: test, fix for issue #2245 - unecessarily creating new layouts for
PyHeapTypeObjjects
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
@@ -1173,37 +1173,32 @@
("new_obj", "METH_NOARGS",
'''
PyObject *obj;
- obj = PyObject_New(PyObject, &Foo12_Type);
+ PyTypeObject *Base1, *Base2, *Base12;
+ Base1 = (PyTypeObject*)PyType_Type.tp_alloc(&PyType_Type, 0);
+ Base2 = (PyTypeObject*)PyType_Type.tp_alloc(&PyType_Type, 0);
+ Base12 = (PyTypeObject*)PyType_Type.tp_alloc(&PyType_Type, 0);
+ Base1->tp_name = "Base1";
+ Base2->tp_name = "Base2";
+ Base12->tp_name = "Base12";
+ Base1->tp_basicsize = sizeof(PyHeapTypeObject);
+ Base2->tp_basicsize = sizeof(PyHeapTypeObject);
+ Base12->tp_basicsize = sizeof(PyHeapTypeObject);
+ Base1->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
Py_TPFLAGS_HEAPTYPE;
+ Base2->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
Py_TPFLAGS_HEAPTYPE;
+ Base12->tp_flags = Py_TPFLAGS_DEFAULT;
+ Base12->tp_base = Base1;
+ Base12->tp_bases = PyTuple_Pack(2, Base1, Base2);
+ Base12->tp_doc = "The Base12 type or object";
+ if (PyType_Ready(Base1) < 0) return NULL;
+ if (PyType_Ready(Base2) < 0) return NULL;
+ if (PyType_Ready(Base12) < 0) return NULL;
+ obj = PyObject_New(PyObject, Base12);
return obj;
'''
- )], prologue='''
- static PyTypeObject Foo1_Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "foo.foo1",
- };
- static PyTypeObject Foo2_Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "foo.foo2",
- };
- static PyTypeObject Foo12_Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "foo.foo12",
- };
- static char doc[]="The foo12 object";
- ''', more_init = '''
- Foo1_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
- Foo2_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
- Foo12_Type.tp_flags = Py_TPFLAGS_DEFAULT;
- Foo12_Type.tp_base = &Foo1_Type;
- Foo12_Type.tp_doc = doc;
- Foo12_Type.tp_bases = PyTuple_Pack(2, &Foo1_Type, &Foo2_Type);
- if (PyType_Ready(&Foo1_Type) < 0) INITERROR;
- if (PyType_Ready(&Foo2_Type) < 0) INITERROR;
- if (PyType_Ready(&Foo12_Type) < 0) INITERROR;
- ''')
+ )])
obj = module.new_obj()
- assert 'foo.foo12' in str(obj)
- assert type(obj).__doc__ == "The foo12 object"
- assert obj.__doc__ == "The foo12 object"
+ assert 'Base12' in str(obj)
+ assert type(obj).__doc__ == "The Base12 type or object"
+ assert obj.__doc__ == "The Base12 type or object"
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
@@ -465,13 +465,17 @@
convert_member_defs(space, dict_w, pto.c_tp_members, self)
name = rffi.charp2str(pto.c_tp_name)
- new_layout = (pto.c_tp_basicsize > rffi.sizeof(PyObject.TO) or
- pto.c_tp_itemsize > 0)
+ flag_heaptype = pto.c_tp_flags & Py_TPFLAGS_HEAPTYPE
+ if flag_heaptype:
+ minsize = rffi.sizeof(PyHeapTypeObject.TO)
+ else:
+ minsize = rffi.sizeof(PyObject.TO)
+ new_layout = (pto.c_tp_basicsize > minsize or pto.c_tp_itemsize > 0)
W_TypeObject.__init__(self, space, name,
bases_w or [space.w_object], dict_w, force_new_layout=new_layout)
self.flag_cpytype = True
- self.flag_heaptype = pto.c_tp_flags & Py_TPFLAGS_HEAPTYPE
+ self.flag_heaptype = flag_heaptype
# if a sequence or a mapping, then set the flag to force it
if pto.c_tp_as_sequence and pto.c_tp_as_sequence.c_sq_item:
self.flag_map_or_seq = 'S'
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit