authorgravatar for koachan@protonmail.comKoakuma <koachan@protonmail.com> 2020-12-04 03:47:06+07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-12-03 13:47:31-07:00
log52de625df991126899d7f547e669a949bb85e923
tree647ff1c27ec36bdc6788e86b7aa925d8f5287840
parentcdde9d8885c887783bd1999281063cd202a648cb

Fix floating point parsing on BE systems (#7256)

* Fix floating point parsing on BE systems * Load the appropriate endian.h files for macOS and BSD * Add endian definition for Windows and extra check for ldshape selection * Fix endian macro definition for macOS Apparently their macros are defined without a leading __. * Define new macro for endian checking purposes This is gross and I really do not like the lack of standardization around this part, but what can I do?

1 files changed, 25 insertions(+), 3 deletions(-)

src/stage1/parse_f128.c+25-3
...@@ -10,6 +10,28 @@...@@ -10,6 +10,28 @@
10#include <string.h>10#include <string.h>
11#include <math.h>11#include <math.h>
1212
13// Every OSes seem to define endianness macros in different files.
14#if defined(__APPLE__)
15 #include <machine/endian.h>
16 #define ZIG_BIG_ENDIAN BIG_ENDIAN
17 #define ZIG_LITTLE_ENDIAN LITTLE_ENDIAN
18 #define ZIG_BYTE_ORDER BYTE_ORDER
19#elif defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
20 #include <sys/endian.h>
21 #define ZIG_BIG_ENDIAN _BIG_ENDIAN
22 #define ZIG_LITTLE_ENDIAN _LITTLE_ENDIAN
23 #define ZIG_BYTE_ORDER _BYTE_ORDER
24#elif defined(_WIN32) || defined(_WIN64)
25 // Assume that Windows installations are always little endian.
26 #define ZIG_LITTLE_ENDIAN 1
27 #define ZIG_BYTE_ORDER ZIG_LITTLE_ENDIAN
28#else // Linux
29 #include <endian.h>
30 #define ZIG_BIG_ENDIAN __BIG_ENDIAN
31 #define ZIG_LITTLE_ENDIAN __LITTLE_ENDIAN
32 #define ZIG_BYTE_ORDER __BYTE_ORDER
33#endif
34
13#define shcnt(f) ((f)->shcnt + ((f)->rpos - (f)->buf))35#define shcnt(f) ((f)->shcnt + ((f)->rpos - (f)->buf))
14#define shlim(f, lim) __shlim((f), (lim))36#define shlim(f, lim) __shlim((f), (lim))
15#define shgetc(f) (((f)->rpos != (f)->shend) ? *(f)->rpos++ : __shgetc(f))37#define shgetc(f) (((f)->rpos != (f)->shend) ? *(f)->rpos++ : __shgetc(f))
...@@ -47,8 +69,7 @@...@@ -47,8 +69,7 @@
4769
48#define DECIMAL_DIG 3670#define DECIMAL_DIG 36
4971
5072#if defined(ZIG_BYTE_ORDER) && ZIG_BYTE_ORDER == ZIG_LITTLE_ENDIAN
51#if __BYTE_ORDER == __LITTLE_ENDIAN
52union ldshape {73union ldshape {
53 float128_t f;74 float128_t f;
54 struct {75 struct {
...@@ -62,7 +83,7 @@ union ldshape {...@@ -62,7 +83,7 @@ union ldshape {
62 uint64_t hi;83 uint64_t hi;
63 } i2;84 } i2;
64};85};
65#elif __BYTE_ORDER == __BIG_ENDIAN86#elif defined(ZIG_BYTE_ORDER) && ZIG_BYTE_ORDER == ZIG_BIG_ENDIAN
66union ldshape {87union ldshape {
67 float128_t f;88 float128_t f;
68 struct {89 struct {
...@@ -76,6 +97,7 @@ union ldshape {...@@ -76,6 +97,7 @@ union ldshape {
76 uint64_t lo;97 uint64_t lo;
77 } i2;98 } i2;
78};99};
100#else
79#error Unsupported endian101#error Unsupported endian
80#endif102#endif
81103