From 5190f6bd67f23671e309cf2b492aa47d69c7c42e Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Thu, 15 Oct 2009 16:34:13 +0200 Subject: [PATCH] new ndarray.base setter/getter functions by Neal Becker --- Cython/Includes/numpy.pxd | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Cython/Includes/numpy.pxd b/Cython/Includes/numpy.pxd index fa5eb951..35fba02b 100644 --- a/Cython/Includes/numpy.pxd +++ b/Cython/Includes/numpy.pxd @@ -17,7 +17,7 @@ DEF _buffer_format_string_len = 255 cimport python_buffer as pybuf -from python_ref cimport PyObject +from python_ref cimport PyObject, Py_XINCREF, Py_XDECREF cimport stdlib cimport stdio @@ -904,5 +904,22 @@ cdef extern from "numpy/ufuncobject.h": int, char *, char *, int, char *) - void import_ufunc() + +cdef inline void set_array_base(ndarray arr, object base): + cdef PyObject* baseptr + cdef ndarray raw = arr + if base is None: + baseptr = NULL + else: + baseptr = base + Py_XINCREF(baseptr) # important to do this before decref below! + Py_XDECREF(raw.base) + raw.base = baseptr + +cdef inline object get_array_base(ndarray arr): + cdef ndarray raw = arr + if raw.base == NULL: + return None + else: + return raw.base -- 2.26.2