Bus error on sparc
Created originally on Bitbucket by vbernat (Vincent Bernat)
Hi!
When running tests on sparc, I get a bus error. Here is a partial backtrace:
=========================================== test session starts ============================================
platform linux2 -- Python 2.7.8 -- py-1.4.23 -- pytest-2.6.0
collected 154 items
testing/test_ffi_backend.py ..............................................................................s...s.........................
Program received signal SIGBUS, Bus error.
write_raw_integer_data (target=0xf741b241 "", source=42623381, size=4) at c/_cffi_backend.c:767
767 *((unsigned int*)target) = (unsigned int)source;
(gdb) bt
#0 write_raw_integer_data (target=0xf741b241 "", source=42623381, size=4) at c/_cffi_backend.c:767
#1 0xf74fa790 in convert_from_object (data=0xf741b241 "", ct=0xf73e90b0, init=42623381)
at c/_cffi_backend.c:1279
#2 0x0009cbc4 in PyObject_SetAttr (v=v@entry=<_cffi_backend.CData at remote 0xf74049b0>,
name=<optimized out>, value=value@entry=42623381) at ../Objects/object.c:1252
#3 0x001166c0 in PyEval_EvalFrameEx (
f=f@entry=Frame 0xf737bcf0, for file /home/bernat/cffi/testing/backend_tests.py, line 1562, in test_struct_packed (self=<TestFFI at remote 0xf738c210>, ffi=<FFI(_parser=<Parser(_packed=False, _structnode2type=<WeakKeyDictionary(_remove=<function at remote 0xf73e94f0>, _pending_removals=[], _iterating=set([]), data={<weakref at remote 0xf741a6f0>: <StructType(fldtypes=(<PrimitiveType(c_name_with_marker='char&', name='char') at remote 0xf73ddb30>, <PrimitiveType(c_name_with_marker='int&', name='int') at remote 0xf73cd990>), name='is_packed', completed=2, forcename=None, packed=True, c_name_with_marker='struct is_packed&', fldnames=('a', 'b'), fldbitsize=(-1, -1)) at remote 0xf738c290>}) at remote 0xf742a760>, _override=False, _partial_length=False, _declarations={'struct is_packed': <...>, 'struct nonpacked': <StructType(fldtypes=(<...>, <...>), name='nonpacked', completed=2, forcename=None, packed=False, c_name_with_marker='struct nonpacked&', fldnames=('a', 'b'), fldbitsize=(-1, -1)) at remote 0xf738c1d0>}, _anonymous_...(truncated),
throwflag=throwflag@entry=0) at ../Python/ceval.c:2005
#4 0x0011bfec in PyEval_EvalCodeEx (co=0xf75ac410, globals=<optimized out>, locals=locals@entry=0x0,
args=args@entry=0xf737e89c, argcount=<optimized out>, kws=kws@entry=0xf7ca403c,
kwcount=kwcount@entry=0, defs=defs@entry=0x0, defcount=defcount@entry=0, closure=0x0)
at ../Python/ceval.c:3253
I have bisected the problem to this changeset:
changeset: 1453:c5e17441bc96
user: Armin Rigo <arigo@tunes.org>
date: Tue Jan 14 09:06:06 2014 +0100
summary: Issue 131: support ffi.cdef("...", packed=True)
The failing test is testing/backend_tests.py@1553::TestFFI::test_struct_packed
but as it was just added in the changeset. I think the problem was already here. Sparc doesn't accept unaligned memory access. We should use memcpy() instead of assignment when we don't know if everything is aligned properly. Other architectures may exhibit the problem depending of the system configuration (like mips) or can be just slower on unaligned accesses (like arm). Or maybe the reverse, don't remember.
I will test and propose a fix shortly.