diff options
| author | Charles Harris <charlesr.harris@gmail.com> | 2021-12-17 14:20:55 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-17 14:20:55 -0700 |
| commit | 0302205105161c6bbae5d45fe4e7a5a624f0dbf4 (patch) | |
| tree | 6908e6059cc639cca8a9c0f9cc9b00ce103d0db1 | |
| parent | c5ead84c4dd065990ca4e134c04ee2918c3d6bdc (diff) | |
| parent | 8e9c01b6436bacd0aa5dfbf3be423fa7b0ad1d1c (diff) | |
| download | numpy-0302205105161c6bbae5d45fe4e7a5a624f0dbf4.tar.gz | |
Merge pull request #20616 from seberg/hack-for-boost-python
MAINT: Help boost::python libraries at least not crash
| -rw-r--r-- | numpy/core/src/multiarray/multiarraymodule.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c index cf0160a2b..576c39f5d 100644 --- a/numpy/core/src/multiarray/multiarraymodule.c +++ b/numpy/core/src/multiarray/multiarraymodule.c @@ -1478,6 +1478,24 @@ PyArray_EquivTypes(PyArray_Descr *type1, PyArray_Descr *type2) if (type1 == type2) { return 1; } + + if (Py_TYPE(Py_TYPE(type1)) == &PyType_Type) { + /* + * 2021-12-17: This case is nonsense and should be removed eventually! + * + * boost::python has/had a bug effectively using EquivTypes with + * `type(arbitrary_obj)`. That is clearly wrong as that cannot be a + * `PyArray_Descr *`. We assume that `type(type(type(arbitrary_obj))` + * is always in practice `type` (this is the type of the metaclass), + * but for our descriptors, `type(type(descr))` is DTypeMeta. + * + * In that case, we just return False. There is a possibility that + * this actually _worked_ effectively (returning 1 sometimes). + * We ignore that possibility for simplicity; it really is not our bug. + */ + return 0; + } + /* * Do not use PyArray_CanCastTypeTo because it supports legacy flexible * dtypes as input. |
