Skip to content

Commit c1bf55a

Browse files
authored
Fix subinterpreter exception handling SEGFAULT (#5795)
* check for current exception, not uncaught_exceptions * remove all in-flight exception handling from ~subinterpreter_scoped_activate
1 parent 90bc05c commit c1bf55a

File tree

1 file changed

+0
-22
lines changed

1 file changed

+0
-22
lines changed

include/pybind11/subinterpreter.h

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -280,28 +280,6 @@ inline subinterpreter_scoped_activate::~subinterpreter_scoped_activate() {
280280
// We were on this interpreter already, so just make sure the GIL goes back as it was
281281
PyGILState_Release(gil_state_);
282282
} else {
283-
#if defined(PYBIND11_DETAILED_ERROR_MESSAGES)
284-
bool has_active_exception;
285-
# if defined(__cpp_lib_uncaught_exceptions)
286-
has_active_exception = std::uncaught_exceptions() > 0;
287-
# else
288-
// removed in C++20, replaced with uncaught_exceptions
289-
has_active_exception = std::uncaught_exception();
290-
# endif
291-
if (has_active_exception) {
292-
try {
293-
std::rethrow_exception(std::current_exception());
294-
} catch (error_already_set &) {
295-
// Because error_already_set holds python objects and what() acquires the GIL, it
296-
// is basically never OK to let these exceptions propagate outside the current
297-
// active interpreter.
298-
pybind11_fail("~subinterpreter_scoped_activate: cannot propagate Python "
299-
"exceptions outside of their owning interpreter");
300-
} catch (...) {
301-
}
302-
}
303-
#endif
304-
305283
if (tstate_) {
306284
#if defined(PYBIND11_DETAILED_ERROR_MESSAGES)
307285
if (detail::get_thread_state_unchecked() != tstate_) {

0 commit comments

Comments
 (0)