Mercurial > cpython-lru_cache-weakref
diff Modules/_struct.c @ 79803:d2127cdec10e
Issue #16166: Add PY_LITTLE_ENDIAN and PY_BIG_ENDIAN macros and unified
endianess detection and handling.
| author | Christian Heimes <christian@cheimes.de> |
|---|---|
| date | Wed, 17 Oct 2012 23:52:17 +0200 |
| parents | 0eedf56f9a38 |
| children | ebc588a3db51 |
line wrap: on
line diff
--- a/Modules/_struct.c Wed Oct 17 17:33:26 2012 +0300 +++ b/Modules/_struct.c Wed Oct 17 23:52:17 2012 +0200 @@ -1199,12 +1199,11 @@ 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 @@ /* 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
