diff options
author | David Cournapeau <cournape@gmail.com> | 2009-06-30 10:17:47 +0000 |
---|---|---|
committer | David Cournapeau <cournape@gmail.com> | 2009-06-30 10:17:47 +0000 |
commit | b67cd04f170e85436c64e602b5369033da210414 (patch) | |
tree | e0fd5a8a5bbe5fb3d8e77603dcf9908f1c6a6a8e | |
parent | bcde38d7ac80434ee50fc7a6b18c72e268946329 (diff) | |
download | numpy-b67cd04f170e85436c64e602b5369033da210414.tar.gz |
BUG: Fix NPY_* macros for endianness (#1154).
I managed to screw them up: they did not actually mimic the gblic
endian.h behavior, that is NPY_BIG_ENDIAN and NPY_LITTLE_ENDIAN should
always be defined, and endianness should be detected by comparison with
NPY_BYTE_ORDER. This needs to be fixed because the behavior of the NPY_
macros was different depending on whether endian.h was available or not.
Let's hope nobody depended on it...
(cherry picked from commit 1eee475d3429832bfaf4022ab24c9a50b97e123a)
-rw-r--r-- | doc/source/reference/c-api.config.rst | 4 | ||||
-rw-r--r-- | numpy/core/code_generators/generate_numpy_api.py | 4 | ||||
-rw-r--r-- | numpy/core/include/numpy/ndarrayobject.h | 2 | ||||
-rw-r--r-- | numpy/core/include/numpy/npy_endian.h | 19 |
4 files changed, 13 insertions, 16 deletions
diff --git a/doc/source/reference/c-api.config.rst b/doc/source/reference/c-api.config.rst index 0c7f6b147..0989c53d7 100644 --- a/doc/source/reference/c-api.config.rst +++ b/doc/source/reference/c-api.config.rst @@ -89,8 +89,8 @@ Platform information .. versionadded:: 1.3.0 Portable alternatives to the ``endian.h`` macros of GNU Libc. - One of :cdata:`NPY_BIG_ENDIAN` :cdata:`NPY_LITTLE_ENDIAN` or - is defined, and :cdata:`NPY_BYTE_ORDER` is either 4321 or 1234. + If big endian, :cdata:`NPY_BYTE_ORDER` == :cdata:`NPY_BIG_ENDIAN`, and + similarly for little endian architectures. Defined in ``numpy/npy_endian.h``. diff --git a/numpy/core/code_generators/generate_numpy_api.py b/numpy/core/code_generators/generate_numpy_api.py index 4dda84146..96a19d94f 100644 --- a/numpy/core/code_generators/generate_numpy_api.py +++ b/numpy/core/code_generators/generate_numpy_api.py @@ -94,13 +94,13 @@ _import_array(void) PyErr_Format(PyExc_RuntimeError, "FATAL: module compiled as unknown endian"); return -1; } -#ifdef NPY_BIG_ENDIAN +#if NPY_BYTE_ORDER ==NPY_BIG_ENDIAN if (st != NPY_CPU_BIG) { PyErr_Format(PyExc_RuntimeError, "FATAL: module compiled as "\ "big endian, but detected different endianness at runtime"); return -1; } -#elif defined(NPY_LITTLE_ENDIAN) +#elif NPY_BYTE_ORDER == NPY_LITTLE_ENDIAN if (st != NPY_CPU_LITTLE) { PyErr_Format(PyExc_RuntimeError, "FATAL: module compiled as"\ "little endian, but detected different endianness at runtime"); diff --git a/numpy/core/include/numpy/ndarrayobject.h b/numpy/core/include/numpy/ndarrayobject.h index d23aa0120..8c38acdd4 100644 --- a/numpy/core/include/numpy/ndarrayobject.h +++ b/numpy/core/include/numpy/ndarrayobject.h @@ -1038,7 +1038,7 @@ typedef struct { #define NPY_SWAP 's' #define NPY_IGNORE '|' -#ifdef NPY_BIG_ENDIAN +#if NPY_BYTE_ORDER == NPY_BIG_ENDIAN #define NPY_NATBYTE NPY_BIG #define NPY_OPPBYTE NPY_LITTLE #else diff --git a/numpy/core/include/numpy/npy_endian.h b/numpy/core/include/numpy/npy_endian.h index 0a5c05ef9..e0d534c86 100644 --- a/numpy/core/include/numpy/npy_endian.h +++ b/numpy/core/include/numpy/npy_endian.h @@ -9,26 +9,23 @@ #ifdef NPY_HAVE_ENDIAN_H /* Use endian.h if available */ #include <endian.h> + #define NPY_BYTE_ORDER __BYTE_ORDER - #if (__BYTE_ORDER == __LITTLE_ENDIAN) - #define NPY_LITTLE_ENDIAN - #elif (__BYTE_ORDER == __BIG_ENDIAN) - #define NPY_BIG_ENDIAN - #else - #error Unknown machine endianness detected. - #endif + #define NPY_LITTLE_ENDIAN __LITTLE_ENDIAN + #define NPY_BIG_ENDIAN __BIG_ENDIAN #else /* Set endianness info using target CPU */ #include "npy_cpu.h" + #define NPY_LITTLE_ENDIAN 1234 + #define NPY_BIG_ENDIAN 4321 + #if defined(NPY_CPU_X86) || defined(NPY_CPU_AMD64)\ || defined(NPY_CPU_IA64) - #define NPY_LITTLE_ENDIAN - #define NPY_BYTE_ORDER 1234 + #define NPY_BYTE_ORDER NPY_LITTLE_ENDIAN #elif defined(NPY_CPU_PPC) || defined(NPY_CPU_SPARC)\ || defined(NPY_CPU_S390) || defined(NPY_CPU_PARISC) || defined(NPY_CPU_PPC64) - #define NPY_BIG_ENDIAN - #define NPY_BYTE_ORDER 4321 + #define NPY_BYTE_ORDER NPY_BIG_ENDIAN #else #error Unknown CPU: can not set endianness #endif |