New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] fstring.format_c_numbers crashes with bus error #4343
Comments
Backtrace would always be useful. What I'd probably do is run it outside the test-suite: something like:
(that's untested though, but hopefully gives you a start anyway). Other things that might be useful:
|
Something in between is missing:
|
Possibly
Hopefully there should be a fstring.something.so file in the directory you're running Python from |
|
That so is from the original build. If I delete it I don't get it again, so some step is missing I fear.
|
@DerDakon, I think you need to pass Here's the backtrace I've gotten:
|
However, the warning output really tells already what's wrong:
In
and
are wrongly forcing 16-bit alignment. I can avoid the SIGBUS by forcing two 8-bit ops instead. |
Simply use memcpy(), the compiler knows when it can be reduced to a MOV or something similar because the platform does not need special alignment handling. |
Thanks @DerDakon and @mgorny (and sorry for my incomplete debugging suggestions). It sounds like The code in question looks to be about 5 years old so I'm not sure what changed that it started failing (probably doesn't really matter though) |
To be clear: are you suggesting to call This code in intended to compile down to a fast loop copying indirectly addressed bytes or byte pairs from a lookup table. Maybe we can just disable the two-byte copying on platforms that require aliasing and fall back to single bytes. But it's obviously more risky to detect such platforms ourselves than to let the C compiler do it for us. If |
Yes, just always use memcpy(). You can use the compiler explorer and use something like this to see that basically no compiler on the standard platforms actually issues any function call: #include <cstring>
short shorten(int *nums, int idx) {
short foo;
memcpy(&foo, nums + idx, sizeof(foo));
return foo;
} Ok, not exactly. "ARM gcc 8.3.1" does issue a memcpy(), but version 9 already optimizes that out. For x86-64 not even gcc 4.1 issues a call. MSVC x86 seems particularly dumb, but who cares for that these days anyway? |
MSVC is essentially the only way to get Cython to run on Windows (which is probably a more important platform to support that Sparc ;) ). Fortunately it does get it right and remove the |
I meant Windows x86. I suspect that beyond some tiny pseudo-embedded things noone has ever seen a recent Windows version on such a machine. Let alone one that isn't actually capable of running it in 64 bit mode instead. |
…em to be aligned. Use memcpy() instead to let the C compiler decide how to do it. Closes cython#4343
…em to be aligned. Use memcpy() instead to let the C compiler decide how to do it. Closes #4343
Describe the bug
Running the testsuite on my Sparc machine (these are very picky about unaligned accesses) crashes in fstring.format_c_numbers.
Environment (please complete the following information):
The error did not happen in 0.9.21
I'll try to get a backtrace, a hint on the right commandline to run this one test under gdb is welcome.
The text was updated successfully, but these errors were encountered: