[pypy-commit] cffi default: test for the recursion in _struct_collecttype(): fails if the

arigo pypy.commits at gmail.com
Wed Jan 31 15:52:24 EST 2018


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r3092:acf2cf3a6959
Date: 2018-01-31 21:52 +0100
http://bitbucket.org/cffi/cffi/changeset/acf2cf3a6959/

Log:	test for the recursion in _struct_collecttype(): fails if the
	recursion is replaced with a simple _do_collect_type()

diff --git a/testing/cffi1/test_re_python.py b/testing/cffi1/test_re_python.py
--- a/testing/cffi1/test_re_python.py
+++ b/testing/cffi1/test_re_python.py
@@ -57,6 +57,7 @@
     int strlen(const char *);
     struct with_union { union { int a; char b; }; };
     union with_struct { struct { int a; char b; }; };
+    struct NVGcolor { union { float rgba[4]; struct { float r,g,b,a; }; }; };
     """)
     ffi.set_source('re_python_pysrc', None)
     ffi.emit_python_code(str(tmpdir.join('re_python_pysrc.py')))
@@ -218,10 +219,19 @@
 def test_anonymous_union_inside_struct():
     # based on issue #357
     from re_python_pysrc import ffi
+    INT = ffi.sizeof("int")
     assert ffi.offsetof("struct with_union", "a") == 0
     assert ffi.offsetof("struct with_union", "b") == 0
-    assert ffi.sizeof("struct with_union") == ffi.sizeof("int")
+    assert ffi.sizeof("struct with_union") == INT
     #
     assert ffi.offsetof("union with_struct", "a") == 0
-    assert ffi.offsetof("union with_struct", "b") == 4
-    assert ffi.sizeof("union with_struct") >= ffi.sizeof("int") + 1
+    assert ffi.offsetof("union with_struct", "b") == INT
+    assert ffi.sizeof("union with_struct") >= INT + 1
+    #
+    FLOAT = ffi.sizeof("float")
+    assert ffi.sizeof("struct NVGcolor") == FLOAT * 4
+    assert ffi.offsetof("struct NVGcolor", "rgba") == 0
+    assert ffi.offsetof("struct NVGcolor", "r") == 0
+    assert ffi.offsetof("struct NVGcolor", "g") == FLOAT
+    assert ffi.offsetof("struct NVGcolor", "b") == FLOAT * 2
+    assert ffi.offsetof("struct NVGcolor", "a") == FLOAT * 3


More information about the pypy-commit mailing list