PSARC/2014/110 CFFI: foreign function interface for Python calling C code
18468609 integrate cffi
The testsuite makes some incorrect assumptions:
- we need to not assume "a standard gcc", so replace the -Werror flag
with -errwarn to turn on the warnings are expected to cause compilation
to fail.
- don't use the -pthread flag for compilation; as Studio doesn't have any
clue what to do with it, and we don't need it on Solaris, anyway.
- don't force the use of gcc when compiling a test shared object; get
that passed in from the makefile.
- don't assume that stdin/stdout/stderr are changeable:
https://bitbucket.org/cffi/cffi/issue/145/solaris-stdout-and-stderr-not-in-libc-not
fixed in
https://bitbucket.org/cffi/cffi/commits/237031079adc
- don't assume that enums can be unsigned or are the same size as long:
https://bitbucket.org/cffi/cffi/issue/143/test_enum_size-makes-invalid-assumptions
Also fix a problem with some assignments to void*:
https://bitbucket.org/cffi/cffi/issue/146/incorrect-type-for-c_callback-variable
fixed in
https://bitbucket.org/cffi/cffi/commits/51d87933eb4b
--- cffi-0.8.2/testing/test_verify.py Thu Mar 6 22:51:56 2014
+++ cffi-0.8.2/testing/test_verify.py Thu Mar 20 18:39:01 2014
@@ -18,8 +18,10 @@
extra_compile_args = [
'-Werror', '-Qunused-arguments', '-Wno-error=shorten-64-to-32']
else:
- # assume a standard gcc
- extra_compile_args = ['-Werror']
+ extra_compile_args = [
+ '-errtags=yes',
+ '-errwarn=E_ASSIGNMENT_TYPE_MISMATCH,E_RETURN_VALUE_TYPE_MISMATCH'
+ ]
class FFI(FFI):
def verify(self, *args, **kwds):
--- cffi-0.8.2/testing/callback_in_thread.py Fri Mar 21 15:58:21 2014
+++ cffi-0.8.2/testing/callback_in_thread.py Fri Mar 21 15:58:30 2014
@@ -22,7 +22,7 @@
pthread_create(&thread, NULL, my_wait_function, (void*)mycb);
return 0;
}
- """, extra_compile_args=['-pthread'])
+ """)
seen = []
@ffi.callback('int(*)(int,int)')
def mycallback(x, y):
--- cffi-0.8.2/testing/test_ownlib.py Tue Oct 9 02:10:04 2012
+++ cffi-0.8.2/testing/test_ownlib.py Tue Mar 25 15:39:35 2014
@@ -1,4 +1,4 @@
-import py, sys
+import os, py, sys
import subprocess, weakref
from cffi import FFI
from cffi.backend_ctypes import CTypesBackend
@@ -28,7 +28,7 @@
from testing.udir import udir
udir.join('testownlib.c').write(SOURCE)
subprocess.check_call(
- 'gcc testownlib.c -shared -fPIC -o testownlib.so',
+ os.getenv('TESTOWNLIB_CC') % ('testownlib.c', 'testownlib.so'),
cwd=str(udir), shell=True)
cls.module = str(udir.join('testownlib.so'))
--- cffi-0.8.2/c/test_c.py Thu Mar 6 22:51:56 2014
+++ cffi-0.8.2/c/test_c.py Mon Mar 24 14:53:27 2014
@@ -1102,7 +1102,7 @@
def test_read_variable():
## FIXME: this test assumes glibc specific behavior, it's not compliant with C standard
## https://bugs.pypy.org/issue1643
- if sys.platform == 'win32' or sys.platform == 'darwin' or sys.platform.startswith('freebsd'):
+ if not sys.platform.startswith("linux"):
py.test.skip("untested")
BVoidP = new_pointer_type(new_void_type())
ll = find_and_load_library('c')
@@ -1112,7 +1112,7 @@
def test_read_variable_as_unknown_length_array():
## FIXME: this test assumes glibc specific behavior, it's not compliant with C standard
## https://bugs.pypy.org/issue1643
- if sys.platform == 'win32' or sys.platform == 'darwin' or sys.platform.startswith('freebsd'):
+ if not sys.platform.startswith("linux"):
py.test.skip("untested")
BCharP = new_pointer_type(new_primitive_type("char"))
BArray = new_array_type(BCharP, None)
@@ -1124,7 +1124,7 @@
def test_write_variable():
## FIXME: this test assumes glibc specific behavior, it's not compliant with C standard
## https://bugs.pypy.org/issue1643
- if sys.platform == 'win32' or sys.platform == 'darwin' or sys.platform.startswith('freebsd'):
+ if not sys.platform.startswith("linux"):
py.test.skip("untested")
BVoidP = new_pointer_type(new_void_type())
ll = find_and_load_library('c')
--- cffi-0.8.2/testing/test_verify.py Thu Mar 6 22:51:56 2014
+++ cffi-0.8.2/testing/test_verify.py Mon Mar 24 15:03:49 2014
@@ -1472,8 +1474,8 @@
assert func() == 42
def test_FILE_stored_in_stdout():
- if sys.platform == 'win32':
- py.test.skip("MSVC: cannot assign to stdout")
+ if not sys.platform.startswith("linux"):
+ py.test.skip("likely, we cannot assign to stdout")
ffi = FFI()
ffi.cdef("int printf(const char *, ...); FILE *setstdout(FILE *);")
lib = ffi.verify("""
--- cffi-0.8.2/testing/test_verify.py Thu Mar 6 22:51:56 2014
+++ cffi-0.8.2/testing/test_verify.py Mon Mar 24 15:06:23 2014
@@ -1598,13 +1598,13 @@
('-123', 4, -1),
('-2147483647-1', 4, -1),
]
- if FFI().sizeof("long") == 8:
+ if FFI().sizeof("long") == 8 and sys.platform != 'sunos5':
cases += [('4294967296L', 8, 2**64-1),
('%dUL' % (2**64-1), 8, 2**64-1),
('-2147483649L', 8, -1),
('%dL-1L' % (1-2**63), 8, -1)]
for hidden_value, expected_size, expected_minus1 in cases:
- if sys.platform == 'win32' and 'U' in hidden_value:
+ if sys.platform in ('win32', 'sunos5') and 'U' in hidden_value:
continue # skipped on Windows
ffi = FFI()
ffi.cdef("enum foo_e { AA, BB, ... };")
@@ -1629,7 +1627,7 @@
(maxulong, -1, ''),
(-1, 0xffffffff, 'U'),
(-1, maxulong, 'UL')]:
- if c2c and sys.platform == 'win32':
+ if c2c and sys.platform in ('win32', 'sunos5'):
continue # enums may always be signed with MSVC
ffi = FFI()
ffi.cdef("enum foo_e { AA=%s };" % c1)
--- a/testing/test_verify.py
+++ b/testing/test_verify.py
@@ -1656,8 +1656,8 @@
ffi = FFI()
ffi.cdef("""
int (*python_callback)(int how_many, int *values);
- void *const c_callback; /* pass this ptr to C routines */
- int some_c_function(void *cb);
+ int (*const c_callback)(int,...); /* pass this ptr to C routines */
+ int some_c_function(int(*cb)(int,...));
""")
lib = ffi.verify("""
#include <stdarg.h>