diff options
| author | Eric Wieser <wieser.eric@gmail.com> | 2018-01-05 10:04:10 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-01-05 10:04:10 -0800 |
| commit | ba9991e0900f38568c5e3d326e2ce88c6b73e907 (patch) | |
| tree | f601438a111de134a6712439422dc7f34bdbfe24 /numpy/core/src | |
| parent | 10ccfe747a68d974ff16a5c0765054b816d5486f (diff) | |
| parent | a670fa652bf582a5454249ee0104249410714168 (diff) | |
| download | numpy-ba9991e0900f38568c5e3d326e2ce88c6b73e907.tar.gz | |
Merge pull request #10158 from seberg/fix-valgrind-errs
BUG: Fix a few smaller valgrind errors
Diffstat (limited to 'numpy/core/src')
| -rw-r--r-- | numpy/core/src/multiarray/ctors.c | 22 | ||||
| -rw-r--r-- | numpy/core/src/umath/test_rational.c.src | 12 |
2 files changed, 20 insertions, 14 deletions
diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c index f4236f36d..31457704e 100644 --- a/numpy/core/src/multiarray/ctors.c +++ b/numpy/core/src/multiarray/ctors.c @@ -2181,7 +2181,6 @@ _is_default_descr(PyObject *descr, PyObject *typestr) { NPY_NO_EXPORT PyObject * PyArray_FromInterface(PyObject *origin) { - PyObject *tmp = NULL; PyObject *iface = NULL; PyObject *attr = NULL; PyObject *base = NULL; @@ -2216,9 +2215,15 @@ PyArray_FromInterface(PyObject *origin) #if defined(NPY_PY3K) /* Allow unicode type strings */ if (PyUnicode_Check(attr)) { - tmp = PyUnicode_AsASCIIString(attr); + PyObject *tmp = PyUnicode_AsASCIIString(attr); + if (tmp == NULL) { + goto fail; + } attr = tmp; } + else { + Py_INCREF(attr); + } #endif if (!PyBytes_Check(attr)) { PyErr_SetString(PyExc_TypeError, @@ -2227,11 +2232,6 @@ PyArray_FromInterface(PyObject *origin) } /* Get dtype from type string */ dtype = _array_typedescr_fromstr(PyString_AS_STRING(attr)); -#if defined(NPY_PY3K) - if (tmp == attr) { - Py_DECREF(tmp); - } -#endif if (dtype == NULL) { goto fail; } @@ -2251,6 +2251,10 @@ PyArray_FromInterface(PyObject *origin) dtype = new_dtype; } } + +#if defined(NPY_PY3K) + Py_DECREF(attr); /* Pairs with the unicode handling above */ +#endif /* Get shape tuple from interface specification */ attr = PyDict_GetItemString(iface, "shape"); @@ -2278,7 +2282,7 @@ PyArray_FromInterface(PyObject *origin) else { n = PyTuple_GET_SIZE(attr); for (i = 0; i < n; i++) { - tmp = PyTuple_GET_ITEM(attr, i); + PyObject *tmp = PyTuple_GET_ITEM(attr, i); dims[i] = PyArray_PyIntAsIntp(tmp); if (error_converting(dims[i])) { goto fail; @@ -2395,7 +2399,7 @@ PyArray_FromInterface(PyObject *origin) goto fail; } for (i = 0; i < n; i++) { - tmp = PyTuple_GET_ITEM(attr, i); + PyObject *tmp = PyTuple_GET_ITEM(attr, i); strides[i] = PyArray_PyIntAsIntp(tmp); if (error_converting(strides[i])) { Py_DECREF(ret); diff --git a/numpy/core/src/umath/test_rational.c.src b/numpy/core/src/umath/test_rational.c.src index 26c3d3799..ffc92b732 100644 --- a/numpy/core/src/umath/test_rational.c.src +++ b/numpy/core/src/umath/test_rational.c.src @@ -394,14 +394,14 @@ pyrational_new(PyTypeObject* type, PyObject* args, PyObject* kwds) { return 0; } size = PyTuple_GET_SIZE(args); - if (size>2) { + if (size > 2) { PyErr_SetString(PyExc_TypeError, "expected rational or numerator and optional denominator"); return 0; } - x[0] = PyTuple_GET_ITEM(args,0); - x[1] = PyTuple_GET_ITEM(args,1); - if (size==1) { + + if (size == 1) { + x[0] = PyTuple_GET_ITEM(args, 0); if (PyRational_Check(x[0])) { Py_INCREF(x[0]); return x[0]; @@ -424,9 +424,11 @@ pyrational_new(PyTypeObject* type, PyObject* args, PyObject* kwds) { return 0; } } - for (i=0;i<size;i++) { + + for (i=0; i<size; i++) { PyObject* y; int eq; + x[i] = PyTuple_GET_ITEM(args, i); n[i] = PyInt_AsLong(x[i]); if (error_converting(n[i])) { if (PyErr_ExceptionMatches(PyExc_TypeError)) { |
