summaryrefslogtreecommitdiff
path: root/numpy/core/src/arrayobject.c
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2006-06-09 23:52:23 +0000
committerTravis Oliphant <oliphant@enthought.com>2006-06-09 23:52:23 +0000
commit6768d24e4709c080d0ed5c7dca1f36f759fa8ba2 (patch)
treef0e96afbee4045aaa1b416a00225d498ac4e1976 /numpy/core/src/arrayobject.c
parente0bd761dc33d9716be220d6481756aa982599132 (diff)
downloadnumpy-6768d24e4709c080d0ed5c7dca1f36f759fa8ba2.tar.gz
Add RNG interface and clean up old-interfaces to be separate from newer ones.
Diffstat (limited to 'numpy/core/src/arrayobject.c')
-rw-r--r--numpy/core/src/arrayobject.c58
1 files changed, 39 insertions, 19 deletions
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c
index 51f50a08b..ef25af71c 100644
--- a/numpy/core/src/arrayobject.c
+++ b/numpy/core/src/arrayobject.c
@@ -4587,26 +4587,34 @@ PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
if (str == NULL) {
str = PyString_InternFromString("__array_finalize__");
}
- if (strides != NULL) { /* did not allocate own data
- or funny strides */
- /* update flags before calling back into
- Python */
- PyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);
- }
func = PyObject_GetAttr((PyObject *)self, str);
- if (func) {
- args = PyTuple_New(1);
- if (obj == NULL) obj=Py_None;
- Py_INCREF(obj);
- PyTuple_SET_ITEM(args, 0, obj);
- res = PyObject_Call(func, args, NULL);
- Py_DECREF(args);
- Py_DECREF(func);
- if (res == NULL) goto fail;
- else Py_DECREF(res);
- }
- }
-
+ if (func && func != Py_None) {
+ if (strides != NULL) { /* did not allocate own data
+ or funny strides */
+ /* update flags before finalize function */
+ PyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);
+ }
+ if PyCObject_Check(func) {
+ PyArray_FinalizeFunc *cfunc;
+ cfunc = PyCObject_AsVoidPtr(func);
+ Py_DECREF(func);
+ if (cfunc(self, obj) < 0) goto fail;
+ }
+ else {
+ args = PyTuple_New(1);
+ if (obj == NULL) obj=Py_None;
+ Py_INCREF(obj);
+ PyTuple_SET_ITEM(args, 0, obj);
+ res = PyObject_Call(func, args, NULL);
+ Py_DECREF(args);
+ Py_DECREF(func);
+ if (res == NULL) goto fail;
+ else Py_DECREF(res);
+ }
+ }
+ else Py_XDECREF(func);
+ }
+
return (PyObject *)self;
fail:
@@ -5598,6 +5606,14 @@ array_flat_set(PyArrayObject *self, PyObject *val)
return retval;
}
+/* If this is None, no function call is made */
+static PyObject *
+array_finalize_get(PyArrayObject *self)
+{
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
static PyGetSetDef array_getsetlist[] = {
{"ndim",
(getter)array_ndim_get,
@@ -5679,6 +5695,10 @@ static PyGetSetDef array_getsetlist[] = {
(getter)array_priority_get,
NULL,
"Array priority"},
+ {"__array_finalize__",
+ (getter)array_finalize_get,
+ NULL,
+ "None"},
{NULL, NULL, NULL, NULL}, /* Sentinel */
};