From 58e551cc737d77575b05de198da49479b81222a1 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 a04d5365..9c7f3688 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -1894,6 +1894,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();