[pypy-svn] r73416 - in pypy/branch/cpython-extension/pypy/module/cpyext: . test
fijal at codespeak.net
fijal at codespeak.net
Mon Apr 5 21:38:29 CEST 2010
Author: fijal
Date: Mon Apr 5 21:38:27 2010
New Revision: 73416
Modified:
pypy/branch/cpython-extension/pypy/module/cpyext/api.py
pypy/branch/cpython-extension/pypy/module/cpyext/getargs.py
pypy/branch/cpython-extension/pypy/module/cpyext/test/test_getargs.py
Log:
(trundle, fijal) try to implement 'O'
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/api.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/api.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/api.py Mon Apr 5 21:38:27 2010
@@ -282,6 +282,7 @@
VA_TP_LIST = {'int': lltype.Signed,
'PyObject*': PyObject,
+ 'PyObject**': PyObjectP,
'int*': rffi.INTP}
def configure_types():
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/getargs.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/getargs.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/getargs.py Mon Apr 5 21:38:27 2010
@@ -1,7 +1,9 @@
-
+from pypy.interpreter.error import OperationError
from pypy.module.cpyext.api import cpython_api, PyObject, CANNOT_FAIL, \
VA_LIST_P, cpython_api_c
from pypy.module.cpyext import api
+from pypy.module.cpyext.pyobject import from_ref, make_ref,\
+ add_borrowed_object, register_container
from pypy.rpython.lltypesystem import lltype, rffi
@cpython_api_c()
@@ -19,17 +21,31 @@
@cpython_api([PyObject, rffi.CCHARP, VA_LIST_P, rffi.INT_real],
rffi.INT_real, error=0)
def pypy_vgetargs1(space, w_obj, fmt, va_list_p, flags):
- i = 0
+ arg_i = 0
+ fmt_i = 0
while True:
- c = fmt[i]
+ c = fmt[fmt_i]
if c == "\x00":
return 1
elif c == "i":
arr = api.va_get_int_star(va_list_p)
arr[0] = rffi.cast(rffi.INT,
- space.int_w(space.getitem(w_obj, space.wrap(i))))
+ space.int_w(space.getitem(w_obj, space.wrap(arg_i))))
+ elif c == "O":
+ w_item = space.getitem(w_obj, space.wrap(arg_i))
+ if fmt[fmt_i + 1] == "!":
+ fmt_i += 1
+ w_type = from_ref(space, api.va_get_PyObject_star(va_list_p))
+ if not space.is_true(space.isinstance(w_item, w_type)):
+ raise OperationError(space.w_TypeError,
+ space.wrap("wrong type"))
+ arr = api.va_get_PyObject_star_star(va_list_p)
+ arr[0] = make_ref(space, w_item)
+ register_container(space, w_obj)
+ add_borrowed_object(space, arr[0])
elif c == ':':
return 1
else:
raise Exception("Unsupported parameter: %s" % (c,))
- i += 1
+ arg_i += 1
+ fmt_i += 1
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/test/test_getargs.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/test/test_getargs.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/test/test_getargs.py Mon Apr 5 21:38:27 2010
@@ -21,6 +21,24 @@
return NULL;
}
return PyInt_FromLong(l);
+ '''),
+ ('oneargobject', 'METH_VARARGS',
+ '''
+ PyObject *obj;
+ if (!PyArg_Parse(args, "O", &obj)) {
+ return NULL;
+ }
+ Py_INCREF(obj);
+ return obj;
+ '''),
+ ('oneargobjectandlisttype', 'METH_VARARGS',
+ '''
+ PyObject *obj;
+ if (!PyArg_Parse(args, "O!", &PyList_Type, &obj)) {
+ return NULL;
+ }
+ Py_INCREF(obj);
+ return obj;
''')])
assert mod.oneargint(1) == 1
raises(TypeError, mod.oneargint, None)
@@ -31,4 +49,8 @@
else:
raise Exception("DID NOT RAISE")
assert mod.oneargandform(1) == 1
-
+
+ sentinel = object()
+ res = mod.oneargobject(sentinel)
+ raises(TypeError, "mod.oneargobjectandlisttype(sentinel)")
+ assert res is sentinel
More information about the Pypy-commit
mailing list