[Cython] Bad interaction between cimported types and module cleanup
Lisandro Dalcin
dalcinl at gmail.com
Fri Aug 3 00:36:55 CEST 2012
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.
@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
@@ -1111,7 +1111,12 @@ 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(
"%s(o);" % tp_dealloc)
else:
--
Lisandro Dalcin
---------------
CIMEC (INTEC/CONICET-UNL)
Predio CONICET-Santa Fe
Colectora RN 168 Km 472, Paraje El Pozo
3000 Santa Fe, Argentina
Tel: +54-342-4511594 (ext 1011)
Tel/Fax: +54-342-4511169
More information about the cython-devel
mailing list