[pypy-commit] pypy default: Add protection against a rare, hard-to-reproduce bug that I believe cannot

arigo noreply at buildbot.pypy.org
Sun Nov 10 11:22:27 CET 2013


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r67925:37537ea3d3c6
Date: 2013-11-10 10:21 +0000
http://bitbucket.org/pypy/pypy/changeset/37537ea3d3c6/

Log:	Add protection against a rare, hard-to-reproduce bug that I believe
	cannot occur in CPython's refcounting model.

diff --git a/lib-python/2.7/weakref.py b/lib-python/2.7/weakref.py
--- a/lib-python/2.7/weakref.py
+++ b/lib-python/2.7/weakref.py
@@ -48,7 +48,14 @@
         def remove(wr, selfref=ref(self)):
             self = selfref()
             if self is not None:
-                del self.data[wr.key]
+                # Changed this for PyPy: made more resistent.  The
+                # issue is that in some corner cases, self.data
+                # might already be changed or removed by the time
+                # this weakref's callback is called.  If that is
+                # the case, we don't want to randomly kill an
+                # unrelated entry.
+                if self.data.get(wr.key) is wr:
+                    del self.data[wr.key]
         self._remove = remove
         UserDict.UserDict.__init__(self, *args, **kw)
 


More information about the pypy-commit mailing list