]> granicus.if.org Git - python/commitdiff
Issue #22079: PyType_Ready() now checks that statically allocated type has
authorSerhiy Storchaka <storchaka@gmail.com>
Wed, 28 Jan 2015 09:03:33 +0000 (11:03 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Wed, 28 Jan 2015 09:03:33 +0000 (11:03 +0200)
no dynamically allocated bases.

Misc/NEWS
Objects/typeobject.c

index bf643d083f77d534b86f8eadacd021229b782a81..f21c2b8459ea5372c695cb6be7d21075191aa531 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -332,6 +332,12 @@ Build
 
 - Issue #17128: Use private version of OpenSSL for 2.7.9 OS X 10.5+ installer.
 
+C API
+-----
+
+- Issue #22079: PyType_Ready() now checks that statically allocated type has
+  no dynamically allocated bases.
+
 Documentation
 -------------
 
@@ -1136,6 +1142,7 @@ Build
 
 C API
 -----
+
 - Issue #20942: PyImport_ImportFrozenModuleObject() no longer sets __file__ to
   match what importlib does; this affects _frozen_importlib as well as any
   module loaded using imp.init_frozen().
index 1d98fc2405e4be460fbcebc1b517de8b35130b77..453bb50ad39b1c499ee0e63fcbc7983cf7e68f96 100644 (file)
@@ -4680,6 +4680,20 @@ PyType_Ready(PyTypeObject *type)
             inherit_slots(type, (PyTypeObject *)b);
     }
 
+    /* All bases of statically allocated type should be statically allocated */
+    if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE))
+        for (i = 0; i < n; i++) {
+            PyObject *b = PyTuple_GET_ITEM(bases, i);
+            if (PyType_Check(b) &&
+                (((PyTypeObject *)b)->tp_flags & Py_TPFLAGS_HEAPTYPE)) {
+                PyErr_Format(PyExc_TypeError,
+                             "type '%.100s' is not dynamically allocated but "
+                             "its base type '%.100s' is dynamically allocated",
+                             type->tp_name, ((PyTypeObject *)b)->tp_name);
+                goto error;
+            }
+        }
+
     /* Sanity check for tp_free. */
     if (PyType_IS_GC(type) && (type->tp_flags & Py_TPFLAGS_BASETYPE) &&
         (type->tp_free == NULL || type->tp_free == PyObject_Del)) {