diff options
-rw-r--r-- | numpy/core/src/multiarray/arraytypes.c.src | 53 | ||||
-rw-r--r-- | numpy/core/src/scalarmathmodule.c.src | 10 | ||||
-rw-r--r-- | numpy/core/src/umath/loops.c.src | 16 |
3 files changed, 30 insertions, 49 deletions
diff --git a/numpy/core/src/multiarray/arraytypes.c.src b/numpy/core/src/multiarray/arraytypes.c.src index c9d517c50..5f0425f60 100644 --- a/numpy/core/src/multiarray/arraytypes.c.src +++ b/numpy/core/src/multiarray/arraytypes.c.src @@ -439,15 +439,11 @@ STRING_setitem(PyObject *op, char *ov, PyArrayObject *ap) PyObject *temp = NULL; if (!PyBytes_Check(op) && !PyUnicode_Check(op) - && PySequence_Check(op) && PySequence_Size(op) > 0) { + && PySequence_Check(op) && PySequence_Size(op) != 0) { PyErr_SetString(PyExc_ValueError, - "setting an array element with a sequence"); + "cannot set an array element with a sequence"); return -1; } - /* Sequence_Size might have returned an error */ - if (PyErr_Occurred()) { - PyErr_Clear(); - } #if defined(NPY_PY3K) if (PyUnicode_Check(op)) { /* Assume ASCII codec -- function similarly as Python 2 */ @@ -501,28 +497,15 @@ STRING_setitem(PyObject *op, char *ov, PyArrayObject *ap) static PyObject * OBJECT_getitem(char *ip, PyArrayObject *ap) { - /* TODO: We might be able to get away with just the "else" clause now */ - if (!ap || PyArray_ISALIGNED(ap)) { - if (*(PyObject **)ip == NULL) { - Py_INCREF(Py_None); - return Py_None; - } - else { - Py_INCREF(*(PyObject **)ip); - return *(PyObject **)ip; - } + PyObject *obj; + NPY_COPY_PYOBJECT_PTR(&obj, ip); + if (obj == NULL) { + Py_INCREF(Py_None); + return Py_None; } else { - PyObject *obj; - NPY_COPY_PYOBJECT_PTR(&obj, ip); - if (obj == NULL) { - Py_INCREF(Py_None); - return Py_None; - } - else { - Py_INCREF(obj); - return obj; - } + Py_INCREF(obj); + return obj; } } @@ -530,18 +513,14 @@ OBJECT_getitem(char *ip, PyArrayObject *ap) static int OBJECT_setitem(PyObject *op, char *ov, PyArrayObject *ap) { + PyObject *obj; + + NPY_COPY_PYOBJECT_PTR(&obj, ov); + Py_XDECREF(obj); + Py_INCREF(op); - /* TODO: We might be able to get away with just the "else" clause now */ - if (!ap || PyArray_ISALIGNED(ap)) { - Py_XDECREF(*(PyObject **)ov); - *(PyObject **)ov = op; - } - else { - PyObject *obj; - NPY_COPY_PYOBJECT_PTR(&obj, ov); - Py_XDECREF(obj); - NPY_COPY_PYOBJECT_PTR(ov, &op); - } + NPY_COPY_PYOBJECT_PTR(ov, &op); + return PyErr_Occurred() ? -1 : 0; } diff --git a/numpy/core/src/scalarmathmodule.c.src b/numpy/core/src/scalarmathmodule.c.src index d1a66e101..418e81531 100644 --- a/numpy/core/src/scalarmathmodule.c.src +++ b/numpy/core/src/scalarmathmodule.c.src @@ -704,10 +704,12 @@ static PyObject * PyObject *ret; npy_@name@ arg1, arg2; /* - * NOTE: In gcc >= 4.1, the compiler will reorder floating point operations and - * floating point error state checks. In particular, the arithmetic operations - * were being reordered so that the errors weren't caught. Declaring this output - * variable volatile was the minimal fix for the issue. (Ticket #1671) + * NOTE: In gcc >= 4.1, the compiler will reorder floating point + * operations and floating point error state checks. In + * particular, the arithmetic operations were being reordered + * so that the errors weren't caught. Declaring this output + * variable volatile was the minimal fix for the issue. + * (Ticket #1671) */ volatile npy_@otyp@ out; #if @twoout@ diff --git a/numpy/core/src/umath/loops.c.src b/numpy/core/src/umath/loops.c.src index 4bd2971c5..26cee7fa0 100644 --- a/numpy/core/src/umath/loops.c.src +++ b/numpy/core/src/umath/loops.c.src @@ -388,8 +388,8 @@ PyUFunc_O_O(char **args, intp *dimensions, intp *steps, void *func) UNARY_LOOP { PyObject *in1 = *(PyObject **)ip1; PyObject **out = (PyObject **)op1; - PyObject *ret = f(in1); - if ((ret == NULL) || PyErr_Occurred()) { + PyObject *ret = f(in1 ? in1 : Py_None); + if (ret == NULL) { return; } Py_XDECREF(*out); @@ -405,7 +405,7 @@ PyUFunc_O_O_method(char **args, intp *dimensions, intp *steps, void *func) UNARY_LOOP { PyObject *in1 = *(PyObject **)ip1; PyObject **out = (PyObject **)op1; - PyObject *ret = PyObject_CallMethod(in1, meth, NULL); + PyObject *ret = PyObject_CallMethod(in1 ? in1 : Py_None, meth, NULL); if (ret == NULL) { return; } @@ -423,8 +423,8 @@ PyUFunc_OO_O(char **args, intp *dimensions, intp *steps, void *func) PyObject *in1 = *(PyObject **)ip1; PyObject *in2 = *(PyObject **)ip2; PyObject **out = (PyObject **)op1; - PyObject *ret = f(in1, in2); - if (PyErr_Occurred()) { + PyObject *ret = f(in1 ? in1 : Py_None, in2 ? in2 : Py_None); + if (ret == NULL) { return; } Py_XDECREF(*out); @@ -441,7 +441,8 @@ PyUFunc_OO_O_method(char **args, intp *dimensions, intp *steps, void *func) PyObject *in1 = *(PyObject **)ip1; PyObject *in2 = *(PyObject **)ip2; PyObject **out = (PyObject **)op1; - PyObject *ret = PyObject_CallMethod(in1, meth, "(O)", in2); + PyObject *ret = PyObject_CallMethod(in1 ? in1 : Py_None, + meth, "(O)", in2); if (ret == NULL) { return; } @@ -482,8 +483,7 @@ PyUFunc_On_Om(char **args, intp *dimensions, intp *steps, void *func) for(j = 0; j < nin; j++) { in = *((PyObject **)ptrs[j]); if (in == NULL) { - Py_DECREF(arglist); - return; + in = Py_None; } PyTuple_SET_ITEM(arglist, j, in); Py_INCREF(in); |