static int _NI_GetIndices(PyObject* indices_object, maybelong** result_indices, maybelong* min_label, maybelong* max_label, maybelong* n_results) { maybelong *indices = NULL, n_indices, ii; if (indices_object == Py_None) { *min_label = -1; *n_results = 1; } else { n_indices = NI_ObjectToLongSequenceAndLength(indices_object, &indices); if (n_indices < 0) goto exit; if (n_indices < 1) { PyErr_SetString(PyExc_RuntimeError, "no correct indices provided"); goto exit; } else { *min_label = *max_label = indices[0]; if (*min_label < 0) { PyErr_SetString(PyExc_RuntimeError, "negative indices not allowed"); goto exit; } for(ii = 1; ii < n_indices; ii++) { if (indices[ii] < 0) { PyErr_SetString(PyExc_RuntimeError, "negative indices not allowed"); goto exit; } if (indices[ii] < *min_label) *min_label = indices[ii]; if (indices[ii] > *max_label) *max_label = indices[ii]; } *result_indices = (maybelong*)malloc((*max_label - *min_label + 1) * sizeof(maybelong)); if (!*result_indices) { PyErr_NoMemory(); goto exit; } for(ii = 0; ii < *max_label - *min_label + 1; ii++) (*result_indices)[ii] = -1; *n_results = 0; for(ii = 0; ii < n_indices; ii++) { if ((*result_indices)[indices[ii] - *min_label] >= 0) { PyErr_SetString(PyExc_RuntimeError, "duplicate index"); goto exit; } (*result_indices)[indices[ii] - *min_label] = ii; ++(*n_results); } } } exit: if (indices) free(indices); return PyErr_Occurred() == NULL; }
static int NI_ObjectToLongSequence(PyObject *object, npy_intp **sequence) { return NI_ObjectToLongSequenceAndLength(object, sequence) >= 0; }
static int NI_ObjectToLongSequence(PyObject *object, maybelong **sequence) { return NI_ObjectToLongSequenceAndLength(object, sequence) >= 0; }