[pypy-svn] r74408 - in pypy/trunk/pypy/module/cpyext: . test

afa at codespeak.net afa at codespeak.net
Thu May 6 13:47:29 CEST 2010


Author: afa
Date: Thu May  6 13:47:27 2010
New Revision: 74408

Modified:
   pypy/trunk/pypy/module/cpyext/pyobject.py
   pypy/trunk/pypy/module/cpyext/test/test_cpyext.py
Log:
Turns borrow_mapping into a dict(addr of container -> set of w_containees)


Modified: pypy/trunk/pypy/module/cpyext/pyobject.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/pyobject.py	(original)
+++ pypy/trunk/pypy/module/cpyext/pyobject.py	Thu May  6 13:47:27 2010
@@ -148,9 +148,10 @@
 
 class RefcountState:
     def __init__(self, space):
+        self.space = space
         self.py_objects_w2r = {} # { w_obj -> raw PyObject }
         self.py_objects_r2w = {} # { addr of raw PyObject -> w_obj }
-        self.borrow_mapping = {} # { addr of container -> { addr of containee -> None } }
+        self.borrow_mapping = {} # { addr of container -> { w_containee -> None } }
         self.borrowed_objects = {} # { addr of containee -> None }
         self.non_heaptypes_w = []
 
@@ -170,6 +171,13 @@
         for w_obj, obj in self.py_objects_w2r.items():
             print "%r: %i" % (w_obj, obj.c_ob_refcnt)
 
+    def reset_borrowed_references(self):
+        while self.borrowed_objects:
+            addr, _ = self.borrowed_objects.popitem()
+            w_obj = self.py_objects_r2w[addr]
+            Py_DecRef(self.space, w_obj)
+        self.borrow_mapping = {}
+
 class NullPointerException(Exception):
     pass
 
@@ -342,7 +350,7 @@
     Py_DecRef(space, container)
     container_ptr = rffi.cast(ADDR, container)
     borrowees = state.borrow_mapping.setdefault(container_ptr, {})
-    borrowees[obj_ptr] = None
+    borrowees[w_borrowed] = None
     return ref
 
 class BorrowPair:
@@ -385,14 +393,8 @@
     ptr = rffi.cast(ADDR, py_obj)
     state = space.fromcache(RefcountState)
     if ptr in state.borrow_mapping: # move to lifeline __del__
-        for containee in state.borrow_mapping[ptr]:
-            w_containee = state.py_objects_r2w.get(containee, None)
-            if w_containee is not None:
-                forget_borrowee(space, w_containee)
-            else:
-                if DEBUG_REFCOUNT:
-                    print >>sys.stderr, "Borrowed object is already gone:", \
-                            hex(containee)
+        for w_containee in state.borrow_mapping[ptr]:
+            forget_borrowee(space, w_containee)
         del state.borrow_mapping[ptr]
 
 

Modified: pypy/trunk/pypy/module/cpyext/test/test_cpyext.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/test/test_cpyext.py	(original)
+++ pypy/trunk/pypy/module/cpyext/test/test_cpyext.py	Thu May  6 13:47:27 2010
@@ -265,11 +265,7 @@
         for w_obj in state.non_heaptypes_w:
             Py_DecRef(self.space, w_obj)
         state.non_heaptypes_w[:] = []
-        while state.borrowed_objects:
-            addr, _ = state.borrowed_objects.popitem()
-            w_obj = state.py_objects_r2w[addr]
-            Py_DecRef(self.space, w_obj)
-        state.borrow_mapping = {}
+        state.reset_borrowed_references()
         if self.check_and_print_leaks():
             assert False, "Test leaks or loses object(s)."
 



More information about the Pypy-commit mailing list