numpy/numpy — pull request #309 by thouis (2012-06-15 12:06:30+00:00)
Title: ENH: expose PyDataMem_NEW/FREE/RENEW as numpy API functions with an event hook.

This is the simplest intersection of two previous pull requests:
https://github.com/numpy/numpy/pull/301
https://github.com/numpy/numpy/pull/284

Changes:
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.