Commit 9a08ff23 authored by Robert Bradshaw's avatar Robert Bradshaw

Guard deallocation with PyObject_GC_Untrack, trac #796.

parent c0bc7e85
......@@ -1127,6 +1127,11 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
or memoryview_slices
or weakref_slot in scope.var_entries):
self.generate_self_cast(scope, code)
# We must mark ths object as (gc) untracked while tearing it down, lest
# the garbage collection is invoked while running this destructor.
if scope.needs_gc():
code.putln("PyObject_GC_UnTrack(o);");
# call the user's __dealloc__
self.generate_usr_dealloc_call(scope, code)
......@@ -1151,6 +1156,11 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.put_xdecref_memoryviewslice("p->%s" % entry.cname,
have_gil=True)
# The base class deallocator probably expects this to be tracked, so
# undo the untracking above.
if scope.needs_gc():
code.putln("PyObject_GC_Track(o);");
if base_type:
tp_dealloc = TypeSlots.get_base_slot_function(scope, tp_slot)
if tp_dealloc is not None:
......
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