Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e09bcc8

Browse files
Issue #22079: PyType_Ready() now checks that statically allocated type has
no dynamically allocated bases.
1 parent db07164 commit e09bcc8

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

Misc/NEWS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,12 @@ Build
332332

333333
- Issue #17128: Use private version of OpenSSL for 2.7.9 OS X 10.5+ installer.
334334

335+
C API
336+
-----
337+
338+
- Issue #22079: PyType_Ready() now checks that statically allocated type has
339+
no dynamically allocated bases.
340+
335341
Documentation
336342
-------------
337343

@@ -1136,6 +1142,7 @@ Build
11361142

11371143
C API
11381144
-----
1145+
11391146
- Issue #20942: PyImport_ImportFrozenModuleObject() no longer sets __file__ to
11401147
match what importlib does; this affects _frozen_importlib as well as any
11411148
module loaded using imp.init_frozen().

Objects/typeobject.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4680,6 +4680,20 @@ PyType_Ready(PyTypeObject *type)
46804680
inherit_slots(type, (PyTypeObject *)b);
46814681
}
46824682

4683+
/* All bases of statically allocated type should be statically allocated */
4684+
if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE))
4685+
for (i = 0; i < n; i++) {
4686+
PyObject *b = PyTuple_GET_ITEM(bases, i);
4687+
if (PyType_Check(b) &&
4688+
(((PyTypeObject *)b)->tp_flags & Py_TPFLAGS_HEAPTYPE)) {
4689+
PyErr_Format(PyExc_TypeError,
4690+
"type '%.100s' is not dynamically allocated but "
4691+
"its base type '%.100s' is dynamically allocated",
4692+
type->tp_name, ((PyTypeObject *)b)->tp_name);
4693+
goto error;
4694+
}
4695+
}
4696+
46834697
/* Sanity check for tp_free. */
46844698
if (PyType_IS_GC(type) && (type->tp_flags & Py_TPFLAGS_BASETYPE) &&
46854699
(type->tp_free == NULL || type->tp_free == PyObject_Del)) {

0 commit comments

Comments
 (0)