[pypy-svn] r73357 - in pypy/branch/cpython-extension/pypy/module/cpyext: . test

agaynor at codespeak.net agaynor at codespeak.net
Sun Apr 4 17:01:52 CEST 2010


Author: agaynor
Date: Sun Apr  4 17:01:51 2010
New Revision: 73357

Modified:
   pypy/branch/cpython-extension/pypy/module/cpyext/eval.py
   pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py
   pypy/branch/cpython-extension/pypy/module/cpyext/test/test_eval.py
Log:
Implemented PyObject_CallObject

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/eval.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/eval.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/eval.py	Sun Apr  4 17:01:51 2010
@@ -4,3 +4,13 @@
 @cpython_api([PyObject, PyObject, PyObject], PyObject)
 def PyEval_CallObjectWithKeywords(space, w_obj, w_arg, w_kwds):
     return space.call(w_obj, w_arg, w_kwds)
+
+ at cpython_api([PyObject, PyObject], PyObject)
+def PyObject_CallObject(space, w_obj, w_arg):
+    """
+    Call a callable Python object callable_object, with arguments given by the
+    tuple args.  If no arguments are needed, then args may be NULL.  Returns
+    the result of the call on success, or NULL on failure.  This is the equivalent
+    of the Python expression apply(callable_object, args) or
+    callable_object(*args)."""
+    return space.call(w_obj, w_arg)

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py	Sun Apr  4 17:01:51 2010
@@ -4516,19 +4516,6 @@
     """
     raise NotImplementedError
 
- at cpython_api([PyObject, PyObject], PyObject)
-def PyObject_CallObject(space, callable_object, args):
-    """
-    
-    
-    
-    Call a callable Python object callable_object, with arguments given by the
-    tuple args.  If no arguments are needed, then args may be NULL.  Returns
-    the result of the call on success, or NULL on failure.  This is the equivalent
-    of the Python expression apply(callable_object, args) or
-    callable_object(*args)."""
-    raise NotImplementedError
-
 @cpython_api([PyObject, rffi.CCHARP, ...], PyObject)
 def PyObject_CallFunction(space, callable, format, ):
     """

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/test/test_eval.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/test/test_eval.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/test/test_eval.py	Sun Apr  4 17:01:51 2010
@@ -28,3 +28,30 @@
         space.setitem(w_d, space.wrap("xyz"), space.wrap(3))
         w_res = api.PyEval_CallObjectWithKeywords(w_f, w_t, w_d)
         assert space.int_w(w_res) == 21
+    
+    def test_call_object(self, space, api):
+        w_l, w_f = space.fixedview(space.appexec([], """():
+        l = []
+        def f(arg1, arg2):
+            l.append(arg1)
+            l.append(arg2)
+            return len(l)
+        return l, f
+        """))
+
+        w_t = space.newtuple([space.wrap(1), space.wrap(2)])
+        w_res = api.PyObject_CallObject(w_f, w_t)
+        assert space.int_w(w_res) == 2
+        assert space.int_w(space.len(w_l)) == 2
+        
+        w_f = space.appexec([], """():
+            def f(*args):
+                assert isinstance(args, tuple)
+                return len(args) + 8
+            return f
+            """)
+
+        w_t = space.newtuple([space.wrap(1), space.wrap(2)])
+        w_res = api.PyObject_CallObject(w_f, w_t)
+        
+        assert space.int_w(w_res) == 10



More information about the Pypy-commit mailing list