diff options
| author | Charles Harris <charlesr.harris@gmail.com> | 2015-08-10 16:54:21 -0600 |
|---|---|---|
| committer | Charles Harris <charlesr.harris@gmail.com> | 2015-08-10 18:53:31 -0600 |
| commit | e422a097ed6ca28e9bf7deeb4024aee81d63a264 (patch) | |
| tree | 0ea7e186e8d0a5af48e2b7374f21c391967b4ea5 /numpy/core | |
| parent | 33d271bec13aba0ba430fc6e3c72e5026b28c665 (diff) | |
| download | numpy-e422a097ed6ca28e9bf7deeb4024aee81d63a264.tar.gz | |
BUG: Fix a non-constant expression used as structure initializer.
PyObject_HashNotImplemented was being used to initialize the tp_hash
slot in the PyArray_Type structure. In mingw32 (gcc version 3.4) that
results in a compile error. Fix by initializing to zero, then
setting to PyObject_HashNotImplemented when the module is loaded.
The function initialization seems to work with more recent compilers, as
the determination of what is considered 'non-constant' is left to the
vendor and has changed.
Diffstat (limited to 'numpy/core')
| -rw-r--r-- | numpy/core/src/multiarray/arrayobject.c | 8 | ||||
| -rw-r--r-- | numpy/core/src/multiarray/multiarraymodule.c | 7 |
2 files changed, 13 insertions, 2 deletions
diff --git a/numpy/core/src/multiarray/arrayobject.c b/numpy/core/src/multiarray/arrayobject.c index 42c83b625..8d9187a57 100644 --- a/numpy/core/src/multiarray/arrayobject.c +++ b/numpy/core/src/multiarray/arrayobject.c @@ -1809,7 +1809,11 @@ NPY_NO_EXPORT PyTypeObject PyArray_Type = { &array_as_number, /* tp_as_number */ &array_as_sequence, /* tp_as_sequence */ &array_as_mapping, /* tp_as_mapping */ - PyObject_HashNotImplemented, /* tp_hash */ + /* + * The tp_hash slot will be set PyObject_HashNotImplemented when the + * module is loaded. + */ + (hashfunc)0, /* tp_hash */ (ternaryfunc)0, /* tp_call */ (reprfunc)array_str, /* tp_str */ (getattrofunc)0, /* tp_getattro */ @@ -1820,7 +1824,7 @@ NPY_NO_EXPORT PyTypeObject PyArray_Type = { | Py_TPFLAGS_CHECKTYPES | Py_TPFLAGS_HAVE_NEWBUFFER #endif - | Py_TPFLAGS_BASETYPE), /* tp_flags */ + | Py_TPFLAGS_BASETYPE), /* tp_flags */ 0, /* tp_doc */ (traverseproc)0, /* tp_traverse */ diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c index 6155551d6..04513c56c 100644 --- a/numpy/core/src/multiarray/multiarraymodule.c +++ b/numpy/core/src/multiarray/multiarraymodule.c @@ -4480,6 +4480,13 @@ PyMODINIT_FUNC initmultiarray(void) { if (!d) { goto err; } + + /* + * Before calling PyType_Ready, initialize the tp_hash slot in + * PyArray_Type to work around mingw32 not being able initialize + * static structure slots with functions from the Python C_API. + */ + PyArray_Type.tp_hash = PyObject_HashNotImplemented; if (PyType_Ready(&PyArray_Type) < 0) { return RETVAL; } |
