summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authormattip <matti.picus@gmail.com>2018-09-13 18:09:03 +0300
committermattip <matti.picus@gmail.com>2018-09-13 18:09:03 +0300
commitea4c8a1ca7bc69873d20340073fb54fb2f2eca2a (patch)
tree74b3f4315717d629ef498ef18a50b4ce1a588810 /numpy
parent31a0d21d7ada4bbaebe02a54a6c4062662e4e2d0 (diff)
downloadnumpy-ea4c8a1ca7bc69873d20340073fb54fb2f2eca2a.tar.gz
MAINT: refactor to share npy_strto{u}ll
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/setup.py2
-rw-r--r--numpy/core/src/common/convert.c30
-rw-r--r--numpy/core/src/common/convert.h13
-rw-r--r--numpy/core/src/multiarray/arraytypes.c.src27
-rw-r--r--numpy/core/src/umath/ufunc_object.c17
5 files changed, 54 insertions, 35 deletions
diff --git a/numpy/core/setup.py b/numpy/core/setup.py
index 1588a2634..4cc9d77e4 100644
--- a/numpy/core/setup.py
+++ b/numpy/core/setup.py
@@ -737,6 +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'),
]
common_src = [
@@ -746,6 +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'),
]
blas_info = get_info('blas_opt', 0)
diff --git a/numpy/core/src/common/convert.c b/numpy/core/src/common/convert.c
new file mode 100644
index 000000000..aec925ae2
--- /dev/null
+++ b/numpy/core/src/common/convert.c
@@ -0,0 +1,30 @@
+#include <numpy/ndarraytypes.h>
+#include "convert.h"
+
+NPY_NO_EXPORT npy_longlong
+npy_strtoll(const char *str, char **endptr, int base)
+{
+#if defined HAVE_STRTOLL
+ return strtoll(str, endptr, base);
+#elif defined _MSC_VER
+ return _strtoi64(str, endptr, base);
+#else
+ /* ok on 64 bit posix */
+ return PyOS_strtol(str, endptr, base);
+#endif
+}
+
+NPY_NO_EXPORT npy_ulonglong
+npy_strtoull(const char *str, char **endptr, int base)
+{
+#if defined HAVE_STRTOULL
+ return strtoull(str, endptr, base);
+#elif defined _MSC_VER
+ return _strtoui64(str, endptr, base);
+#else
+ /* ok on 64 bit posix */
+ return PyOS_strtoul(str, endptr, base);
+#endif
+}
+
+
diff --git a/numpy/core/src/common/convert.h b/numpy/core/src/common/convert.h
new file mode 100644
index 000000000..6106b1d13
--- /dev/null
+++ b/numpy/core/src/common/convert.h
@@ -0,0 +1,13 @@
+#ifndef _COMMON_CONVERT_H
+#define _COMMON_CONVERT_H
+
+
+/* Convert a string to an int in an arbitrary base */
+NPY_NO_EXPORT npy_longlong
+npy_strtoll(const char *str, char **endptr, int base);
+
+/* Convert a string to an int in an arbitrary base */
+NPY_NO_EXPORT npy_ulonglong
+npy_strtoull(const char *str, char **endptr, int base);
+
+#endif
diff --git a/numpy/core/src/multiarray/arraytypes.c.src b/numpy/core/src/multiarray/arraytypes.c.src
index d622effe6..e5ee7c1e9 100644
--- a/numpy/core/src/multiarray/arraytypes.c.src
+++ b/numpy/core/src/multiarray/arraytypes.c.src
@@ -36,6 +36,7 @@
#include "npy_cblas.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
@@ -150,32 +151,6 @@ MyPyLong_AsUnsigned@Type@ (PyObject *obj)
/**end repeat**/
-static npy_longlong
-npy_strtoll(const char *str, char **endptr, int base)
-{
-#if defined HAVE_STRTOLL
- return strtoll(str, endptr, base);
-#elif defined _MSC_VER
- return _strtoi64(str, endptr, base);
-#else
- /* ok on 64 bit posix */
- return PyOS_strtol(str, endptr, base);
-#endif
-}
-
-static npy_ulonglong
-npy_strtoull(const char *str, char **endptr, int base)
-{
-#if defined HAVE_STRTOULL
- return strtoull(str, endptr, base);
-#elif defined _MSC_VER
- return _strtoui64(str, endptr, base);
-#else
- /* ok on 64 bit posix */
- return PyOS_strtoul(str, endptr, base);
-#endif
-}
-
/*
*****************************************************************************
** GETITEM AND SETITEM **
diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c
index 584d3605b..cd9479b28 100644
--- a/numpy/core/src/umath/ufunc_object.c
+++ b/numpy/core/src/umath/ufunc_object.c
@@ -46,6 +46,7 @@
#include "npy_import.h"
#include "extobj.h"
#include "common.h"
+#include <convert.h>
/********** PRINTF DEBUG TRACING **************/
#define NPY_UF_DBG_TRACING 0
@@ -479,18 +480,16 @@ _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_intp
- _get_size(const char* str)
- {
+static npy_longlong
+_get_size(const char* str)
+{
char *stop;
-#if defined(_MSC_VER)
- npy_intp size = (npy_intp)_strtoi64(str, &stop, 10);
-#else
- npy_intp size = (npy_intp)strtoll(str, &stop, 10);
-#endif
+ npy_longlong size = npy_strtoll(str, &stop, 10);
if (stop == str || _is_alpha_underscore(*stop)) {
/* not a well formed number */
@@ -622,7 +621,7 @@ _parse_signature(PyUFuncObject *ufunc, const char *signature)
frozen_size = -1;
}
else {
- frozen_size = _get_size(signature + i);
+ frozen_size = (npy_intp)_get_size(signature + i);
if (frozen_size <= 0) {
parse_error = "expect dimension name or non-zero frozen size";
goto fail;