diff options
author | Julian Taylor <jtaylor.debian@googlemail.com> | 2014-04-24 21:24:18 +0200 |
---|---|---|
committer | Julian Taylor <jtaylor.debian@googlemail.com> | 2014-04-24 21:24:18 +0200 |
commit | cb045e9330b81c3b002339cac8213f568f7650f7 (patch) | |
tree | 697143fbd8c3ae5b042f4bc6230ec792a5a2385e | |
parent | 999753f85153ae68536aebe9f51ee3ff02b950bc (diff) | |
download | numpy-cb045e9330b81c3b002339cac8213f568f7650f7.tar.gz |
MAINT: add a few nonnull attributes to array creation functions
also fix wrong capi documentation of PyArray_NewFromDescr stating it
accepts NULL dtype while it does not.
-rw-r--r-- | doc/source/reference/c-api.array.rst | 2 | ||||
-rw-r--r-- | numpy/core/code_generators/numpy_api.py | 8 | ||||
-rw-r--r-- | numpy/core/src/multiarray/ctors.c | 6 |
3 files changed, 10 insertions, 6 deletions
diff --git a/doc/source/reference/c-api.array.rst b/doc/source/reference/c-api.array.rst index 2ce43b2be..23355bc91 100644 --- a/doc/source/reference/c-api.array.rst +++ b/doc/source/reference/c-api.array.rst @@ -190,7 +190,7 @@ From scratch .. cfunction:: PyObject* PyArray_NewFromDescr(PyTypeObject* subtype, PyArray_Descr* descr, int nd, npy_intp* dims, npy_intp* strides, void* data, int flags, PyObject* obj) - This function steals a reference to *descr* if it is not NULL. + This function steals a reference to *descr*. This is the main array creation function. Most new arrays are created with this flexible function. diff --git a/numpy/core/code_generators/numpy_api.py b/numpy/core/code_generators/numpy_api.py index 2a0da9c6e..83bfe02e4 100644 --- a/numpy/core/code_generators/numpy_api.py +++ b/numpy/core/code_generators/numpy_api.py @@ -128,7 +128,7 @@ multiarray_funcs_api = { 'PyArray_CopyInto': 82, 'PyArray_CopyAnyInto': 83, 'PyArray_CopyObject': 84, - 'PyArray_NewCopy': 85, + 'PyArray_NewCopy': (85, NonNull(1)), 'PyArray_ToList': 86, 'PyArray_ToString': 87, 'PyArray_ToFile': 88, @@ -136,8 +136,8 @@ multiarray_funcs_api = { 'PyArray_Dumps': 90, 'PyArray_ValidType': 91, 'PyArray_UpdateFlags': 92, - 'PyArray_New': 93, - 'PyArray_NewFromDescr': (94, StealRef(2)), + 'PyArray_New': (93, NonNull(1)), + 'PyArray_NewFromDescr': (94, StealRef(2), NonNull([1, 2])), 'PyArray_DescrNew': 95, 'PyArray_DescrNewFromType': 96, 'PyArray_GetPriority': 97, @@ -318,7 +318,7 @@ multiarray_funcs_api = { 'PyArray_CanCastArrayTo': 274, 'PyArray_CanCastTypeTo': 275, 'PyArray_EinsteinSum': 276, - 'PyArray_NewLikeArray': (277, StealRef(3)), + 'PyArray_NewLikeArray': (277, StealRef(3), NonNull(1)), 'PyArray_GetArrayParamsFromObject': 278, 'PyArray_ConvertClipmodeSequence': 279, 'PyArray_MatrixProduct2': 280, diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c index a45a470bf..5f8fbc4dc 100644 --- a/numpy/core/src/multiarray/ctors.c +++ b/numpy/core/src/multiarray/ctors.c @@ -26,6 +26,7 @@ #include "array_assign.h" #include "mapping.h" /* for array_item_asarray */ #include "scalarmathmodule.h" /* for npy_mul_with_overflow_intp */ +#include <assert.h> /* * Reading from a file or a string. @@ -885,12 +886,15 @@ PyArray_NewFromDescr_int(PyTypeObject *subtype, PyArray_Descr *descr, int nd, int i; size_t sd; npy_intp size; + assert(dims != NULL || (nd == 0)); if (descr->subarray) { PyObject *ret; npy_intp newdims[2*NPY_MAXDIMS]; npy_intp *newstrides = NULL; - memcpy(newdims, dims, nd*sizeof(npy_intp)); + if (nd > 0) { + memcpy(newdims, dims, nd * sizeof(npy_intp)); + } if (strides) { newstrides = newdims + NPY_MAXDIMS; memcpy(newstrides, strides, nd*sizeof(npy_intp)); |