[pypy-svn] r74804 - in pypy/trunk/pypy/module/cpyext: . test
afa at codespeak.net
afa at codespeak.net
Thu May 27 13:21:52 CEST 2010
Author: afa
Date: Thu May 27 13:21:51 2010
New Revision: 74804
Modified:
pypy/trunk/pypy/module/cpyext/slotdefs.py
pypy/trunk/pypy/module/cpyext/test/test_typeobject.py
Log:
Fill "tp_call" slot
Modified: pypy/trunk/pypy/module/cpyext/slotdefs.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/slotdefs.py (original)
+++ pypy/trunk/pypy/module/cpyext/slotdefs.py Thu May 27 13:21:51 2010
@@ -124,6 +124,10 @@
space.get_and_call_args(w_descr, w_self, args)
return 0
+ at cpython_api([PyObject, PyObject, PyObject], PyObject)
+def slot_tp_call(space, w_self, w_args, w_kwds):
+ return space.call(w_self, w_args, w_kwds)
+
@cpython_api([PyObject], PyObject)
def slot_nb_int(space, w_self):
return space.int(w_self)
Modified: pypy/trunk/pypy/module/cpyext/test/test_typeobject.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/test/test_typeobject.py (original)
+++ pypy/trunk/pypy/module/cpyext/test/test_typeobject.py Thu May 27 13:21:51 2010
@@ -208,3 +208,23 @@
assert module.nb_int(10) == 10
assert module.nb_int(-12.3) == -12
raises(ValueError, module.nb_int, "123")
+
+ def test_tp_call(self):
+ module = self.import_extension('foo', [
+ ("tp_call", "METH_VARARGS",
+ '''
+ PyObject *obj = PyTuple_GET_ITEM(args, 0);
+ PyObject *c_args = PyTuple_GET_ITEM(args, 1);
+ if (!obj->ob_type->tp_call)
+ {
+ PyErr_SetNone(PyExc_ValueError);
+ return NULL;
+ }
+ return obj->ob_type->tp_call(obj, c_args, NULL);
+ '''
+ )
+ ])
+ class C:
+ def __call__(self, *args):
+ return args
+ assert module.tp_call(C(), ('x', 2)) == ('x', 2)
More information about the Pypy-commit
mailing list