Commit d5da2dbc authored by Stefan Behnel's avatar Stefan Behnel Committed by GitHub

Merge pull request #2930 from pablogsal/2929

Clean weakrefs before calling user's dealloc
parents eb40e5d1 82b029b3
...@@ -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