summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2019-05-26 13:04:30 +0200
committerArmin Rigo <arigo@tunes.org>2019-05-26 13:04:30 +0200
commite3b8a0de6e8f52f5d8a9df8bcfe999611f145995 (patch)
tree4c727d61f1d1899eb78643a5e560303b8f448be8 /testing
parentf611fd0f3e9c4e8397d3b22cbeece0436fd23811 (diff)
downloadcffi-e3b8a0de6e8f52f5d8a9df8bcfe999611f145995.tar.gz
Support for from_buffer("type *")
Diffstat (limited to 'testing')
-rw-r--r--testing/cffi1/test_recompiler.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/testing/cffi1/test_recompiler.py b/testing/cffi1/test_recompiler.py
index 6636a6e..d560d6a 100644
--- a/testing/cffi1/test_recompiler.py
+++ b/testing/cffi1/test_recompiler.py
@@ -2338,3 +2338,24 @@ def test_realize_struct_error():
typedef int foo_t; struct foo_s { void (*x)(foo_t); };
""")
py.test.raises(TypeError, ffi.new, "struct foo_s *")
+
+def test_from_buffer_struct():
+ ffi = FFI()
+ ffi.cdef("""struct foo_s { int a, b; };""")
+ lib = verify(ffi, "test_from_buffer_struct_p", """
+ struct foo_s { int a, b; };
+ """)
+ p = ffi.new("struct foo_s *", [-219239, 58974983])
+ q = ffi.from_buffer("struct foo_s[]", ffi.buffer(p))
+ assert ffi.typeof(q) == ffi.typeof("struct foo_s[]")
+ assert len(q) == 1
+ assert q[0].a == p.a
+ assert q[0].b == p.b
+ assert q == p
+ q = ffi.from_buffer("struct foo_s *", ffi.buffer(p))
+ assert ffi.typeof(q) == ffi.typeof("struct foo_s *")
+ assert q.a == p.a
+ assert q.b == p.b
+ assert q[0].a == p.a
+ assert q[0].b == p.b
+ assert q == p