[Pyrex] Weakrefs patch, take 2

Peter Johnson peter at tortall.net
Wed Mar 28 04:52:44 UTC 2007


Sorry for taking so long to notice this, but it appears that part of my 
previous weakrefs patch 
(http://lists.copyleft.no/pipermail/pyrex/2006-December/002092.html) did 
not get applied to Pyrex.  The parts of the patch that were missed deal 
with traverse and clear code generation.

The clear code is really the critical case, as generating clear code for 
__weakref__ messes up reference counting, resulting in a nasty assertion 
from the Python garbage collector:
     visit_decref: Assertion `gc->gc.gc_refs != 0' failed.

The attached patch (against 0.9.5.1) fixes the issue by not generating 
traverse and clear code for __weakref__.

Thanks,
Peter Johnson
-------------- next part --------------
--- Compiler/ModuleNode.py.orig	Fri Jan 26 20:21:03 2007
+++ Compiler/ModuleNode.py	Tue Mar 27 21:42:40 2007
@@ -519,7 +519,7 @@
                 % scope.mangle_internal("tp_traverse"))
         py_attrs = []
         for entry in scope.var_entries:
-            if entry.type.is_pyobject:
+            if entry.type.is_pyobject and entry.name <> "__weakref__":
                 py_attrs.append(entry)
         if base_type or py_attrs:
             code.putln(
@@ -555,7 +555,7 @@
                 % scope.mangle_internal("tp_clear"))
         py_attrs = []
         for entry in scope.var_entries:
-            if entry.type.is_pyobject:
+            if entry.type.is_pyobject and entry.name <> "__weakref__":
                 py_attrs.append(entry)
         if py_attrs:
             self.generate_self_cast(scope, code)


More information about the Pyrex mailing list