summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2016-10-27 17:21:47 +0200
committerArmin Rigo <arigo@tunes.org>2016-10-27 17:21:47 +0200
commitdcfbf4bf975e66029e6ef00ce36395c75c2f3ee7 (patch)
tree1d690e444a9b53a9615c88e69982ca217ad50acc /testing
parent0b175568e2b8afc92ecef2ed88fc8ae0b56c0b83 (diff)
downloadcffi-dcfbf4bf975e66029e6ef00ce36395c75c2f3ee7.tar.gz
Decided to fix ffi.sizeof() too. Update the documentation.
Diffstat (limited to 'testing')
-rw-r--r--testing/cffi0/test_verify.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/testing/cffi0/test_verify.py b/testing/cffi0/test_verify.py
index 73eb5c3..fbcdf8d 100644
--- a/testing/cffi0/test_verify.py
+++ b/testing/cffi0/test_verify.py
@@ -591,10 +591,15 @@ def test_struct_array_c99_1():
ffi.verify("struct foo_s { int x; int a[]; };")
assert ffi.sizeof('struct foo_s') == 1 * ffi.sizeof('int')
s = ffi.new("struct foo_s *", [424242, 4])
- assert ffi.sizeof(s[0]) == 1 * ffi.sizeof('int') # the same in C
+ assert ffi.sizeof(ffi.typeof(s[0])) == 1 * ffi.sizeof('int')
+ assert ffi.sizeof(s[0]) == 5 * ffi.sizeof('int')
+ # ^^^ explanation: if you write in C: "char x[5];", then
+ # "sizeof(ax" will evaluate to 5. The behavior above is
+ # a generalization of that to "struct foo_s[len(a)=5] x;"
+ # if you could do that in C.
assert s.a[3] == 0
s = ffi.new("struct foo_s *", [424242, [-40, -30, -20, -10]])
- assert ffi.sizeof(s[0]) == 1 * ffi.sizeof('int')
+ assert ffi.sizeof(s[0]) == 5 * ffi.sizeof('int')
assert s.a[3] == -10
s = ffi.new("struct foo_s *")
assert ffi.sizeof(s[0]) == 1 * ffi.sizeof('int')
@@ -609,10 +614,10 @@ def test_struct_array_c99_2():
ffi.verify("struct foo_s { int x, y; int a[]; };")
assert ffi.sizeof('struct foo_s') == 2 * ffi.sizeof('int')
s = ffi.new("struct foo_s *", [424242, 4])
- assert ffi.sizeof(s[0]) == 2 * ffi.sizeof('int')
+ assert ffi.sizeof(s[0]) == 6 * ffi.sizeof('int')
assert s.a[3] == 0
s = ffi.new("struct foo_s *", [424242, [-40, -30, -20, -10]])
- assert ffi.sizeof(s[0]) == 2 * ffi.sizeof('int')
+ assert ffi.sizeof(s[0]) == 6 * ffi.sizeof('int')
assert s.a[3] == -10
s = ffi.new("struct foo_s *")
assert ffi.sizeof(s[0]) == 2 * ffi.sizeof('int')