Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAINT: Help boost::python libraries at least not crash #20618

Merged
merged 1 commit into from Dec 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions numpy/core/src/multiarray/multiarraymodule.c
Expand Up @@ -1473,6 +1473,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.
Expand Down