From 114c42641335bdc26cbf61c18c82b0f5c8a6d4f8 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Wed, 17 Oct 2012 23:52:17 +0200 Subject: Issue #16166: Add PY_LITTLE_ENDIAN and PY_BIG_ENDIAN macros and unified endianess detection and handling. --- Modules/_struct.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'Modules/_struct.c') diff --git a/Modules/_struct.c b/Modules/_struct.c index 0b20e26e6b..0f501447b6 100644 --- a/Modules/_struct.c +++ b/Modules/_struct.c @@ -1199,12 +1199,11 @@ whichtable(char **pfmt) case '!': /* Network byte order is big-endian */ return bigendian_table; case '=': { /* Host byte order -- different from native in alignment! */ - int n = 1; - char *p = (char *) &n; - if (*p == 1) - return lilendian_table; - else - return bigendian_table; +#if PY_LITTLE_ENDIAN + return lilendian_table; +#else + return bigendian_table; +#endif } default: --*pfmt; /* Back out of pointer increment */ @@ -2088,13 +2087,13 @@ PyInit__struct(void) /* Check endian and swap in faster functions */ { - int one = 1; formatdef *native = native_table; formatdef *other, *ptr; - if ((int)*(unsigned char*)&one) - other = lilendian_table; - else - other = bigendian_table; +#if PY_LITTLE_ENDIAN + other = lilendian_table; +#else + other = bigendian_table; +#endif /* Scan through the native table, find a matching entry in the endian table and swap in the native implementations whenever possible -- cgit v1.2.1