diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-06-09 23:52:23 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-06-09 23:52:23 +0000 |
commit | 6768d24e4709c080d0ed5c7dca1f36f759fa8ba2 (patch) | |
tree | f0e96afbee4045aaa1b416a00225d498ac4e1976 /numpy/core/src | |
parent | e0bd761dc33d9716be220d6481756aa982599132 (diff) | |
download | numpy-6768d24e4709c080d0ed5c7dca1f36f759fa8ba2.tar.gz |
Add RNG interface and clean up old-interfaces to be separate from newer ones.
Diffstat (limited to 'numpy/core/src')
-rw-r--r-- | numpy/core/src/arraymethods.c | 11 | ||||
-rw-r--r-- | numpy/core/src/arrayobject.c | 58 |
2 files changed, 39 insertions, 30 deletions
diff --git a/numpy/core/src/arraymethods.c b/numpy/core/src/arraymethods.c index c83aea36e..79235e58c 100644 --- a/numpy/core/src/arraymethods.c +++ b/numpy/core/src/arraymethods.c @@ -548,14 +548,6 @@ array_wraparray(PyArrayObject *self, PyObject *args) return ret; } -/* NO-OP --- just so all subclasses will have one by default. */ -static PyObject * -array_finalize(PyArrayObject *self, PyObject *args) -{ - Py_INCREF(Py_None); - return Py_None; -} - static char doc_array_getarray[] = "m.__array__(|dtype) just returns either a new reference to self if dtype is not given or a new array of provided data type if dtype is different from the current dtype of the array."; @@ -1620,9 +1612,6 @@ static PyMethodDef array_methods[] = { /* for subtypes */ {"__array__", (PyCFunction)array_getarray, 1, doc_array_getarray}, {"__array_wrap__", (PyCFunction)array_wraparray, 1, doc_wraparray}, - /* default version so it is found... -- only used for subclasses */ - {"__array_finalize__", (PyCFunction)array_finalize, 1, NULL}, - /* for the copy module */ {"__copy__", (PyCFunction)array_copy, 1, doc_copy}, 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 */ }; |