diff options
author | Armin Rigo <arigo@tunes.org> | 2018-08-30 11:36:45 +0200 |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2018-08-30 11:36:45 +0200 |
commit | 3cb559c1ea1c27ec2621e8e5c1487b403a50f9af (patch) | |
tree | 34efe7b3bf3a2d4563396cc39a1bbe9b2bfe9ee3 /testing/cffi0 | |
parent | 17307ff332b4300ba2871dcb9abba1ec915a5869 (diff) | |
download | cffi-3cb559c1ea1c27ec2621e8e5c1487b403a50f9af.tar.gz |
Issue #379
Accept ``ffi.new("int[4]", p)`` if p is itself another cdata ``int[4]``.
Diffstat (limited to 'testing/cffi0')
-rw-r--r-- | testing/cffi0/backend_tests.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/testing/cffi0/backend_tests.py b/testing/cffi0/backend_tests.py index 85fb0d4..b535108 100644 --- a/testing/cffi0/backend_tests.py +++ b/testing/cffi0/backend_tests.py @@ -1972,3 +1972,18 @@ class BackendTests: assert seen[1] == 101 assert seen[2] == 202 assert seen[3] == 303 + + def test_ffi_array_as_init(self): + ffi = FFI(backend=self.Backend()) + p = ffi.new("int[4]", [10, 20, 30, 400]) + q = ffi.new("int[4]", p) + assert list(q) == [10, 20, 30, 400] + py.test.raises(TypeError, ffi.new, "int[3]", p) + py.test.raises(TypeError, ffi.new, "int[5]", p) + py.test.raises(TypeError, ffi.new, "int16_t[4]", p) + s = ffi.new("struct {int i[4];}*", {'i': p}) + assert list(s.i) == [10, 20, 30, 400] + + def test_too_many_initializers(self): + ffi = FFI(backend=self.Backend()) + py.test.raises(IndexError, ffi.new, "int[4]", [10, 20, 30, 40, 50]) |