summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Cournapeau <cournape@gmail.com>2009-06-30 10:08:27 +0000
committerDavid Cournapeau <cournape@gmail.com>2009-06-30 10:08:27 +0000
commit8e96f6afadbb5e985442d5821e6f79eb5f795a7b (patch)
tree2477f1b3ff95708a16cf82cca45810e5ba48cd5a
parentdfd3b749cb4c423ea4c211044f34d36bc07218ba (diff)
downloadnumpy-8e96f6afadbb5e985442d5821e6f79eb5f795a7b.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...
-rw-r--r--doc/source/reference/c-api.config.rst4
-rw-r--r--numpy/core/code_generators/generate_numpy_api.py4
-rw-r--r--numpy/core/include/numpy/ndarrayobject.h2
-rw-r--r--numpy/core/include/numpy/npy_endian.h19
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 33e3aeaa4..06bb6d4d2 100644
--- a/numpy/core/code_generators/generate_numpy_api.py
+++ b/numpy/core/code_generators/generate_numpy_api.py
@@ -115,13 +115,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 57c4daab5..479ac2771 100644
--- a/numpy/core/include/numpy/ndarrayobject.h
+++ b/numpy/core/include/numpy/ndarrayobject.h
@@ -1096,7 +1096,7 @@ PyArrayNeighborhoodIter_Next2D(PyArrayNeighborhoodIterObject* iter);
#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