[pypy-svn] r73252 - in pypy/branch/cpython-extension/pypy/module/cpyext: . include test
fijal at codespeak.net
fijal at codespeak.net
Thu Apr 1 18:26:40 CEST 2010
Author: fijal
Date: Thu Apr 1 18:26:36 2010
New Revision: 73252
Added:
pypy/branch/cpython-extension/pypy/module/cpyext/eval.py (contents, props changed)
pypy/branch/cpython-extension/pypy/module/cpyext/include/eval.h
pypy/branch/cpython-extension/pypy/module/cpyext/test/test_eval.py (contents, props changed)
Modified:
pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py
pypy/branch/cpython-extension/pypy/module/cpyext/include/Python.h
Log:
Add PyEval_CallObject[WithKeywords]
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py Thu Apr 1 18:26:36 2010
@@ -44,5 +44,6 @@
import pypy.module.cpyext.intobject
import pypy.module.cpyext.listobject
import pypy.module.cpyext.sequence
+import pypy.module.cpyext.eval
# now that all rffi_platform.Struct types are registered, configure them
api.configure_types()
Added: pypy/branch/cpython-extension/pypy/module/cpyext/eval.py
==============================================================================
--- (empty file)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/eval.py Thu Apr 1 18:26:36 2010
@@ -0,0 +1,6 @@
+
+from pypy.module.cpyext.api import cpython_api, PyObject, CANNOT_FAIL
+
+ at 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)
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/include/Python.h
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/include/Python.h (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/include/Python.h Thu Apr 1 18:26:36 2010
@@ -41,6 +41,7 @@
#include "tupleobject.h"
#include "dictobject.h"
#include "intobject.h"
+#include "eval.h"
// XXX This shouldn't be included here
#include "structmember.h"
Added: pypy/branch/cpython-extension/pypy/module/cpyext/include/eval.h
==============================================================================
--- (empty file)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/include/eval.h Thu Apr 1 18:26:36 2010
@@ -0,0 +1,18 @@
+
+/* Int object interface */
+
+#ifndef Py_EVAL_H
+#define Py_EVAL_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "Python.h"
+
+#define PyEval_CallObject(func,arg) \
+ PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL)
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* !Py_EVAL_H */
Added: pypy/branch/cpython-extension/pypy/module/cpyext/test/test_eval.py
==============================================================================
--- (empty file)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/test/test_eval.py Thu Apr 1 18:26:36 2010
@@ -0,0 +1,30 @@
+
+from pypy.module.cpyext.test.test_api import BaseApiTest
+
+class TestEval(BaseApiTest):
+ def test_eval(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.PyEval_CallObjectWithKeywords(w_f, w_t, None)
+ assert space.int_w(w_res) == 2
+ assert space.int_w(space.len(w_l)) == 2
+ w_f = space.appexec([], """():
+ def f(*args, **kwds):
+ assert isinstance(kwds, dict)
+ assert 'xyz' in kwds
+ return len(kwds) + len(args) * 10
+ return f
+ """)
+ w_t = space.newtuple([space.w_None, space.w_None])
+ w_d = space.newdict()
+ 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
More information about the Pypy-commit
mailing list