diff options
| author | Travis E. Oliphant <teoliphant@gmail.com> | 2012-12-15 19:30:08 -0800 |
|---|---|---|
| committer | Travis E. Oliphant <teoliphant@gmail.com> | 2012-12-15 19:30:08 -0800 |
| commit | afde23f1897812570f176227fb1d32245c28bb3c (patch) | |
| tree | 5a0ef8eefdde30f17e30ab3151dd701ffab0204c | |
| parent | 5f04dc8a53346e8225d0865a0e7064e4f4d93d4b (diff) | |
| parent | 3c23c9f6f50b5bea5f449cddd607d5758e4b45b1 (diff) | |
| download | numpy-afde23f1897812570f176227fb1d32245c28bb3c.tar.gz | |
Merge pull request #2831 from certik/fix2738
FIX: Fixes the segfault in PyArray_FromScalar
| -rw-r--r-- | numpy/core/src/multiarray/scalarapi.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/numpy/core/src/multiarray/scalarapi.c b/numpy/core/src/multiarray/scalarapi.c index fcc68e9ba..810029a73 100644 --- a/numpy/core/src/multiarray/scalarapi.c +++ b/numpy/core/src/multiarray/scalarapi.c @@ -295,17 +295,20 @@ PyArray_FromScalar(PyObject *scalar, PyArray_Descr *outcode) return (PyObject *)r; } + /* Need to INCREF typecode because PyArray_NewFromDescr steals a + * reference below and we still need to access typecode afterwards. */ + Py_INCREF(typecode); r = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, typecode, 0, NULL, NULL, NULL, 0, NULL); if (r==NULL) { - Py_XDECREF(outcode); + Py_DECREF(typecode); Py_XDECREF(outcode); return NULL; } if (PyDataType_FLAGCHK(typecode, NPY_USE_SETITEM)) { if (typecode->f->setitem(scalar, PyArray_DATA(r), r) < 0) { - Py_XDECREF(outcode); Py_DECREF(r); + Py_DECREF(typecode); Py_XDECREF(outcode); Py_DECREF(r); return NULL; } goto finish; @@ -332,19 +335,20 @@ PyArray_FromScalar(PyObject *scalar, PyArray_Descr *outcode) finish: if (outcode == NULL) { + Py_DECREF(typecode); return (PyObject *)r; } if (PyArray_EquivTypes(outcode, typecode)) { if (!PyTypeNum_ISEXTENDED(typecode->type_num) || (outcode->elsize == typecode->elsize)) { - Py_DECREF(outcode); + Py_DECREF(typecode); Py_DECREF(outcode); return (PyObject *)r; } } /* cast if necessary to desired output typecode */ ret = PyArray_CastToType((PyArrayObject *)r, outcode, 0); - Py_DECREF(r); + Py_DECREF(typecode); Py_DECREF(r); return ret; } |
