[Cython] Bad interaction between cimported types and module cleanup

Stefan Behnel stefan_ml at behnel.de
Sat Aug 4 14:59:38 CEST 2012


Lisandro Dalcin, 03.08.2012 18:51:
> diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py
> index 2472de3..255b047 100644
> --- a/Cython/Compiler/ModuleNode.py
> +++ b/Cython/Compiler/ModuleNode.py
> @@ -1111,7 +1111,11 @@ 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
> +                # Using the cimported base type pointer interacts
> +                # badly with module cleanup nullyfing these pointers.
> +                # Use instead the base type pointer from the
> +                # instance's type pointer.
> +                tp_dealloc = "Py_TYPE(o)->tp_base->tp_dealloc"
>              code.putln(
>                      "%s(o);" % tp_dealloc)
>          else:

Tried it, doesn't work. The problem is that this always goes through the
actual type of the object, ignoring the type hierarchy completely, which
kills the tp_dealloc() call chain and runs into an infinite loop starting
from the second inheritance level (or a crash because of multiple DECREF
calls on the same fields).

Stefan



More information about the cython-devel mailing list