From 1f35c14dc9c29f611afebc4754592e0af729e3f4 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Sun, 13 Jan 2008 18:51:38 +0100 Subject: [PATCH] divert tp_clear()/tp_traverse() to parent type if type has no object attributes --- Cython/Compiler/TypeSlots.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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): -- 2.26.2