From be294ab42bc51c7588e9ed50982046c03f00f618 Mon Sep 17 00:00:00 2001 From: "Thouis (Ray) Jones" Date: Fri, 25 May 2012 09:59:43 +0200 Subject: ENH: expose PyDataMem_NEW/FREE/RENEW as numpy API functions with an event hook. Moves PyDataMem_NEW/FREE/RENEW to the external API. Fixes PyDataMem_NEW/RENEW to return void* instead of char*. Replaces PyDataMem_NEW/FREE with NpySortArray_malloc/free in sort.c.src (should be reverted if npysort is moved to be part of multiarraymodule). Adds PyDataMem_SetEventHook which takes a (PyDataMem_EventHookFunc *) as an argument, with signature: void hook(void *old, void *new, size_t size). When not NULL, hook will be called at the end of each PyDataMem_NEW/FREE/RENEW: result = PyDataMem_NEW(size) -> (*hook(NULL, result, size) PyDataMem_FREE(ptr) -> (*hook(ptr, NULL, 0) result = PyDataMem_RENEW(ptr, size) -> (*hook)(ptr, result, size) Adds tests in multiarray_tests.c.src, driven by tests/test_multiarray.py. --- numpy/lib/src/_compiled_base.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'numpy/lib/src') diff --git a/numpy/lib/src/_compiled_base.c b/numpy/lib/src/_compiled_base.c index c31ee5cd8..9bb8a613d 100644 --- a/numpy/lib/src/_compiled_base.c +++ b/numpy/lib/src/_compiled_base.c @@ -670,7 +670,10 @@ arr_interp(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwdict) /* only pre-calculate slopes if there are relatively few of them. */ if (lenxp <= lenx) { - slopes = (double *) PyDataMem_NEW((lenxp - 1)*sizeof(double)); + slopes = (double *) PyArray_malloc((lenxp - 1)*sizeof(double)); + if (! slopes) { + goto fail; + } NPY_BEGIN_ALLOW_THREADS; for (i = 0; i < lenxp - 1; i++) { slopes[i] = (dy[i + 1] - dy[i])/(dx[i + 1] - dx[i]); @@ -692,7 +695,7 @@ arr_interp(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwdict) } } NPY_END_ALLOW_THREADS; - PyDataMem_FREE(slopes); + PyArray_free(slopes); } else { NPY_BEGIN_ALLOW_THREADS; -- cgit v1.2.1 From 423ddfb0484eecdf825209337b20ec929f038b6f Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Mon, 11 Jun 2012 22:21:30 +0200 Subject: STY: core: move non-Py3 specific stuff out from npy_3kcompat.h to private npy_pycompat.h npy_3kcompat.h is semi-private, so this can be done. --- numpy/lib/src/_compiled_base.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'numpy/lib/src') diff --git a/numpy/lib/src/_compiled_base.c b/numpy/lib/src/_compiled_base.c index 9bb8a613d..d389b7f8e 100644 --- a/numpy/lib/src/_compiled_base.c +++ b/numpy/lib/src/_compiled_base.c @@ -7,6 +7,10 @@ #include "numpy/ufuncobject.h" #include "string.h" +#if (PY_VERSION_HEX < 0x02060000) +#define Py_TYPE(o) (((PyObject*)(o))->ob_type) +#endif + static npy_intp incr_slot_(double x, double *bins, npy_intp lbins) { -- cgit v1.2.1