[pypy-commit] pypy ffi-backend: Update the test to hg/cffi/c/test_c, and fix.
arigo
noreply at buildbot.pypy.org
Fri Jul 27 14:37:32 CEST 2012
Author: Armin Rigo <arigo at tunes.org>
Branch: ffi-backend
Changeset: r56488:57a1071ad895
Date: 2012-07-27 14:37 +0200
http://bitbucket.org/pypy/pypy/changeset/57a1071ad895/
Log: Update the test to hg/cffi/c/test_c, and fix.
diff --git a/pypy/module/_cffi_backend/ccallback.py b/pypy/module/_cffi_backend/ccallback.py
--- a/pypy/module/_cffi_backend/ccallback.py
+++ b/pypy/module/_cffi_backend/ccallback.py
@@ -10,7 +10,9 @@
from pypy.module._cffi_backend.cdataobj import W_CData, W_CDataApplevelOwning
from pypy.module._cffi_backend.ctypefunc import SIZE_OF_FFI_ARG, BIG_ENDIAN
-from pypy.module._cffi_backend import cerrno
+from pypy.module._cffi_backend.ctypeprim import W_CTypePrimitiveSigned
+from pypy.module._cffi_backend.ctypevoid import W_CTypeVoid
+from pypy.module._cffi_backend import cerrno, misc
# ____________________________________________________________
@@ -78,8 +80,7 @@
#
w_res = space.call(self.w_callable, space.newtuple(args_w))
#
- if fresult.size > 0:
- convert_from_object_fficallback(fresult, ll_res, w_res)
+ convert_from_object_fficallback(fresult, ll_res, w_res)
def print_error(self, operr):
space = self.space
@@ -101,11 +102,19 @@
def convert_from_object_fficallback(fresult, ll_res, w_res):
- if fresult.is_primitive_integer and fresult.size < SIZE_OF_FFI_ARG:
+ space = fresult.space
+ small_result = fresult.size < SIZE_OF_FFI_ARG
+ if small_result and isinstance(fresult, W_CTypeVoid):
+ if not space.is_w(w_res, space.w_None):
+ raise OperationError(space.w_TypeError,
+ space.wrap("callback with the return type 'void'"
+ " must return None"))
+ return
+ #
+ if small_result and fresult.is_primitive_integer:
# work work work around a libffi irregularity: for integer return
# types we have to fill at least a complete 'ffi_arg'-sized result
# buffer.
- from pypy.module._cffi_backend.ctypeprim import W_CTypePrimitiveSigned
if type(fresult) is W_CTypePrimitiveSigned:
# It's probably fine to always zero-extend, but you never
# know: maybe some code somewhere expects a negative
@@ -120,8 +129,7 @@
# manual inlining and tweaking of
# W_CTypePrimitiveSigned.convert_from_object() in order
# to write a whole 'ffi_arg'.
- from pypy.module._cffi_backend import misc
- value = misc.as_long_long(fresult.space, w_res)
+ value = misc.as_long_long(space, w_res)
value = r_ulonglong(value)
misc.write_raw_integer_data(ll_res, value, SIZE_OF_FFI_ARG)
return
diff --git a/pypy/module/_cffi_backend/ctypeobj.py b/pypy/module/_cffi_backend/ctypeobj.py
--- a/pypy/module/_cffi_backend/ctypeobj.py
+++ b/pypy/module/_cffi_backend/ctypeobj.py
@@ -36,8 +36,9 @@
def newp(self, w_init):
space = self.space
- raise OperationError(space.w_TypeError,
- space.wrap("expected a pointer or array ctype"))
+ raise operationerrfmt(space.w_TypeError,
+ "expected a pointer or array ctype, got '%s'",
+ self.name)
def cast(self, w_ob):
space = self.space
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
@@ -916,6 +916,17 @@
assert s.a == -10
assert s.b == 1E-42
+def test_callback_returning_void():
+ BVoid = new_void_type()
+ BFunc = new_function_type((), BVoid, False)
+ def cb():
+ seen.append(42)
+ f = callback(BFunc, cb)
+ seen = []
+ f()
+ assert seen == [42]
+ py.test.raises(TypeError, callback, BFunc, cb, -42)
+
def test_enum_type():
BEnum = new_enum_type("foo", (), ())
assert repr(BEnum) == "<ctype 'enum foo'>"
@@ -985,7 +996,8 @@
assert f(0) == unichr(0)
assert f(255) == unichr(255)
assert f(0x1234) == u'\u1234'
- assert f(-1) == u'\U00012345'
+ if sizeof(BWChar) == 4:
+ assert f(-1) == u'\U00012345'
def test_struct_with_bitfields():
BLong = new_primitive_type("long")
@@ -1360,7 +1372,7 @@
s.a1 = u'\ud807\udf44'
assert s.a1 == u'\U00011f44'
else:
- py.test.raises(ValueError, "s.a1 = u'\U00012345'")
+ py.test.raises(TypeError, "s.a1 = u'\U00012345'")
#
BWCharArray = new_array_type(BWCharP, None)
a = newp(BWCharArray, u'hello \u1234 world')
More information about the pypy-commit
mailing list