Dan Colish avatar Dan Colish committed 69d94d4 Merge

merge

Comments (0)

Files changed (5)

pypy/module/cpyext/stubs.py

     """
     raise NotImplementedError
 
-@cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
-def PyWeakref_CheckProxy(space, ob):
-    """Return true if ob is a proxy object.
-    """
-    raise NotImplementedError
Add a comment to this file

pypy/module/cpyext/test/test_unicodeobject.py

File contents unchanged.

pypy/module/cpyext/test/test_weakref.py

         w_proxy = api.PyWeakref_NewProxy(w_obj, None)
         assert space.unwrap(space.str(w_proxy)) == "<type 'exceptions.Warning'>"
         assert space.unwrap(space.repr(w_proxy)).startswith('<weak')
+        ret = api.PyWeakref_CheckProxy(w_proxy)
+        assert ret == 1
 
     def test_weakref_lockobject(self, space, api):
         # some new weakrefable object
Add a comment to this file

pypy/module/cpyext/unicodeobject.py

File contents unchanged.

pypy/module/cpyext/weakrefobject.py

-from pypy.module.cpyext.api import cpython_api
+from pypy.module.cpyext.api import cpython_api, build_type_checkers, CANNOT_FAIL
 from pypy.module.cpyext.pyobject import PyObject, borrow_from
-from pypy.module._weakref.interp__weakref import W_Weakref, proxy
+from pypy.module._weakref.interp__weakref import W_Weakref, W_CallableProxy, W_Proxy, proxy
+from pypy.rpython.lltypesystem import rffi
 
 @cpython_api([PyObject, PyObject], PyObject)
 def PyWeakref_NewRef(space, w_obj, w_callback):
 
 @cpython_api([PyObject, PyObject], PyObject)
 def PyWeakref_NewProxy(space, w_obj, w_callback):
-    """Return a weak reference proxy object for the object *ob*.  This will
-    alwas return a new reference, but is not guaranteed to create a new
-    object; an existing proxy object may be returned.  The second parameter,
-    *callback*, can be a callable object that receives notification when *ob*
-    is garbage collected; it should accept a single parameter, which will be
-    the weak reference object itself. *callback* may also be ``None`` or
-    *NULL*.  If *ob* is not a weakly-referencable object, or if *callback* is
-    not callable, ``None``, or *NULL*, this will return *NULL* and raise
-    :exc:`TypeError`.
+    """Return a weak reference proxy object for the object *ob*.  This will always
+    return a new reference, but is not guaranteed to create a new object; an
+    existing proxy object may be returned.  The second parameter, *callback*, can
+    be a callable object that receives notification when *ob* is garbage
+    collected; it should accept a single parameter, which will be the weak
+    reference object itself. *callback* may also be ``None`` or *NULL*.  If *ob*
+    is not a weakly-referencable object, or if *callback* is not callable,
+    ``None``, or *NULL*, this will return *NULL* and raise :exc:`TypeError`.
     """
     return proxy(space, w_obj, w_callback)
 
+@cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
+def PyWeakref_CheckProxy(space, w_proxy):
+    """Return true if ob is a proxy object.
+    """
+    w_proxy_t = space.gettypeobject(W_Proxy.typedef)
+    w_callable_t = space.gettypeobject(W_CallableProxy.typedef)
+    if (space.is_true(space.isinstance(w_proxy, w_proxy_t)) or
+         space.is_true(space.isinstance(w_proxy, w_callable_t))):
+        return 1
+    else:
+        return 0
+
 @cpython_api([PyObject], PyObject)
 def PyWeakref_GetObject(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)
-
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.