[pypy-svn] r74405 - pypy/trunk/pypy/module/cpyext

afa at codespeak.net afa at codespeak.net
Thu May 6 12:55:53 CEST 2010


Author: afa
Date: Thu May  6 12:55:52 2010
New Revision: 74405

Modified:
   pypy/trunk/pypy/module/cpyext/api.py
   pypy/trunk/pypy/module/cpyext/pyobject.py
Log:
Fix translation, at last.


Modified: pypy/trunk/pypy/module/cpyext/api.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/api.py	(original)
+++ pypy/trunk/pypy/module/cpyext/api.py	Thu May  6 12:55:52 2010
@@ -216,7 +216,7 @@
                         else:
                             return api_function.error_value
                     if res is None:
-                        return res
+                        return None
                     elif isinstance(res, BorrowedPair):
                         return res.w_borrowed
                     else:
@@ -448,10 +448,11 @@
                 retval = error_value
 
             elif callable.api_func.restype is PyObject:
-                if isinstance(result, BorrowedPair):
+                if result is None:
+                    retval = make_ref(space, None)
+                elif isinstance(result, BorrowedPair):
                     retval = result.get_ref(space)
                 elif not rffi._isllptr(result):
-                    assert not isinstance(result, BorrowedPair)
                     retval = make_ref(space, result)
                 else:
                     retval = result

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 12:55:52 2010
@@ -305,17 +305,17 @@
         Create a borrowed reference, which will live as long as the container
         has a living reference (as a PyObject!)
         """
-        if self.w_borrowed is None:
-            return lltype.nullptr(PyObject.TO)
-
         ref = make_ref(space, self.w_borrowed)
+        if not ref:
+            return ref
 
+        # state.borrowed_objects owns the reference
         state = space.fromcache(State)
         obj_ptr = rffi.cast(ADDR, ref)
         if obj_ptr not in state.borrowed_objects:
             state.borrowed_objects[obj_ptr] = None
         else:
-            Py_DecRef(space, ref)
+            Py_DecRef(space, ref) # already in borrowed list
 
         if self.w_container is None: # self-managed
             return ref



More information about the Pypy-commit mailing list