Author: Armin Rigo <[email protected]>
Branch:
Changeset: r59153:42c0d1650cf4
Date: 2012-11-30 15:50 -0800
http://bitbucket.org/pypy/pypy/changeset/42c0d1650cf4/
Log: Update to cffi/12a797fcf465.
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
@@ -10,7 +10,7 @@
from pypy.rlib import rposix
from pypy.module._cffi_backend.ctypeobj import W_CType
-from pypy.module._cffi_backend import cdataobj, misc, ctypeprim
+from pypy.module._cffi_backend import cdataobj, misc, ctypeprim, ctypevoid
class W_CTypePtrOrArray(W_CType):
@@ -72,8 +72,9 @@
for i in range(len(lst_w)):
ctitem.convert_from_object(cdata, lst_w[i])
cdata = rffi.ptradd(cdata, ctitem.size)
- elif (self.ctitem.is_primitive_integer and
- self.ctitem.size == rffi.sizeof(lltype.Char)):
+ elif (self.can_cast_anything or
+ (self.ctitem.is_primitive_integer and
+ self.ctitem.size == rffi.sizeof(lltype.Char))):
if not space.isinstance_w(w_ob, space.w_str):
raise self._convert_error("str or list or tuple", w_ob)
s = space.str_w(w_ob)
@@ -265,10 +266,14 @@
return 0
else:
return 0
- if self.ctitem.size <= 0:
- return 0
+ itemsize = self.ctitem.size
+ if itemsize <= 0:
+ if isinstance(self.ctitem, ctypevoid.W_CTypeVoid):
+ itemsize = 1
+ else:
+ return 0
try:
- datasize = ovfcheck(length * self.ctitem.size)
+ datasize = ovfcheck(length * itemsize)
except OverflowError:
raise OperationError(space.w_OverflowError,
space.wrap("array size would overflow a ssize_t"))
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
@@ -988,6 +988,25 @@
for i in range(10):
assert res.a[i] == p1.a[i] - p2.a[i]
+def test_call_function_23():
+ BVoid = new_void_type() # declaring the function as int(void*)
+ BVoidP = new_pointer_type(BVoid)
+ BInt = new_primitive_type("int")
+ BFunc23 = new_function_type((BVoidP,), BInt, False)
+ f = cast(BFunc23, _testfunc(23))
+ res = f(b"foo")
+ assert res == 1000 * ord(b'f')
+
+def test_call_function_23_bis():
+ # declaring the function as int(unsigned char*)
+ BUChar = new_primitive_type("unsigned char")
+ BUCharP = new_pointer_type(BUChar)
+ BInt = new_primitive_type("int")
+ BFunc23 = new_function_type((BUCharP,), BInt, False)
+ f = cast(BFunc23, _testfunc(23))
+ res = f(b"foo")
+ assert res == 1000 * ord(b'f')
+
def test_cannot_pass_struct_with_array_of_length_0():
BInt = new_primitive_type("int")
BArray0 = new_array_type(new_pointer_type(BInt), 0)
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
@@ -172,6 +172,11 @@
return result;
}
+static int _testfunc23(char *p)
+{
+ return 1000 * p[0];
+}
+
DLLEXPORT void *gettestfunc(int num)
{
void *f;
@@ -199,6 +204,7 @@
case 20: f = &_testfunc20; break;
case 21: f = &_testfunc21; break;
case 22: f = &_testfunc22; break;
+ case 23: f = &_testfunc23; break;
default:
return NULL;
}
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit