Skip to content

Commit 816298a

Browse files
committed
Ensure we are not leaking a Python error is something is wrong elsewhere (e.g. UB, or bug in Python beta testing).
See also: #5879 (comment)
1 parent 0f1f8ea commit 816298a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

include/pybind11/cast.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,10 @@ struct type_caster<T, enable_if_t<std::is_arithmetic<T>::value && !is_std_char_t
285285
}
286286
}
287287

288-
// Python API reported an error
289-
bool py_err = py_value == (py_type) -1 && PyErr_Occurred();
288+
bool py_err = (PyErr_Occurred() != nullptr);
289+
if (py_err) {
290+
assert(py_value == static_cast<py_type>(-1));
291+
}
290292

291293
// Check to see if the conversion is valid (integers should match exactly)
292294
// Signed/unsigned checks happen elsewhere

0 commit comments

Comments
 (0)