diff options
author | mattip <matti.picus@gmail.com> | 2018-09-13 21:09:37 +0300 |
---|---|---|
committer | mattip <matti.picus@gmail.com> | 2018-09-13 21:09:37 +0300 |
commit | 2c061739859c84632f31ba08b61f405a05ac07f4 (patch) | |
tree | 3993e1ecfba062b2509b52288a0f4e90628b5c59 /numpy/core | |
parent | 5d8295dd8f36a191f6ecfa63aa0b3debb27a7cc4 (diff) | |
download | numpy-2c061739859c84632f31ba08b61f405a05ac07f4.tar.gz |
MAINT: rework wrapping and sharing common functions
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/setup.py | 4 | ||||
-rw-r--r-- | numpy/core/src/common/wrapper.c (renamed from numpy/core/src/common/convert.c) | 7 | ||||
-rw-r--r-- | numpy/core/src/common/wrapper.h (renamed from numpy/core/src/common/convert.h) | 4 | ||||
-rw-r--r-- | numpy/core/src/multiarray/arraytypes.c.src | 2 | ||||
-rw-r--r-- | numpy/core/src/umath/ufunc_object.c | 46 |
5 files changed, 19 insertions, 44 deletions
diff --git a/numpy/core/setup.py b/numpy/core/setup.py index 4cc9d77e4..986e40007 100644 --- a/numpy/core/setup.py +++ b/numpy/core/setup.py @@ -737,7 +737,7 @@ def configuration(parent_package='',top_path=None): join('src', 'common', 'ucsnarrow.h'), join('src', 'common', 'ufunc_override.h'), join('src', 'common', 'umathmodule.h'), - join('src', 'common', 'convert.h'), + join('src', 'common', 'wrapper.h'), ] common_src = [ @@ -747,7 +747,7 @@ def configuration(parent_package='',top_path=None): join('src', 'common', 'templ_common.h.src'), join('src', 'common', 'ucsnarrow.c'), join('src', 'common', 'ufunc_override.c'), - join('src', 'common', 'convert.c'), + join('src', 'common', 'wrapper.c'), ] blas_info = get_info('blas_opt', 0) diff --git a/numpy/core/src/common/convert.c b/numpy/core/src/common/wrapper.c index aec925ae2..43b7064fc 100644 --- a/numpy/core/src/common/convert.c +++ b/numpy/core/src/common/wrapper.c @@ -1,5 +1,8 @@ -#include <numpy/ndarraytypes.h> -#include "convert.h" +#define NPY_NO_DEPRECATED_API NPY_API_VERSION +#define _MULTIARRAYMODULE +#include <Python.h> +#include <numpy/arrayobject.h> +#include "wrapper.h" NPY_NO_EXPORT npy_longlong npy_strtoll(const char *str, char **endptr, int base) diff --git a/numpy/core/src/common/convert.h b/numpy/core/src/common/wrapper.h index 6106b1d13..3c0686d92 100644 --- a/numpy/core/src/common/convert.h +++ b/numpy/core/src/common/wrapper.h @@ -1,5 +1,5 @@ -#ifndef _COMMON_CONVERT_H -#define _COMMON_CONVERT_H +#ifndef _COMMON_WRAPPER_H +#define _COMMON_WRAPPER_H /* Convert a string to an int in an arbitrary base */ diff --git a/numpy/core/src/multiarray/arraytypes.c.src b/numpy/core/src/multiarray/arraytypes.c.src index e5ee7c1e9..31d69b5f5 100644 --- a/numpy/core/src/multiarray/arraytypes.c.src +++ b/numpy/core/src/multiarray/arraytypes.c.src @@ -34,9 +34,9 @@ #include "cblasfuncs.h" #include "npy_cblas.h" +#include "wrapper.h" #include <limits.h> #include <assert.h> -#include <convert.h> /* check for sequences, but ignore the types numpy considers scalars */ static NPY_INLINE npy_bool diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c index 1485b4274..8f792ef31 100644 --- a/numpy/core/src/umath/ufunc_object.c +++ b/numpy/core/src/umath/ufunc_object.c @@ -46,7 +46,7 @@ #include "npy_import.h" #include "extobj.h" #include "common.h" -#include <convert.h> +#include "wrapper.h" /********** PRINTF DEBUG TRACING **************/ #define NPY_UF_DBG_TRACING 0 @@ -480,12 +480,10 @@ _is_alnum_underscore(char ch) return _is_alpha_underscore(ch) || (ch >= '0' && ch <= '9'); } -NPY_NO_EXPORT npy_longlong -npy_strtoll(const char *str, char **endptr, int base); /* * Convert a string into a number */ -static npy_longlong +static npy_int _get_size(const char* str) { char *stop; @@ -495,6 +493,10 @@ _get_size(const char* str) /* not a well formed number */ return -1; } + if (size >= NPY_MAX_INTP || size <= NPY_MIN_INTP) { + /* len(str) too long */ + return -1; + } return size; } @@ -4851,39 +4853,8 @@ PyUFunc_FromFuncAndDataAndSignature(PyUFuncGenericFunction *func, void **data, { PyUFuncObject *ufunc; /* - * Use memcpy and an initialzed instance to set the newly allocated PyUFuncObject. - The version field is a constant and cannot be initialzed in C directly + * The version field is a constant and cannot be initialzed in C directly */ - PyUFuncObject PyUFuncObject_init = { - PyObject_HEAD_INIT(0) - 0, 0, 0, /* nin, nout, nargs */ - 0, /* identity */ - NULL, /* functions */ - NULL, /* data */ - 0, /* ntypes */ - UFUNC_VERSION, /* version */ - NULL, /* name */ - NULL, /* types */ - NULL, /* doc */ - NULL, /* ptr */ - NULL, /* obj */ - NULL, /* userloops */ - 0, /* core_enabled */ - 0, /* core_num_dim_ix */ - NULL, /* core_num_dims */ - NULL, /* core_dim_ixs */ - NULL, /* core_offsets */ - NULL, /* core_signature */ - NULL, /* type_resolver */ - NULL, /* legacy_inner_loop_selector */ - NULL, /* reserved2 */ - NULL, /* masked_inner_loop_selector */ - NULL, /* op_flags */ - 0, /* iter_flags */ - NULL, /* core_dim_sizes */ - NULL, /* core_dim_flags */ - }; - if (nin + nout > NPY_MAXARGS) { PyErr_Format(PyExc_ValueError, "Cannot construct a ufunc with more than %d operands " @@ -4896,7 +4867,8 @@ PyUFunc_FromFuncAndDataAndSignature(PyUFuncGenericFunction *func, void **data, if (ufunc == NULL) { return NULL; } - memcpy(ufunc, &PyUFuncObject_init, sizeof(PyUFuncObject)); + memset(ufunc, 0, sizeof(PyUFuncObject)); + *((int*)&ufunc->version) = UFUNC_VERSION; PyObject_Init((PyObject *)ufunc, &PyUFunc_Type); ufunc->nin = nin; |