[pypy-svn] r79002 - pypy/branch/rlist-jit/pypy/module/cpyext

arigo at codespeak.net arigo at codespeak.net
Thu Nov 11 17:13:35 CET 2010


Author: arigo
Date: Thu Nov 11 17:13:33 2010
New Revision: 79002

Modified:
   pypy/branch/rlist-jit/pypy/module/cpyext/api.py
   pypy/branch/rlist-jit/pypy/module/cpyext/pyobject.py
Log:
Merge r79000 from trunk.


Modified: pypy/branch/rlist-jit/pypy/module/cpyext/api.py
==============================================================================
--- pypy/branch/rlist-jit/pypy/module/cpyext/api.py	(original)
+++ pypy/branch/rlist-jit/pypy/module/cpyext/api.py	Thu Nov 11 17:13:33 2010
@@ -226,7 +226,7 @@
             def unwrapper(space, *args):
                 from pypy.module.cpyext.pyobject import Py_DecRef
                 from pypy.module.cpyext.pyobject import make_ref, from_ref
-                from pypy.module.cpyext.pyobject import BorrowPair
+                from pypy.module.cpyext.pyobject import Reference
                 newargs = ()
                 to_decref = []
                 assert len(args) == len(api_function.argtypes)
@@ -270,8 +270,8 @@
                             return api_function.error_value
                     if res is None:
                         return None
-                    elif isinstance(res, BorrowPair):
-                        return res.w_borrowed
+                    elif isinstance(res, Reference):
+                        return res.get_wrapped(space)
                     else:
                         return res
                 finally:
@@ -473,7 +473,7 @@
     @specialize.ll()
     def wrapper(*args):
         from pypy.module.cpyext.pyobject import make_ref, from_ref
-        from pypy.module.cpyext.pyobject import BorrowPair
+        from pypy.module.cpyext.pyobject import Reference
         # we hope that malloc removal removes the newtuple() that is
         # inserted exactly here by the varargs specializer
         llop.gc_stack_bottom(lltype.Void)   # marker for trackgcroot.py
@@ -525,7 +525,7 @@
             elif is_PyObject(callable.api_func.restype):
                 if result is None:
                     retval = make_ref(space, None)
-                elif isinstance(result, BorrowPair):
+                elif isinstance(result, Reference):
                     retval = result.get_ref(space)
                 elif not rffi._isllptr(result):
                     retval = rffi.cast(callable.api_func.restype,

Modified: pypy/branch/rlist-jit/pypy/module/cpyext/pyobject.py
==============================================================================
--- pypy/branch/rlist-jit/pypy/module/cpyext/pyobject.py	(original)
+++ pypy/branch/rlist-jit/pypy/module/cpyext/pyobject.py	Thu Nov 11 17:13:33 2010
@@ -424,7 +424,18 @@
     state = space.fromcache(RefcountState)
     return state.make_borrowed(w_container, w_borrowed)
 
-class BorrowPair:
+class Reference:
+    def __init__(self, pyobj):
+        assert not isinstance(pyobj, W_Root)
+        self.pyobj = pyobj
+
+    def get_ref(self, space):
+        return self.pyobj
+
+    def get_wrapped(self, space):
+        return from_ref(space, self.pyobj)
+
+class BorrowPair(Reference):
     """
     Delays the creation of a borrowed reference.
     """
@@ -435,6 +446,9 @@
     def get_ref(self, space):
         return make_borrowed_ref(space, self.w_container, self.w_borrowed)
 
+    def get_wrapped(self, space):
+        return self.w_borrowed
+
 def borrow_from(container, borrowed):
     return BorrowPair(container, borrowed)
 



More information about the Pypy-commit mailing list