diff options
author | Stefan Behnel <stefan_ml@behnel.de> | 2021-09-01 00:09:02 +0200 |
---|---|---|
committer | Stefan Behnel <stefan_ml@behnel.de> | 2021-09-01 09:08:21 +0200 |
commit | 2c08fd50d62e4255602ee3c0d41157df7608e773 (patch) | |
tree | 8a5c417e09118e776186d00569bb6a85d88e2ce2 | |
parent | 58d6a7d7f2be284638e62724a43b0ecc80d31cf9 (diff) | |
download | cython-2c08fd50d62e4255602ee3c0d41157df7608e773.tar.gz |
Avoid copying unaligned 16-bit values since some platforms require them to be aligned. Use memcpy() instead to let the C compiler decide how to do it.
Closes https://github.com/cython/cython/issues/4343
-rw-r--r-- | Cython/Utility/TypeConversion.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/Cython/Utility/TypeConversion.c b/Cython/Utility/TypeConversion.c index 751d12b62..3669bc9ec 100644 --- a/Cython/Utility/TypeConversion.c +++ b/Cython/Utility/TypeConversion.c @@ -788,10 +788,10 @@ static const char DIGITS_HEX[2*16+1] = { static CYTHON_INLINE PyObject* {{TO_PY_FUNCTION}}({{TYPE}} value, Py_ssize_t width, char padding_char, char format_char); /////////////// CIntToPyUnicode /////////////// +//@requires: StringTools.c::IncludeStringH //@requires: StringTools.c::BuildPyUnicode //@requires: CIntToDigits //@requires: GCCDiagnostics - // NOTE: inlining because most arguments are constant, which collapses lots of code below static CYTHON_INLINE PyObject* {{TO_PY_FUNCTION}}({{TYPE}} value, Py_ssize_t width, char padding_char, char format_char) { @@ -829,14 +829,14 @@ static CYTHON_INLINE PyObject* {{TO_PY_FUNCTION}}({{TYPE}} value, Py_ssize_t wid digit_pos = abs((int)(remaining % (8*8))); remaining = ({{TYPE}}) (remaining / (8*8)); dpos -= 2; - *(uint16_t*)dpos = ((const uint16_t*)DIGIT_PAIRS_8)[digit_pos]; /* copy 2 digits at a time */ + memcpy(dpos, DIGIT_PAIRS_8 + digit_pos * 2, 2); /* copy 2 digits at a time, unaligned */ last_one_off = (digit_pos < 8); break; case 'd': digit_pos = abs((int)(remaining % (10*10))); remaining = ({{TYPE}}) (remaining / (10*10)); dpos -= 2; - *(uint16_t*)dpos = ((const uint16_t*)DIGIT_PAIRS_10)[digit_pos]; /* copy 2 digits at a time */ + memcpy(dpos, DIGIT_PAIRS_10 + digit_pos * 2, 2); /* copy 2 digits at a time, unaligned */ last_one_off = (digit_pos < 10); break; case 'x': |