summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2020-05-20 23:29:46 +0200
committerArmin Rigo <arigo@tunes.org>2020-05-20 23:29:46 +0200
commitbb48fdcc86c5bd2c211fba2ac4cffe8b6efb49e2 (patch)
treedd4e9101065c0a799cca5c03f31c3c310ef15d9a /testing
parent680aa960da02dfa304c6b889489c05c38de89318 (diff)
downloadcffi-bb48fdcc86c5bd2c211fba2ac4cffe8b6efb49e2.tar.gz
#453
Special-case typedefs of arrays with '...' length, so that they can be used through recompiler.py as if they had a specified length in most cases.
Diffstat (limited to 'testing')
-rw-r--r--testing/cffi1/test_recompiler.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/testing/cffi1/test_recompiler.py b/testing/cffi1/test_recompiler.py
index bb64ba2..397270b 100644
--- a/testing/cffi1/test_recompiler.py
+++ b/testing/cffi1/test_recompiler.py
@@ -2122,6 +2122,40 @@ def test_typedef_array_dotdotdot():
p = ffi.new("vmat_t", 4)
assert ffi.sizeof(p[3]) == 8 * ffi.sizeof("int")
+def test_typedef_array_dotdotdot_usage():
+ ffi = FFI()
+ ffi.cdef("""
+ typedef int foo_t[...];
+ typedef int mat_t[...][...];
+ struct s { foo_t a; foo_t *b; foo_t **c; };
+ int myfunc(foo_t a, foo_t *b, foo_t **c);
+ struct sm { mat_t a; mat_t *b; mat_t **c; };
+ int myfuncm(mat_t a, mat_t *b, mat_t **c);
+ """)
+ lib = verify(ffi, "test_typedef_array_dotdotdot_usage", """
+ typedef int foo_t[50];
+ typedef int mat_t[6][7];
+ struct s { foo_t a; foo_t *b; foo_t **c; };
+ static int myfunc(foo_t a, foo_t *b, foo_t **c) { return (**c)[49]; }
+ struct sm { mat_t a; mat_t *b; mat_t **c; };
+ static int myfuncm(mat_t a, mat_t *b, mat_t **c) { return (**c)[5][6]; }
+ """)
+ assert ffi.sizeof("foo_t") == 50 * ffi.sizeof("int")
+ p = ffi.new("struct s *")
+ assert ffi.sizeof(p[0]) == 50 * ffi.sizeof("int") + 2 * ffi.sizeof("void *")
+ p.a[49] = 321
+ p.b = ffi.addressof(p, 'a')
+ p.c = ffi.addressof(p, 'b')
+ assert lib.myfunc(ffi.NULL, ffi.NULL, p.c) == 321
+ #
+ assert ffi.sizeof("mat_t") == 42 * ffi.sizeof("int")
+ p = ffi.new("struct sm *")
+ assert ffi.sizeof(p[0]) == 42 * ffi.sizeof("int") + 2 * ffi.sizeof("void *")
+ p.a[5][6] = -321
+ p.b = ffi.addressof(p, 'a')
+ p.c = ffi.addressof(p, 'b')
+ assert lib.myfuncm(ffi.NULL, ffi.NULL, p.c) == -321
+
def test_call_with_custom_field_pos():
ffi = FFI()
ffi.cdef("""