-
-
Couldn't load subscription status.
- Fork 5.7k
fix reinterpret(Char, ::UInt32) for "unnatural" values (fix #29181) #29192
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
Conversation
87083bb to
3759d23
Compare
src/datatype.c
Outdated
| jl_ptls_t ptls = jl_get_ptls_states(); | ||
| if (0 < (int32_t)x) | ||
| return boxed_char_cache[x >> 24]; | ||
| uint32_t u = __builtin_bswap32(x); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have bswap_32 defined for this for a few platforms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bswap_32 is the correct version since it takes care of the difference between clang, ICC, MSVC, or not having the builtin available at all.
see
Lines 32 to 57 in 7507511
| #if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ > 4 || __GNUC_MINOR__ >= 8)) | |
| #define bswap_16(x) __builtin_bswap16(x) | |
| #define bswap_32(x) __builtin_bswap32(x) | |
| #define bswap_64(x) __builtin_bswap64(x) | |
| #elif defined(_MSC_VER) | |
| #define bswap_16(x) _byteswap_ushort(x) | |
| #define bswap_32(x) _byteswap_ulong(x) | |
| #define bswap_64(x) _byteswap_uint64(x) | |
| #elif defined(__INTEL_COMPILER) | |
| #define bswap_16(x) _bswap16(x) | |
| #define bswap_32(x) _bswap(x) | |
| #define bswap_64(x) _bswap64(x) | |
| #else | |
| #define bswap_16(x) (((x) & 0x00ff) << 8 | ((x) & 0xff00) >> 8) | |
| #define bswap_32(x) \ | |
| ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \ | |
| (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)) | |
| STATIC_INLINE uint64_t ByteSwap64(uint64_t x) | |
| { | |
| uint32_t high = (uint32_t) (x >> 32); | |
| uint32_t low = (uint32_t) x; | |
| return ((uint64_t) bswap_32 (high)) | | |
| (((uint64_t) bswap_32 (low)) << 32); | |
| } | |
| #define bswap_64(x) ByteSwap64(x) | |
| #endif |
3759d23 to
0a18ca9
Compare
This code was assuming that character values only have bit-patterns that decoding a string can produce, but of course `reinterpret` can produce any bit pattern in a `Char` whatsoever. The fix doesn't use that assumption and only uses the cache for actual ASCII characters.
0a18ca9 to
7d3fdcd
Compare
|
We're seeing a lot of httpbin flakiness again. Time to switch, @staticfloat? |
|
@StefanKarpinski your wish is my command: #29228 |
…29192) This code was assuming that character values only have bit-patterns that decoding a string can produce, but of course `reinterpret` can produce any bit pattern in a `Char` whatsoever. The fix doesn't use that assumption and only uses the cache for actual ASCII characters. (cherry picked from commit 88f74b7)
…29192) This code was assuming that character values only have bit-patterns that decoding a string can produce, but of course `reinterpret` can produce any bit pattern in a `Char` whatsoever. The fix doesn't use that assumption and only uses the cache for actual ASCII characters. (cherry picked from commit 88f74b7)
…29192) This code was assuming that character values only have bit-patterns that decoding a string can produce, but of course `reinterpret` can produce any bit pattern in a `Char` whatsoever. The fix doesn't use that assumption and only uses the cache for actual ASCII characters. (cherry picked from commit 88f74b7)
…29192) This code was assuming that character values only have bit-patterns that decoding a string can produce, but of course `reinterpret` can produce any bit pattern in a `Char` whatsoever. The fix doesn't use that assumption and only uses the cache for actual ASCII characters. (cherry picked from commit 88f74b7)
No description provided.