Author: David Schneider <david.schnei...@picle.org> Branch: Changeset: r1268:09f85e97e9d3 Date: 2013-06-16 10:18 -0500 http://bitbucket.org/cffi/cffi/changeset/09f85e97e9d3/
Log: Fix for the alignment calculation of anonymous and zero sized bitfields on ARM. diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c --- a/c/_cffi_backend.c +++ b/c/_cffi_backend.c @@ -3503,6 +3503,7 @@ goto error; do_align = 1; +#ifndef __arm__ if (fbitsize >= 0) { if (!(sflags & SF_MSVC_BITFIELDS)) { /* GCC: anonymous bitfields (of any size) don't cause alignment */ @@ -3513,6 +3514,7 @@ do_align = fbitsize > 0; } } +#endif if (alignment < falign && do_align) alignment = falign; diff --git a/testing/test_ffi_backend.py b/testing/test_ffi_backend.py --- a/testing/test_ffi_backend.py +++ b/testing/test_ffi_backend.py @@ -1,4 +1,5 @@ -import py, sys +import py, sys, platform +import pytest from testing import backend_tests, test_function, test_ownlib from cffi import FFI import _cffi_backend @@ -121,6 +122,7 @@ self.check("int a:2; short b:15; char c:2; char y;", 5, 4, 8) self.check("int a:2; char b:1; char c:1; char y;", 1, 4, 4) + @pytest.mark.skipif("platform.machine().startswith('arm')") def test_bitfield_anonymous_no_align(self): L = FFI().alignof("long long") self.check("char y; int :1;", 0, 1, 2) @@ -133,6 +135,20 @@ self.check("char x; long long z:57; char y;", L + 8, L, L + 8 + L) self.check("char x; long long :57; char y;", L + 8, 1, L + 9) + @pytest.mark.skipif("not platform.machine().startswith('arm')") + def test_bitfield_anonymous_align_arm(self): + L = FFI().alignof("long long") + self.check("char y; int :1;", 0, 4, 4) + self.check("char x; int z:1; char y;", 2, 4, 4) + self.check("char x; int :1; char y;", 2, 4, 4) + self.check("char x; long long z:48; char y;", 7, L, 8) + self.check("char x; long long :48; char y;", 7, 8, 8) + self.check("char x; long long z:56; char y;", 8, L, 8 + L) + self.check("char x; long long :56; char y;", 8, L, 8 + L) + self.check("char x; long long z:57; char y;", L + 8, L, L + 8 + L) + self.check("char x; long long :57; char y;", L + 8, L, L + 8 + L) + + @pytest.mark.skipif("platform.machine().startswith('arm')") def test_bitfield_zero(self): L = FFI().alignof("long long") self.check("char y; int :0;", 0, 1, 4) @@ -143,6 +159,17 @@ self.check("char x; int :0; short b:1; char y;", 5, 2, 6) self.check("int a:1; int :0; int b:1; char y;", 5, 4, 8) + @pytest.mark.skipif("not platform.machine().startswith('arm')") + def test_bitfield_zero_arm(self): + L = FFI().alignof("long long") + self.check("char y; int :0;", 0, 4, 4) + self.check("char x; int :0; char y;", 4, 4, 8) + self.check("char x; int :0; int :0; char y;", 4, 4, 8) + self.check("char x; long long :0; char y;", L, 8, L + 8) + self.check("short x, y; int :0; int :0;", 2, 4, 4) + self.check("char x; int :0; short b:1; char y;", 5, 4, 8) + self.check("int a:1; int :0; int b:1; char y;", 5, 4, 8) + def test_error_cases(self): ffi = FFI() py.test.raises(TypeError, _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit