diff options
author | Julian Taylor <jtaylor.debian@googlemail.com> | 2013-08-08 19:04:40 +0200 |
---|---|---|
committer | Julian Taylor <jtaylor.debian@googlemail.com> | 2013-08-16 10:11:26 +0200 |
commit | afceb18ded0a263196919106ad6e0dba252b204f (patch) | |
tree | 00bf41a3dd6bff14eb75d48fcc40d5ede37d4dbd /numpy | |
parent | 9b10a5f7a0f260981ad69cec147807080a456d0a (diff) | |
download | numpy-afceb18ded0a263196919106ad6e0dba252b204f.tar.gz |
ENH: add PyDataMem_NEW_ZEROED which allocates memory with calloc
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/code_generators/cversions.txt | 4 | ||||
-rw-r--r-- | numpy/core/code_generators/numpy_api.py | 1 | ||||
-rw-r--r-- | numpy/core/src/multiarray/multiarraymodule.c | 20 |
3 files changed, 23 insertions, 2 deletions
diff --git a/numpy/core/code_generators/cversions.txt b/numpy/core/code_generators/cversions.txt index 24d376ac6..6ab422055 100644 --- a/numpy/core/code_generators/cversions.txt +++ b/numpy/core/code_generators/cversions.txt @@ -15,5 +15,5 @@ 0x00000007 = e396ba3912dcf052eaee1b0b203a7724 # Version 8 Added interface to MapIterObject 0x00000008 = 17321775fc884de0b1eda478cd61c74b -# Version 9 Added interface for partition functions. -0x00000009 = f99a02b75bd60205d1afe1eed080fd53 +# Version 9 Added interface for partition functions, PyArray_NEW_ZEROED +0x00000009 = 327bd114df09c2eb7a0bcc6901e2a3ed diff --git a/numpy/core/code_generators/numpy_api.py b/numpy/core/code_generators/numpy_api.py index ad9ee3eec..791bc6ffc 100644 --- a/numpy/core/code_generators/numpy_api.py +++ b/numpy/core/code_generators/numpy_api.py @@ -339,6 +339,7 @@ multiarray_funcs_api = { 'PyArray_Partition': 296, 'PyArray_ArgPartition': 297, 'PyArray_SelectkindConverter': 298, + 'PyDataMem_NEW_ZEROED': 299, # End 1.8 API } diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c index f8e434e67..dd1f3c7d7 100644 --- a/numpy/core/src/multiarray/multiarraymodule.c +++ b/numpy/core/src/multiarray/multiarraymodule.c @@ -3500,6 +3500,26 @@ PyDataMem_NEW(size_t size) } /*NUMPY_API + * Allocates zeroed memory for array data. + */ +NPY_NO_EXPORT void * +PyDataMem_NEW_ZEROED(size_t size, size_t elsize) +{ + void *result; + + result = calloc(size, elsize); + if (_PyDataMem_eventhook != NULL) { + PyGILState_STATE gilstate = PyGILState_Ensure(); + if (_PyDataMem_eventhook != NULL) { + (*_PyDataMem_eventhook)(NULL, result, size * elsize, + _PyDataMem_eventhook_user_data); + } + PyGILState_Release(gilstate); + } + return (char *)result; +} + +/*NUMPY_API * Free memory for array data. */ NPY_NO_EXPORT void |