Commit 82b029b3 authored by Pablo Galindo's avatar Pablo Galindo

Clean weakrefs before calling user's dealloc

We must clean the weakreferences before calling the user's __dealloc__
because if the __dealloc__ releases the GIL, a weakref can be
dereferenced accessing the object in an inconsistent state or
resurrecting it.
parent 874a7994
...@@ -1475,12 +1475,16 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1475,12 +1475,16 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
UtilityCode.load_cached("PyTrashcan", "ExtensionTypes.c")) UtilityCode.load_cached("PyTrashcan", "ExtensionTypes.c"))
code.putln("__Pyx_TRASHCAN_BEGIN(o, %s)" % slot_func_cname) code.putln("__Pyx_TRASHCAN_BEGIN(o, %s)" % slot_func_cname)
# call the user's __dealloc__
self.generate_usr_dealloc_call(scope, code)
if weakref_slot: if weakref_slot:
# We must clean the weakreferences before calling the user's __dealloc__
# because if the __dealloc__ releases the GIL, a weakref can be
# dereferenced accessing the object in an inconsistent state or
# resurrecting it.
code.putln("if (p->__weakref__) PyObject_ClearWeakRefs(o);") code.putln("if (p->__weakref__) PyObject_ClearWeakRefs(o);")
# call the user's __dealloc__
self.generate_usr_dealloc_call(scope, code)
if dict_slot: if dict_slot:
code.putln("if (p->__dict__) PyDict_Clear(p->__dict__);") code.putln("if (p->__dict__) PyDict_Clear(p->__dict__);")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment