3 Aug 2012 00:36
[Cython] Bad interaction between cimported types and module cleanup
Basically, the module cleanup function nullifies the type ptr of
cimported parent types, but tp_dealloc slots of children types access
these null pointers, then you get a segfault. Looking at Py_Finalize()
, atexit functions are run BEFORE a gargabe collection step and the
destroy of all modules.
<at> Stefan, I remember you also had issues with module cleanup and object
deallocation. Did you find a solution?
Could you give a quick look at the following patch? Do you think the
extra pointer deref for getting Py_TYPE(o)->tp_base->tp_dealloc would
be a performance regression? BTW, The "if 0" branch is the original
code, the else branch is my proposed fix.
diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py
index 2472de3..8758967 100644
--- a/Cython/Compiler/ModuleNode.py
+++ b/Cython/Compiler/ModuleNode.py
<at> <at> -1111,7 +1111,12 <at> <at> class ModuleNode(Nodes.Node, Nodes.BlockNode):
if base_type:
tp_dealloc = TypeSlots.get_base_slot_function(scope, tp_slot)
if tp_dealloc is None:
- tp_dealloc = "%s->tp_dealloc" % base_type.typeptr_cname
+ if 0:
+ # XXX bad interaction between
+ # cimported types and module cleanup
+ tp_dealloc = "%s->tp_dealloc" % base_type.typeptr_cname
+ else:
+ tp_dealloc = "Py_TYPE(o)->tp_base->tp_dealloc"
code.putln(
(Continue reading)
RSS Feed