-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fixing SystemError when nb_bool/nb_nonzero sets a Python exception in type_caster<bool>::load #1976
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
Fixing SystemError when nb_bool/nb_nonzero sets a Python exception in type_caster<bool>::load #1976
Conversation
… type_caster<bool>::load
(Thanks to @tdegeus for reporting on Gitter and sticking along while debugging, btw!) |
OK, this is because Ready to merge, as far as I'm concerned, then! |
Thanks @YannickJadoul ! |
What strikes me as odd about this PR is why this is something specific to the |
@wjakob The main problem is calling into the C API without checking the result (i.e., if it's When other casters call into the C API, they do check the result for errors and clear if necessary. For example: integer-types caster, pybind11/include/pybind11/cast.h Line 1024 in a6355b0
pybind11/include/pybind11/cast.h Line 1219 in a6355b0
|
Ok, fair enough -- merged, thanks! |
… type_caster<bool>::load (#1976)
The two Travis CI jobs are failing because something ( |
If the error indicator is set by a failing conversion in
type_caster<bool>::load
(e.g., by trying to convert anumpy.ndarray
of 2 or more values, resulting inValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
), the error is not noticed and Python complains that a non-NULL value is returned while an error has been set (SystemError: [...] returned a result with an error set
).This PR should fix that.
NOTE: Without the changes to
cast.h
, the newly added test fails:Is that not unexpected as well? Shouldn't all
error_already_set
exceptions be caught by pybind11?