diff options
author | Pablo Galindo <pablogsal@gmail.com> | 2019-04-24 10:28:50 +0100 |
---|---|---|
committer | Pablo Galindo <pablogsal@gmail.com> | 2019-04-24 10:28:50 +0100 |
commit | 82b029b333b39bc5558bbae4a7f63c9ed4889f0e (patch) | |
tree | 1031250c9b81020f340b27142fdb6d7397974b24 /Cython/Compiler/ModuleNode.py | |
parent | 874a79941db81e7b2975d337de6b07f9d0f2c188 (diff) | |
download | cython-82b029b333b39bc5558bbae4a7f63c9ed4889f0e.tar.gz |
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.
Diffstat (limited to 'Cython/Compiler/ModuleNode.py')
-rw-r--r-- | Cython/Compiler/ModuleNode.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index 2b7939e84..2d4144b62 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -1475,12 +1475,16 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): UtilityCode.load_cached("PyTrashcan", "ExtensionTypes.c")) 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: + # 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);") + # call the user's __dealloc__ + self.generate_usr_dealloc_call(scope, code) + if dict_slot: code.putln("if (p->__dict__) PyDict_Clear(p->__dict__);") |