divert tp_clear()/tp_traverse() to parent type if type has no object attributes
authorStefan Behnel <scoder@users.berlios.de>
Sun, 13 Jan 2008 17:51:38 +0000 (18:51 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Sun, 13 Jan 2008 17:51:38 +0000 (18:51 +0100)
Cython/Compiler/TypeSlots.py

index faf14793b09b292d28b4113b07f7dee6b335f18d..f68daa0188cf12c07377a63d1e4a1cc49f5a4ae9 100644 (file)
@@ -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):