Author: Armin Rigo <[email protected]>
Branch:
Changeset: r78472:e522adea1e4f
Date: 2015-07-06 19:42 +0200
http://bitbucket.org/pypy/pypy/changeset/e522adea1e4f/
Log: Update to cffi/0d2cff1af99f
diff --git a/pypy/module/test_lib_pypy/cffi_tests/cffi0/test_ffi_backend.py
b/pypy/module/test_lib_pypy/cffi_tests/cffi0/test_ffi_backend.py
--- a/pypy/module/test_lib_pypy/cffi_tests/cffi0/test_ffi_backend.py
+++ b/pypy/module/test_lib_pypy/cffi_tests/cffi0/test_ffi_backend.py
@@ -63,7 +63,7 @@
seen = []
def myalloc(size):
seen.append(size)
- return ffi.new("char[]", "X" * size)
+ return ffi.new("char[]", b"X" * size)
def myfree(raw):
seen.append(raw)
alloc1 = ffi.new_allocator(myalloc, myfree)
@@ -95,7 +95,7 @@
seen = []
def myalloc(size):
seen.append(size)
- return ffi.new("char[]", "X" * size)
+ return ffi.new("char[]", b"X" * size)
alloc1 = ffi.new_allocator(myalloc) # no 'free'
p1 = alloc1("int[10]")
assert seen == [40]
diff --git a/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_ffi_obj.py
b/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_ffi_obj.py
--- a/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_ffi_obj.py
+++ b/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_ffi_obj.py
@@ -252,7 +252,7 @@
seen = []
def myalloc(size):
seen.append(size)
- return ffi.new("char[]", "X" * size)
+ return ffi.new("char[]", b"X" * size)
def myfree(raw):
seen.append(raw)
alloc1 = ffi.new_allocator(myalloc, myfree)
@@ -284,7 +284,7 @@
seen = []
def myalloc(size):
seen.append(size)
- return ffi.new("char[]", "X" * size)
+ return ffi.new("char[]", b"X" * size)
alloc1 = ffi.new_allocator(myalloc) # no 'free'
p1 = alloc1("int[10]")
assert seen == [40]
diff --git a/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py
b/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py
--- a/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py
+++ b/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py
@@ -1116,7 +1116,8 @@
#
@ffi.callback("int *(*)(void)")
def get_my_value():
- return values + it.next()
+ for nextvalue in it:
+ return values + nextvalue
lib.get_my_value = get_my_value
#
values[0] = 41
@@ -1129,3 +1130,22 @@
assert values[2] == 42
assert p[-1] == 41
assert p[+1] == 42
+ #
+ # if get_my_value raises or returns nonsense, the exception is printed
+ # to stderr like with any callback, but then the C expression 'my_value'
+ # expand to '*NULL'. We assume here that '&my_value' will return NULL
+ # without segfaulting, and check for NULL when accessing the variable.
+ @ffi.callback("int *(*)(void)")
+ def get_my_value():
+ raise LookupError
+ lib.get_my_value = get_my_value
+ py.test.raises(ffi.error, getattr, lib, 'my_value')
+ py.test.raises(ffi.error, setattr, lib, 'my_value', 50)
+ py.test.raises(ffi.error, ffi.addressof, lib, 'my_value')
+ @ffi.callback("int *(*)(void)")
+ def get_my_value():
+ return "hello"
+ lib.get_my_value = get_my_value
+ py.test.raises(ffi.error, getattr, lib, 'my_value')
+ e = py.test.raises(ffi.error, setattr, lib, 'my_value', 50)
+ assert str(e.value) == "global variable 'my_value' is at address NULL"
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit