[New-bugs-announce] [issue15727] PyType_FromSpecWithBases tp_new bugfix

Robin Schreiber report at bugs.python.org
Sun Aug 19 17:57:46 CEST 2012


New submission from Robin Schreiber:

As with every type, that has been created and initialized, HeapTypes created form PyType_FromSpecWithBases() have to pass through PyType_Ready(). Here the function inherit_special might be called, which, among other things, does the following:
....
3892         if (base != &PyBaseObject_Type ||                                                                                                                
3893             (type->tp_flags & Py_TPFLAGS_HEAPTYPE)) {
3894             if (type->tp_new == NULL)
3895                 type->tp_new = base->tp_new;
3896         }
....
The code does not know of Heaptypes that have been created from extension-types by the PEP 384 refactorings. This includes extension-types that do not specify a tp_new method but instead have seperate factory methods, that are only used within the extension module. inherit_special() might consequently assign inappropriate new-methods to these type objects.

To circumvent this issue, I propose to enhance PyType_FromSpecWithBases in the following way: If no tp_new has been specified, we assign the newly defined PySpec_New() method to tp_new which simply denies the user to create an instance of this type. This also prohibits inherit_special to falsely inherit inappropriate new-methods.

----------
components: Interpreter Core
files: PyType_FromSpecWithBases_tp_new_fix.patch
keywords: patch
messages: 168579
nosy: Robin.Schreiber, loewis
priority: normal
severity: normal
status: open
title: PyType_FromSpecWithBases tp_new bugfix
type: behavior
versions: Python 3.4
Added file: http://bugs.python.org/file26897/PyType_FromSpecWithBases_tp_new_fix.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15727>
_______________________________________


More information about the New-bugs-announce mailing list