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

afa at codespeak.net afa at codespeak.net
Tue May 4 14:07:41 CEST 2010


Author: afa
Date: Tue May  4 14:07:40 2010
New Revision: 74357

Modified:
   pypy/trunk/pypy/module/cpyext/test/test_weakref.py
   pypy/trunk/pypy/module/cpyext/weakrefobject.py
Log:
Add the new function PyWeakref_LockObject, similar to PyWeakref_GetObject
except that it returns a *new reference*.
PyWeakref_GetObject does not work on cpyext and should be removed.


Modified: pypy/trunk/pypy/module/cpyext/test/test_weakref.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/test/test_weakref.py	(original)
+++ pypy/trunk/pypy/module/cpyext/test/test_weakref.py	Tue May  4 14:07:40 2010
@@ -7,6 +7,7 @@
         w_ref = api.PyWeakref_NewRef(w_obj, space.w_None)
         assert w_ref is not None
         assert space.is_w(api.PyWeakref_GetObject(w_ref), w_obj)
+        assert space.is_w(api.PyWeakref_LockObject(w_ref), w_obj)
 
         w_obj = space.newtuple([])
         assert api.PyWeakref_NewRef(w_obj, space.w_None) is None

Modified: pypy/trunk/pypy/module/cpyext/weakrefobject.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/weakrefobject.py	(original)
+++ pypy/trunk/pypy/module/cpyext/weakrefobject.py	Tue May  4 14:07:40 2010
@@ -18,9 +18,16 @@
 
 @cpython_api([PyObject], PyObject, borrowed=True)
 def PyWeakref_GetObject(space, w_ref):
-    """Return the referenced object from a weak reference, ref.  If the referent is
-    no longer live, returns None.
+    """Return the referenced object from a weak reference.  If the referent is
+    no longer live, returns None. This function returns a borrowed reference.
     """
     register_container(space, w_ref)
     return space.call_function(w_ref)
 
+ at cpython_api([PyObject], PyObject)
+def PyWeakref_LockObject(space, w_ref):
+    """Return the referenced object from a weak reference.  If the referent is
+    no longer live, returns None. This function returns a new reference.
+    """
+    return space.call_function(w_ref)
+



More information about the Pypy-commit mailing list