[pypy-commit] pypy default: cffi/ab441e95dfbf: add PyPy support for big-endian bitfields.
arigo
noreply at buildbot.pypy.org
Wed Oct 23 12:32:21 CEST 2013
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r67525:3ebf9399d5ad
Date: 2013-10-23 12:31 +0200
http://bitbucket.org/pypy/pypy/changeset/3ebf9399d5ad/
Log: cffi/ab441e95dfbf: add PyPy support for big-endian bitfields.
diff --git a/pypy/module/_cffi_backend/newtype.py b/pypy/module/_cffi_backend/newtype.py
--- a/pypy/module/_cffi_backend/newtype.py
+++ b/pypy/module/_cffi_backend/newtype.py
@@ -117,13 +117,17 @@
SF_MSVC_BITFIELDS = 1
SF_GCC_ARM_BITFIELDS = 2
+SF_GCC_BIG_ENDIAN = 4
if sys.platform == 'win32':
DEFAULT_SFLAGS = SF_MSVC_BITFIELDS
-elif rffi_platform.getdefined('__arm__', ''):
- DEFAULT_SFLAGS = SF_GCC_ARM_BITFIELDS
else:
- DEFAULT_SFLAGS = 0
+ if rffi_platform.getdefined('__arm__', ''):
+ DEFAULT_SFLAGS = SF_GCC_ARM_BITFIELDS
+ else:
+ DEFAULT_SFLAGS = 0
+ if sys.byteorder == 'big':
+ DEFAULT_SFLAGS |= SF_GCC_BIG_ENDIAN
@unwrap_spec(name=str)
def new_struct_type(space, name):
@@ -325,6 +329,9 @@
prev_bitfield_free -= fbitsize
field_offset_bytes = boffset / 8 - ftype.size
+ if sflags & SF_GCC_BIG_ENDIAN:
+ bitshift = 8 * ftype.size - fbitsize- bitshift
+
fld = ctypestruct.W_CField(ftype, field_offset_bytes,
bitshift, fbitsize)
fields_list.append(fld)
diff --git a/pypy/module/_cffi_backend/test/_backend_test_c.py b/pypy/module/_cffi_backend/test/_backend_test_c.py
--- a/pypy/module/_cffi_backend/test/_backend_test_c.py
+++ b/pypy/module/_cffi_backend/test/_backend_test_c.py
@@ -2949,8 +2949,6 @@
_test_bitfield_details(flag=2)
def test_bitfield_as_big_endian():
- if '__pypy__' in sys.builtin_module_names:
- py.test.skip("no big endian machine supported on pypy for now")
_test_bitfield_details(flag=4)
More information about the pypy-commit
mailing list