mirror of
https://github.com/pybind/pybind11.git
synced 2026-04-20 14:59:27 +00:00
Fix subinterpreter exception handling SEGFAULT (#5795)
* check for current exception, not uncaught_exceptions * remove all in-flight exception handling from ~subinterpreter_scoped_activate
This commit is contained in:
@@ -280,28 +280,6 @@ inline subinterpreter_scoped_activate::~subinterpreter_scoped_activate() {
|
|||||||
// We were on this interpreter already, so just make sure the GIL goes back as it was
|
// We were on this interpreter already, so just make sure the GIL goes back as it was
|
||||||
PyGILState_Release(gil_state_);
|
PyGILState_Release(gil_state_);
|
||||||
} else {
|
} else {
|
||||||
#if defined(PYBIND11_DETAILED_ERROR_MESSAGES)
|
|
||||||
bool has_active_exception;
|
|
||||||
# if defined(__cpp_lib_uncaught_exceptions)
|
|
||||||
has_active_exception = std::uncaught_exceptions() > 0;
|
|
||||||
# else
|
|
||||||
// removed in C++20, replaced with uncaught_exceptions
|
|
||||||
has_active_exception = std::uncaught_exception();
|
|
||||||
# endif
|
|
||||||
if (has_active_exception) {
|
|
||||||
try {
|
|
||||||
std::rethrow_exception(std::current_exception());
|
|
||||||
} catch (error_already_set &) {
|
|
||||||
// Because error_already_set holds python objects and what() acquires the GIL, it
|
|
||||||
// is basically never OK to let these exceptions propagate outside the current
|
|
||||||
// active interpreter.
|
|
||||||
pybind11_fail("~subinterpreter_scoped_activate: cannot propagate Python "
|
|
||||||
"exceptions outside of their owning interpreter");
|
|
||||||
} catch (...) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (tstate_) {
|
if (tstate_) {
|
||||||
#if defined(PYBIND11_DETAILED_ERROR_MESSAGES)
|
#if defined(PYBIND11_DETAILED_ERROR_MESSAGES)
|
||||||
if (detail::get_thread_state_unchecked() != tstate_) {
|
if (detail::get_thread_state_unchecked() != tstate_) {
|
||||||
|
|||||||
Reference in New Issue
Block a user