Skip to content

Commit

Permalink
Merge pull request numpy#7965 from mattip/fix-modify-tuple
Browse files Browse the repository at this point in the history
BUG: cannot modify tuple after use
  • Loading branch information
jaimefrio authored Aug 24, 2016
2 parents 276423a + 4433421 commit d92c75b
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions numpy/core/src/multiarray/multiarraymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -3672,25 +3671,26 @@ _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 */
PyTuple_SetItem(args_tuple, i, arg);
}

item_result = PyObject_CallObject(method, args_tuple);
Py_DECREF(args_tuple);
if (item_result == NULL) {
goto err;
}
Expand All @@ -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;
Expand Down

0 comments on commit d92c75b

Please sign in to comment.