Skip to content

Commit

Permalink
refactor bugfix #201
Browse files Browse the repository at this point in the history
  • Loading branch information
kwgoodman committed Jan 4, 2019
1 parent d30741d commit 3eb2ff8
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions bottleneck/src/reduce_template.c
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,7 @@ reducer(char *name,
int reduce_all = 0;

PyArrayObject *a;
static PyObject *y;
PyObject *y;

PyObject *a_obj = NULL;
PyObject *axis_obj = Py_None;
Expand Down Expand Up @@ -1255,23 +1255,20 @@ reducer(char *name,
axis = PyArray_PyIntAsInt(axis_obj);
if (error_converting(axis)) {
TYPE_ERR("`axis` must be an integer or None");
Py_DECREF(a);
return NULL;
goto cleanup;
}
ndim = PyArray_NDIM(a);
if (axis < 0) {
axis += ndim;
if (axis < 0) {
PyErr_Format(PyExc_ValueError,
"axis(=%d) out of bounds", axis);
Py_DECREF(a);
return NULL;
goto cleanup;
}
}
else if (axis >= ndim) {
PyErr_Format(PyExc_ValueError, "axis(=%d) out of bounds", axis);
Py_DECREF(a);
return NULL;
goto cleanup;
}
if (ndim == 1) {
reduce_all = 1;
Expand All @@ -1286,8 +1283,7 @@ reducer(char *name,
ddof = PyArray_PyIntAsInt(ddof_obj);
if (error_converting(ddof)) {
TYPE_ERR("`ddof` must be an integer");
Py_DECREF(a);
return NULL;
goto cleanup;
}
}

Expand Down Expand Up @@ -1335,6 +1331,10 @@ reducer(char *name,

return y;

cleanup:
Py_DECREF(a);
return NULL;

}

/* docstrings ------------------------------------------------------------- */
Expand Down

0 comments on commit 3eb2ff8

Please sign in to comment.