[Numpy-svn] r6035 - trunk/numpy/core/src
numpy-svn at scipy.org
numpy-svn at scipy.org
Sat Nov 15 23:01:08 EST 2008
Author: charris
Date: 2008-11-15 22:01:01 -0600 (Sat, 15 Nov 2008)
New Revision: 6035
Modified:
trunk/numpy/core/src/ufuncobject.c
trunk/numpy/core/src/umathmodule.c.src
Log:
Add error checking to Object loops.
Fix reference leak in Sign Object loop.
Define a binary version of PyNumber_Power so that the generic
object loop doesn't have to check for that function.
Clean up generic object loops.
Modified: trunk/numpy/core/src/ufuncobject.c
===================================================================
--- trunk/numpy/core/src/ufuncobject.c 2008-11-14 16:59:14 UTC (rev 6034)
+++ trunk/numpy/core/src/ufuncobject.c 2008-11-16 04:01:01 UTC (rev 6035)
@@ -268,12 +268,7 @@
UNARY_LOOP {
PyObject *in1 = *(PyObject **)ip1;
PyObject **out = (PyObject **)op1;
- PyObject *ret;
-
- if (in1 == NULL) {
- return;
- }
- ret = f(in1);
+ PyObject *ret = f(in1);
if ((ret == NULL) || PyErr_Occurred()) {
return;
}
@@ -291,7 +286,6 @@
PyObject *in1 = *(PyObject **)ip1;
PyObject **out = (PyObject **)op1;
PyObject *ret = PyObject_CallMethod(in1, meth, NULL);
-
if (ret == NULL) {
return;
}
@@ -304,21 +298,12 @@
static void
PyUFunc_OO_O(char **args, intp *dimensions, intp *steps, void *func)
{
+ binaryfunc f = (binaryfunc)func;
BINARY_LOOP {
PyObject *in1 = *(PyObject **)ip1;
PyObject *in2 = *(PyObject **)ip2;
PyObject **out = (PyObject **)op1;
- PyObject *ret;
-
- if ((in1 == NULL) || (in2 == NULL)) {
- return;
- }
- if ( (void *) func == (void *) PyNumber_Power) {
- ret = ((ternaryfunc)func)(in1, in2, Py_None);
- }
- else {
- ret = ((binaryfunc)func)(in1, in2);
- }
+ PyObject *ret = f(in1, in2);
if (PyErr_Occurred()) {
return;
}
@@ -337,7 +322,6 @@
PyObject *in2 = *(PyObject **)ip2;
PyObject **out = (PyObject **)op1;
PyObject *ret = PyObject_CallMethod(in1, meth, "(O)", in2);
-
if (ret == NULL) {
return;
}
Modified: trunk/numpy/core/src/umathmodule.c.src
===================================================================
--- trunk/numpy/core/src/umathmodule.c.src 2008-11-14 16:59:14 UTC (rev 6034)
+++ trunk/numpy/core/src/umathmodule.c.src 2008-11-16 04:01:01 UTC (rev 6035)
@@ -139,6 +139,16 @@
return result;
}
+/*
+ * Define numpy version of PyNumber_Power as binary function.
+ */
+static PyObject *
+npy_PyNumber_Power(PyObject *x, PyObject *y)
+{
+ PyNumber_Power(x, y, Py_None);
+}
+#define PyNumber_Power npy_PyNumber_Power
+
/**begin repeat
* #Kind = Max, Min#
* #OP = >=, <=#
@@ -1520,7 +1530,11 @@
BINARY_LOOP {
PyObject *in1 = *(PyObject **)ip1;
PyObject *in2 = *(PyObject **)ip2;
- *((Bool *)op1) = (Bool) PyObject_RichCompareBool(in1, in2, Py_ at OP@);
+ int ret = PyObject_RichCompareBool(in1, in2, Py_ at OP@);
+ if (ret == -1) {
+ return;
+ }
+ *((Bool *)op1) = (Bool)ret;
}
}
/**end repeat**/
@@ -1531,7 +1545,13 @@
PyObject *zero = PyInt_FromLong(0);
UNARY_LOOP {
PyObject *in1 = *(PyObject **)ip1;
- *((PyObject **)op1) = PyInt_FromLong(PyObject_Compare(in1, zero));
+ PyObject **out = (PyObject **)op1;
+ PyObject *ret = PyInt_FromLong(PyObject_Compare(in1, zero));
+ if (PyErr_Occurred()) {
+ return;
+ }
+ Py_XDECREF(*out);
+ *out = ret;
}
Py_DECREF(zero);
}
More information about the Numpy-svn
mailing list