diff options
| author | Armin Rigo <arigo@tunes.org> | 2015-11-02 23:12:06 +0100 |
|---|---|---|
| committer | Armin Rigo <arigo@tunes.org> | 2015-11-02 23:12:06 +0100 |
| commit | 8249cb6f4e628cce17b509cc24ece6425b83497a (patch) | |
| tree | 66a16906ac8cf9bf3e8a2747a28fb87bddfedee5 /testing/cffi1 | |
| parent | 361b5b2a0b736af048c842515bbb4478d8287f80 (diff) | |
| download | cffi-8249cb6f4e628cce17b509cc24ece6425b83497a.tar.gz | |
Issue #228: "bool" not working in out-of-line FFI objects. Same problem
with all Windows common types. Mostly fixed by moving the list of
common types to C code. The only remaining corner case I can think of
is "FILE", which works only if it was mentioned in the cdef while
building the out-of-line module.
Diffstat (limited to 'testing/cffi1')
| -rw-r--r-- | testing/cffi1/test_commontypes.py | 15 | ||||
| -rw-r--r-- | testing/cffi1/test_ffi_obj.py | 14 | ||||
| -rw-r--r-- | testing/cffi1/test_parse_c_type.py | 7 | ||||
| -rw-r--r-- | testing/cffi1/test_verify1.py | 9 |
4 files changed, 34 insertions, 11 deletions
diff --git a/testing/cffi1/test_commontypes.py b/testing/cffi1/test_commontypes.py new file mode 100644 index 0000000..212da8d --- /dev/null +++ b/testing/cffi1/test_commontypes.py @@ -0,0 +1,15 @@ +import py, os, cffi +import _cffi_backend + + +def test_alphabetical_order(): + f = open(os.path.join(os.path.dirname(cffi.__file__), + '..', 'c', 'commontypes.c')) + lines = [line for line in f.readlines() if line.strip().startswith('EQ(')] + f.close() + assert lines == sorted(lines) + +def test_get_common_types(): + d = {} + _cffi_backend._get_common_types(d) + assert d["bool"] == "_Bool" diff --git a/testing/cffi1/test_ffi_obj.py b/testing/cffi1/test_ffi_obj.py index 8241c75..253206a 100644 --- a/testing/cffi1/test_ffi_obj.py +++ b/testing/cffi1/test_ffi_obj.py @@ -395,3 +395,17 @@ def test_ffi_new_allocator_4(): return ffi.NULL alloc5 = ffi.new_allocator(myalloc5) py.test.raises(MemoryError, alloc5, "int[5]") + +def test_bool_issue228(): + ffi = _cffi1_backend.FFI() + fntype = ffi.typeof("int(*callback)(bool is_valid)") + assert repr(fntype.args[0]) == "<ctype '_Bool'>" + +def test_cast_from_int_type_to_bool(): + ffi = _cffi1_backend.FFI() + for basetype in ['char', 'short', 'int', 'long', 'long long']: + for sign in ['signed', 'unsigned']: + type = '%s %s' % (sign, basetype) + assert int(ffi.cast("_Bool", ffi.cast(type, 42))) == 1 + assert int(ffi.cast("bool", ffi.cast(type, 42))) == 1 + assert int(ffi.cast("_Bool", ffi.cast(type, 0))) == 0 diff --git a/testing/cffi1/test_parse_c_type.py b/testing/cffi1/test_parse_c_type.py index 479e0e8..e90243d 100644 --- a/testing/cffi1/test_parse_c_type.py +++ b/testing/cffi1/test_parse_c_type.py @@ -19,8 +19,11 @@ ffi = cffi.FFI() ffi.cdef(header) lib = ffi.verify( - open(os.path.join(cffi_dir, '..', 'c', 'parse_c_type.c')).read(), - include_dirs=[cffi_dir]) + open(os.path.join(cffi_dir, '..', 'c', 'parse_c_type.c')).read() + """ +static const char *get_common_type(const char *search, size_t search_len) { + return NULL; +} +""", include_dirs=[cffi_dir]) class ParseError(Exception): pass diff --git a/testing/cffi1/test_verify1.py b/testing/cffi1/test_verify1.py index ffc2fc3..4678736 100644 --- a/testing/cffi1/test_verify1.py +++ b/testing/cffi1/test_verify1.py @@ -1494,15 +1494,6 @@ def test_cannot_pass_float(): assert lib.foo(0) == 1 py.test.raises(TypeError, lib.foo, 0.0) -def test_cast_from_int_type_to_bool(): - ffi = FFI() - for basetype in ['char', 'short', 'int', 'long', 'long long']: - for sign in ['signed', 'unsigned']: - type = '%s %s' % (sign, basetype) - assert int(ffi.cast("_Bool", ffi.cast(type, 42))) == 1 - assert int(ffi.cast("bool", ffi.cast(type, 42))) == 1 - assert int(ffi.cast("_Bool", ffi.cast(type, 0))) == 0 - def test_addressof(): ffi = FFI() ffi.cdef(""" |
