[docs] [issue26979] The danger of PyType_FromSpec()
Christian Tismer
report at bugs.python.org
Sat Jun 2 06:30:09 EDT 2018
Christian Tismer <tismer at stackless.com> added the comment:
There is another catch that belongs in the same category.
There is line 2841 in typeobject.c
if (type->tp_dealloc == NULL) {
/* It's a heap type, so needs the heap types' dealloc.
subtype_dealloc will call the base type's tp_dealloc, if
necessary. */
type->tp_dealloc = subtype_dealloc;
}
When converting the PySide types, it became a real problem. Types with an
existing tp_dealloc behaved normal, but those with tp_dealloc=NULL
gave segfaults. I ended up supplying a default dummy_dealloc()
that is just there to occupy this slot. Then it worked.
And another source of incompatibility:
PyType_FromSpec() enforces a tp_name field to be dotted, to compute a module
name. Very annoying incompatibility that could be avoided.
A small but remarkable glitch:
Most fields of the PyType_Spec/PyType_Slot combo are copied, but some are not.
So expect funny behaviour when creating types with dynamically generated
specs without strdup. That should IMHO be changed.
----------
nosy: +Christian.Tismer
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue26979>
_______________________________________
More information about the docs
mailing list