From c9ee873a53e0dbcc2a260ab06da04542443846a3 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Mon, 16 Apr 2018 19:08:45 -0700 Subject: [PATCH] Properly report exceptions thrown during module initialization. If an exception is thrown during module initialization, the error_already_set destructor will try to call `get_internals()` *after* setting Python's error indicator, resulting in a `SystemError: ... returned with an error set`. Fix that by temporarily stashing away the error indicator in the destructor. --- include/pybind11/pybind11.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 9a5f71a1d..f84d4bb35 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -1867,6 +1867,7 @@ class gil_scoped_release { }; error_already_set::~error_already_set() { if (type) { + error_scope scope; gil_scoped_acquire gil; type.release().dec_ref(); value.release().dec_ref();