summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaime <jaime.frio@gmail.com>2016-08-24 09:21:39 +0200
committerGitHub <noreply@github.com>2016-08-24 09:21:39 +0200
commitd92c75b46fa316a7711049c278bfb4d4f11b2349 (patch)
tree78eebc88feb521d952f00020e794dcc474460683
parent276423aa7f4f7d39189ee5ccf7b167ad2c9c25a7 (diff)
parent4433421ad3b1306b42e1023658a9bab7813f5838 (diff)
downloadnumpy-d92c75b46fa316a7711049c278bfb4d4f11b2349.tar.gz
Merge pull request #7965 from mattip/fix-modify-tuple
BUG: cannot modify tuple after use
-rw-r--r--numpy/core/src/multiarray/multiarraymodule.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c
index d90debc6f..39acf87fa 100644
--- a/numpy/core/src/multiarray/multiarraymodule.c
+++ b/numpy/core/src/multiarray/multiarraymodule.c
@@ -3635,7 +3635,6 @@ _vec_string_with_args(PyArrayObject* char_array, PyArray_Descr* type,
PyArrayMultiIterObject* in_iter = NULL;
PyArrayObject* result = NULL;
PyArrayIterObject* out_iter = NULL;
- PyObject* args_tuple = NULL;
Py_ssize_t i, n, nargs;
nargs = PySequence_Size(args) + 1;
@@ -3672,18 +3671,18 @@ _vec_string_with_args(PyArrayObject* char_array, PyArray_Descr* type,
goto err;
}
- args_tuple = PyTuple_New(n);
- if (args_tuple == NULL) {
- goto err;
- }
-
while (PyArray_MultiIter_NOTDONE(in_iter)) {
PyObject* item_result;
+ PyObject* args_tuple = PyTuple_New(n);
+ if (args_tuple == NULL) {
+ goto err;
+ }
for (i = 0; i < n; i++) {
PyArrayIterObject* it = in_iter->iters[i];
PyObject* arg = PyArray_ToScalar(PyArray_ITER_DATA(it), it->ao);
if (arg == NULL) {
+ Py_DECREF(args_tuple);
goto err;
}
/* Steals ref to arg */
@@ -3691,6 +3690,7 @@ _vec_string_with_args(PyArrayObject* char_array, PyArray_Descr* type,
}
item_result = PyObject_CallObject(method, args_tuple);
+ Py_DECREF(args_tuple);
if (item_result == NULL) {
goto err;
}
@@ -3709,14 +3709,12 @@ _vec_string_with_args(PyArrayObject* char_array, PyArray_Descr* type,
Py_DECREF(in_iter);
Py_DECREF(out_iter);
- Py_DECREF(args_tuple);
return (PyObject*)result;
err:
Py_XDECREF(in_iter);
Py_XDECREF(out_iter);
- Py_XDECREF(args_tuple);
Py_XDECREF(result);
return 0;