]> 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 08:52:49 +0000 (10:52 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Wed, 28 Jan 2015 08:52:49 +0000 (10:52 +0200)
no dynamically allocated bases.

Misc/NEWS
Objects/typeobject.c

index c08951ef8be3356f678fd97192b2de1a736d430e..2256bf835dd02a92f41241986609e30004229799 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -117,6 +117,12 @@ Build
 
 - Issue #23212: Update 10.5 OS X installer build to use OpenSSL 1.0.1k.
 
+C API
+-----
+
+- Issue #22079: PyType_Ready() now checks that statically allocated type has
+  no dynamically allocated bases.
+
 
 What's New in Python 2.7.9?
 ===========================
index 619ac9be1725b4e9c6a3cfcfccaf905a72e0e0bb..23dda2ac93bad84ba4aca00c6f76faf5373f50d4 100644 (file)
@@ -4073,6 +4073,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)) {