[Numpy-svn] r5052 - trunk/numpy/core/src
numpy-svn at scipy.org
numpy-svn at scipy.org
Sat Apr 19 22:42:56 EDT 2008
Author: charris
Date: 2008-04-19 21:42:23 -0500 (Sat, 19 Apr 2008)
New Revision: 5052
Modified:
trunk/numpy/core/src/ufuncobject.c
Log:
More clean up the generic object loops.
There is a reference counting error in the code that calls these loops.
Modified: trunk/numpy/core/src/ufuncobject.c
===================================================================
--- trunk/numpy/core/src/ufuncobject.c 2008-04-20 00:45:27 UTC (rev 5051)
+++ trunk/numpy/core/src/ufuncobject.c 2008-04-20 02:42:23 UTC (rev 5052)
@@ -234,7 +234,7 @@
x1 = *((PyObject **)ip1);
x2 = *((PyObject **)ip2);
if ((x1 == NULL) || (x2 == NULL)) {
- goto done;
+ return;
}
if ( (void *) func == (void *) PyNumber_Power) {
tmp = ((ternaryfunc)func)(x1, x2, Py_None);
@@ -243,13 +243,11 @@
tmp = ((binaryfunc)func)(x1, x2);
}
if (PyErr_Occurred()) {
- goto done;
+ return;
}
Py_XDECREF(*((PyObject **)op));
*((PyObject **)op) = tmp;
}
-done:
- return;
}
/*UFUNC_API*/
@@ -263,33 +261,20 @@
char *ip1 = args[0];
char *ip2 = args[1];
char *op = args[2];
+ char *meth = (char *)func;
intp i;
- PyObject *tmp, *meth, *arglist, *x1, *x2;
for(i = 0; i < n; i++, ip1 += is1, ip2 += is2, op += os) {
- x1 = *(PyObject **)ip1;
- x2 = *(PyObject **)ip2;
- if ((x1 == NULL) || (x2 == NULL)) {
+ PyObject *in1 = *(PyObject **)ip1;
+ PyObject *in2 = *(PyObject **)ip2;
+ PyObject **out = (PyObject **)op;
+ PyObject *ret = PyObject_CallMethod(in1, meth, "(O)", in2);
+
+ if (ret == NULL) {
return;
}
- meth = PyObject_GetAttrString(x1, (char *)func);
- if (meth != NULL) {
- arglist = PyTuple_New(1);
- if (arglist == NULL) {
- Py_DECREF(meth);
- return;
- }
- Py_INCREF(x2);
- PyTuple_SET_ITEM(arglist, 0, x2);
- tmp = PyEval_CallObject(meth, arglist);
- Py_DECREF(arglist);
- Py_DECREF(meth);
- if ((tmp==NULL) || PyErr_Occurred()) {
- return;
- }
- Py_XDECREF(*((PyObject **)op));
- *((PyObject **)op) = tmp;
- }
+ Py_XDECREF(*out);
+ *out = ret;
}
}
@@ -487,30 +472,19 @@
intp is2 = steps[1];
char *ip1 = args[0];
char *op = args[1];
+ char *meth = (char *)func;
intp i;
- PyObject *tmp, *meth, *arglist, *x1;
for(i = 0; i < n; i++, ip1 += is1, op += is2) {
- x1 = *(PyObject **)ip1;
- if (x1 == NULL) {
+ PyObject *in1 = *(PyObject **)ip1;
+ PyObject **out = (PyObject **)op;
+ PyObject *ret = PyObject_CallMethod(in1, meth, NULL);
+
+ if (ret == NULL) {
return;
}
- meth = PyObject_GetAttrString(x1, (char *)func);
- if (meth != NULL) {
- arglist = PyTuple_New(0);
- if (arglist == NULL) {
- Py_DECREF(meth);
- return;
- }
- tmp = PyEval_CallObject(meth, arglist);
- Py_DECREF(arglist);
- Py_DECREF(meth);
- if ((tmp==NULL) || PyErr_Occurred()) {
- return;
- }
- Py_XDECREF(*((PyObject **)op));
- *((PyObject **)op) = tmp;
- }
+ Py_XDECREF(*out);
+ *out = ret;
}
}
More information about the Numpy-svn
mailing list