Author: Armin Rigo <[email protected]>
Branch:
Changeset: r97199:0dadf2ae75d9
Date: 2019-08-17 08:42 +0200
http://bitbucket.org/pypy/pypy/changeset/0dadf2ae75d9/
Log: update to cffi/74f57a76ed53
diff --git a/extra_tests/cffi_tests/cffi1/test_recompiler.py
b/extra_tests/cffi_tests/cffi1/test_recompiler.py
--- a/extra_tests/cffi_tests/cffi1/test_recompiler.py
+++ b/extra_tests/cffi_tests/cffi1/test_recompiler.py
@@ -2414,6 +2414,18 @@
assert ffi.sizeof(a[0]) == ffi.sizeof("unsigned")
assert ffi.sizeof(b[0]) == ffi.sizeof(a[0])
+def test_struct_with_func_with_struct_pointer_arg():
+ ffi = FFI()
+ ffi.cdef("""struct BinaryTree {
+ int (* CompareKey)(struct BinaryTree *tree);
+ };""")
+ lib = verify(ffi, "test_struct_with_func_with_struct_pointer_arg", """
+ struct BinaryTree {
+ int (* CompareKey)(struct BinaryTree *tree);
+ };
+ """)
+ ffi.new("struct BinaryTree *")
+
def test_struct_with_func_with_struct_arg():
ffi = FFI()
ffi.cdef("""struct BinaryTree {
diff --git a/pypy/module/_cffi_backend/ctypefunc.py
b/pypy/module/_cffi_backend/ctypefunc.py
--- a/pypy/module/_cffi_backend/ctypefunc.py
+++ b/pypy/module/_cffi_backend/ctypefunc.py
@@ -128,6 +128,10 @@
return W_CTypePtrBase._fget(self, attrchar)
def call(self, funcaddr, args_w):
+ if not funcaddr:
+ raise oefmt(self.space.w_RuntimeError,
+ "cannot call null function pointer from cdata '%s'",
+ self.name)
if self.cif_descr:
# regular case: this function does not take '...' arguments
self = jit.promote(self)
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
@@ -4425,3 +4425,10 @@
float(cast(BBool, 42))
with pytest.raises(TypeError):
complex(cast(BBool, 42))
+
+def test_cannot_call_null_function_pointer():
+ BInt = new_primitive_type("int")
+ BFunc = new_function_type((BInt, BInt), BInt, False)
+ f = cast(BFunc, 0)
+ with pytest.raises(RuntimeError):
+ f(40, 2)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit