* Returns -1 and sets an exception if *index is an invalid index for * an array of size max_item, otherwise adjusts it in place to be * 0 <= *index < max_item, and returns 0. * 'axis' should be the array axis that is being indexed over, if known. If * unknown, use -1. * If _save is NULL it is assumed the GIL is taken * If _save is not NULL it is assumed the GIL is not taken and it * is acqu
| 101 | * is acquired in the case of an error |
| 102 | */ |
| 103 | static inline int |
| 104 | check_and_adjust_index(npy_intp *index, npy_intp max_item, int axis, |
| 105 | PyThreadState * _save) |
| 106 | { |
| 107 | /* Check that index is valid, taking into account negative indices */ |
| 108 | if (NPY_UNLIKELY((*index < -max_item) || (*index >= max_item))) { |
| 109 | NPY_END_THREADS; |
| 110 | /* Try to be as clear as possible about what went wrong. */ |
| 111 | if (axis >= 0) { |
| 112 | PyErr_Format(PyExc_IndexError, |
| 113 | "index %"NPY_INTP_FMT" is out of bounds " |
| 114 | "for axis %d with size %"NPY_INTP_FMT, |
| 115 | *index, axis, max_item); |
| 116 | } else { |
| 117 | PyErr_Format(PyExc_IndexError, |
| 118 | "index %"NPY_INTP_FMT" is out of bounds " |
| 119 | "for size %"NPY_INTP_FMT, *index, max_item); |
| 120 | } |
| 121 | return -1; |
| 122 | } |
| 123 | /* adjust negative indices */ |
| 124 | if (*index < 0) { |
| 125 | *index += max_item; |
| 126 | } |
| 127 | return 0; |
| 128 | } |
| 129 | |
| 130 | /* |
| 131 | * Returns -1 and sets an exception if *axis is an invalid axis for |
no outgoing calls
no test coverage detected