[Python-checkins] cpython (merge 3.4 -> default): Issue #22079: PyType_Ready() now checks that statically allocated type has

serhiy.storchaka python-checkins at python.org
Wed Jan 28 10:10:28 CET 2015


https://hg.python.org/cpython/rev/eb26255e11f1
changeset:   94350:eb26255e11f1
parent:      94347:1df1fde8f360
parent:      94349:747855f29b9d
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Wed Jan 28 11:06:04 2015 +0200
summary:
  Issue #22079: PyType_Ready() now checks that statically allocated type has
no dynamically allocated bases.

files:
  Misc/NEWS            |   3 +++
  Objects/typeobject.c |  14 ++++++++++++++
  2 files changed, 17 insertions(+), 0 deletions(-)


diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -1519,6 +1519,9 @@
 C API
 -----
 
+- Issue #22079: PyType_Ready() now checks that statically allocated type has
+  no dynamically allocated bases.
+
 - Issue #22453: Removed non-documented macro PyObject_REPR().
 
 - Issue #18395: Rename ``_Py_char2wchar()`` to :c:func:`Py_DecodeLocale`,
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -4683,6 +4683,20 @@
             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)) {

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list