summaryrefslogtreecommitdiff
path: root/numpy/core
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2006-01-19 05:03:46 +0000
committerTravis Oliphant <oliphant@enthought.com>2006-01-19 05:03:46 +0000
commitee811d8a07cdc121de6ff96d4ffa6482fc8ce410 (patch)
treed150605f97670716dbd3a19137802aa2905148e5 /numpy/core
parent6a30aaf84be313b29a4072ec3357ff5e4a6b2d74 (diff)
downloadnumpy-ee811d8a07cdc121de6ff96d4ffa6482fc8ce410.tar.gz
Added NDARRAY_VERSION check on import_array
Diffstat (limited to 'numpy/core')
-rw-r--r--numpy/core/code_generators/generate_array_api.py7
-rw-r--r--numpy/core/code_generators/multiarray_api_order.txt2
-rw-r--r--numpy/core/include/numpy/arrayobject.h2
-rw-r--r--numpy/core/src/multiarraymodule.c22
-rw-r--r--numpy/core/src/scalartypes.inc.src1
5 files changed, 32 insertions, 2 deletions
diff --git a/numpy/core/code_generators/generate_array_api.py b/numpy/core/code_generators/generate_array_api.py
index db8086903..e60920eb1 100644
--- a/numpy/core/code_generators/generate_array_api.py
+++ b/numpy/core/code_generators/generate_array_api.py
@@ -62,6 +62,13 @@ import_array(void)
Py_DECREF(c_api);
Py_DECREF(numpy);
if (PyArray_API == NULL) return -1;
+ /* Perform runtime check of C API version */
+ if (NDARRAY_VERSION != PyArray_GetNDArrayCVersion()) {
+ PyErr_Format(PyExc_RuntimeError, "numpy C-API mismatch: module "\
+ "compiled against version %%X but this version of numpy is %%X", \
+ (uint) PyArray_GetNDArrayCVersion(), (uint) NDARRAY_VERSION);
+ return -1;
+ }
return 0;
}
#endif
diff --git a/numpy/core/code_generators/multiarray_api_order.txt b/numpy/core/code_generators/multiarray_api_order.txt
index 8dbb86882..d328ad7fc 100644
--- a/numpy/core/code_generators/multiarray_api_order.txt
+++ b/numpy/core/code_generators/multiarray_api_order.txt
@@ -64,3 +64,5 @@ PyArray_Arange
PyArray_ArangeObj
PyArray_SortkindConverter
PyArray_LexSort
+PyArray_GetNDArrayCVersion
+
diff --git a/numpy/core/include/numpy/arrayobject.h b/numpy/core/include/numpy/arrayobject.h
index 2c6a6e99c..af94b03c6 100644
--- a/numpy/core/include/numpy/arrayobject.h
+++ b/numpy/core/include/numpy/arrayobject.h
@@ -74,7 +74,7 @@ extern "C" {
#define PY_SUCCEED 1
/* Helpful to distinguish what is installed */
-#define NDARRAY_VERSION 0x0802
+#define NDARRAY_VERSION 0x000904
/* Some platforms don't define bool, long long, or long double.
Handle that here.
diff --git a/numpy/core/src/multiarraymodule.c b/numpy/core/src/multiarraymodule.c
index c9cfa975f..b402ec831 100644
--- a/numpy/core/src/multiarraymodule.c
+++ b/numpy/core/src/multiarraymodule.c
@@ -4998,6 +4998,26 @@ array_arange(PyObject *ignored, PyObject *args, PyObject *kws) {
return PyArray_ArangeObj(o_start, o_stop, o_step, typecode);
}
+/*MULTIARRAY_API
+ GetNDArrayCVersion
+*/
+static uint
+PyArray_GetNDArrayCVersion(void)
+{
+ return (uint)NDARRAY_VERSION;
+}
+
+static char
+doc__get_ndarray_c_version[] = "_get_ndarray_c_version() gets the compile time NDARRAY_VERSION number";
+
+static PyObject *
+array__get_ndarray_c_version(PyObject *dummy, PyObject *args, PyObject *kwds)
+{
+ static char *kwlist[] = {NULL};
+ if(!PyArg_ParseTupleAndKeywords(args, kwds, "", kwlist )) return NULL;
+
+ return PyInt_FromLong( (long) PyArray_GetNDArrayCVersion() );
+}
static char
doc_set_string_function[] = "set_string_function(f, repr=1) sets the python function f to be the function used to obtain a pretty printable string version of a array whenever a array is printed. f(M) should expect a array argument M, and should return a string consisting of the desired representation of M for printing.";
@@ -5223,6 +5243,8 @@ buffer_buffer(PyObject *dummy, PyObject *args, PyObject *kwds)
static struct PyMethodDef array_module_methods[] = {
+ {"_get_ndarray_c_version", (PyCFunction)array__get_ndarray_c_version,
+ METH_VARARGS|METH_KEYWORDS, doc__get_ndarray_c_version},
{"set_string_function", (PyCFunction)array_set_string_function,
METH_VARARGS|METH_KEYWORDS, doc_set_string_function},
{"set_numeric_ops", (PyCFunction)array_set_ops_function,
diff --git a/numpy/core/src/scalartypes.inc.src b/numpy/core/src/scalartypes.inc.src
index 3503c959c..2d619bd38 100644
--- a/numpy/core/src/scalartypes.inc.src
+++ b/numpy/core/src/scalartypes.inc.src
@@ -32,7 +32,6 @@ static PyBoolScalarObject _PyArrayScalar_BoolValues[] = {
{PyObject_HEAD_INIT(&PyBoolArrType_Type) 1},
};
-
/* Inheritance established later when tp_bases is set (or tp_base for
single inheritance) */