Skip to content

Commit

Permalink
MAINT: use PyErr_SetString in _import_array where possible
Browse files Browse the repository at this point in the history
Update error messages in _import_array to avoid format string
processing when not needed by the error message text.
  • Loading branch information
karlotness committed Jun 20, 2022
1 parent 2b00ad2 commit fb73e4e
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions numpy/core/code_generators/generate_numpy_api.py
Expand Up @@ -89,19 +89,22 @@
*/
st = PyArray_GetEndianness();
if (st == NPY_CPU_UNKNOWN_ENDIAN) {
PyErr_Format(PyExc_RuntimeError, "FATAL: module compiled as unknown endian");
PyErr_SetString(PyExc_RuntimeError,
"FATAL: module compiled as unknown endian");
return -1;
}
#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");
PyErr_SetString(PyExc_RuntimeError,
"FATAL: module compiled as big endian, but "
"detected different endianness at runtime");
return -1;
}
#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");
PyErr_SetString(PyExc_RuntimeError,
"FATAL: module compiled as little endian, but "
"detected different endianness at runtime");
return -1;
}
#endif
Expand Down

0 comments on commit fb73e4e

Please sign in to comment.