[pypy-commit] pypy ffi-backend: Update from cffi and add the same special case.
arigo
noreply at buildbot.pypy.org
Sat Aug 4 18:49:48 CEST 2012
Author: Armin Rigo <arigo at tunes.org>
Branch: ffi-backend
Changeset: r56574:affcac045afa
Date: 2012-08-04 18:49 +0200
http://bitbucket.org/pypy/pypy/changeset/affcac045afa/
Log: Update from cffi and add the same special case.
diff --git a/pypy/module/_cffi_backend/ctypeptr.py b/pypy/module/_cffi_backend/ctypeptr.py
--- a/pypy/module/_cffi_backend/ctypeptr.py
+++ b/pypy/module/_cffi_backend/ctypeptr.py
@@ -272,7 +272,17 @@
return True
else:
set_mustfree_flag(cdata, False)
- self.convert_from_object(cdata, w_ob)
+ try:
+ self.convert_from_object(cdata, w_ob)
+ except OperationError:
+ if (self.is_struct_ptr and isinstance(ob, cdataobj.W_CData)
+ and ob.ctype is self.ctitem):
+ # special case to make the life of verifier.py easier:
+ # if the formal argument type is 'struct foo *' but
+ # we pass a 'struct foo', then get a pointer to it
+ rffi.cast(rffi.CCHARPP, cdata)[0] = ob._cdata
+ else:
+ raise
return False
def getcfield(self, attr):
diff --git a/pypy/module/_cffi_backend/test/_backend_test_c.py b/pypy/module/_cffi_backend/test/_backend_test_c.py
--- a/pypy/module/_cffi_backend/test/_backend_test_c.py
+++ b/pypy/module/_cffi_backend/test/_backend_test_c.py
@@ -791,6 +791,22 @@
res = f(x[0])
assert res == -4042 + ord('A')
+def test_call_function_20():
+ BChar = new_primitive_type("char")
+ BShort = new_primitive_type("short")
+ BStruct = new_struct_type("foo")
+ BStructPtr = new_pointer_type(BStruct)
+ complete_struct_or_union(BStruct, [('a1', BChar, -1),
+ ('a2', BShort, -1)])
+ BFunc18 = new_function_type((BStructPtr,), BShort, False)
+ f = cast(BFunc18, _testfunc(20))
+ x = newp(BStructPtr, {'a1': 'A', 'a2': -4042})
+ # test the exception that allows us to pass a 'struct foo' where the
+ # function really expects a 'struct foo *'.
+ res = f(x[0])
+ assert res == -4042 + ord('A')
+ assert res == f(x)
+
def test_call_function_9():
BInt = new_primitive_type("int")
BFunc9 = new_function_type((BInt,), BInt, True) # vararg
diff --git a/pypy/module/_cffi_backend/test/_test_lib.c b/pypy/module/_cffi_backend/test/_test_lib.c
--- a/pypy/module/_cffi_backend/test/_test_lib.c
+++ b/pypy/module/_cffi_backend/test/_test_lib.c
@@ -135,6 +135,11 @@
return x;
}
+static short _testfunc20(struct _testfunc7_s *ptr)
+{
+ return ptr->a1 + ptr->a2;
+}
+
void *gettestfunc(int num)
{
void *f;
@@ -159,6 +164,7 @@
case 17: f = &_testfunc17; break;
case 18: f = &_testfunc18; break;
case 19: f = &_testfunc19; break;
+ case 20: f = &_testfunc20; break;
default:
return NULL;
}
More information about the pypy-commit
mailing list