From: Stefan Behnel Date: Sun, 13 Jan 2008 17:51:38 +0000 (+0100) Subject: divert tp_clear()/tp_traverse() to parent type if type has no object attributes X-Git-Tag: 0.9.6.14~29^2~62^2~10 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=1f35c14dc9c29f611afebc4754592e0af729e3f4;p=cython.git divert tp_clear()/tp_traverse() to parent type if type has no object attributes --- diff --git a/Cython/Compiler/TypeSlots.py b/Cython/Compiler/TypeSlots.py index faf14793..f68daa01 100644 --- a/Cython/Compiler/TypeSlots.py +++ b/Cython/Compiler/TypeSlots.py @@ -220,10 +220,16 @@ class GCDependentSlot(InternalMethodSlot): InternalMethodSlot.__init__(self, slot_name) def slot_code(self, scope): - if scope.needs_gc(): - return InternalMethodSlot.slot_code(self, scope) - else: + if not scope.needs_gc(): return "0" + if not scope.has_pyobject_attrs: + # if the type does not have object attributes, it can + # delegate GC methods to its parent - iff the parent + # functions are defined in the same module + parent_type_scope = scope.parent_type.base_type.scope + if scope.parent_scope is parent_type_scope.parent_scope: + return self.slot_code(parent_type_scope) + return InternalMethodSlot.slot_code(self, scope) class SyntheticSlot(InternalMethodSlot):