* Unpack a tuple into an array of new references. Returns the number of objects * unpacked. * * Useful if a tuple is being iterated over multiple times, or for a code path * that doesn't always want the overhead of allocating a tuple. */
| 177 | * that doesn't always want the overhead of allocating a tuple. |
| 178 | */ |
| 179 | static inline npy_intp |
| 180 | unpack_tuple(PyTupleObject *index, PyObject **result, npy_intp result_n) |
| 181 | { |
| 182 | npy_intp n, i; |
| 183 | n = PyTuple_GET_SIZE(index); |
| 184 | if (n > result_n) { |
| 185 | PyErr_SetString(PyExc_IndexError, |
| 186 | "too many indices for array"); |
| 187 | return -1; |
| 188 | } |
| 189 | for (i = 0; i < n; i++) { |
| 190 | result[i] = PyTuple_GET_ITEM(index, i); |
| 191 | Py_INCREF(result[i]); |
| 192 | } |
| 193 | return n; |
| 194 | } |
| 195 | |
| 196 | /* Unpack a single scalar index, taking a new reference to match unpack_tuple */ |
| 197 | static inline npy_intp |