From 8d396fcff2735b211939fbb22729212145e29c9f Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Thu, 24 Nov 2016 23:11:02 +0100 Subject: [PATCH] use pybind11::gil_scoped_acquire instead of PyGILState_* --- include/pybind11/common.h | 9 +-------- include/pybind11/pybind11.h | 8 ++++++++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/pybind11/common.h b/include/pybind11/common.h index e965324c..7da4215e 100644 --- a/include/pybind11/common.h +++ b/include/pybind11/common.h @@ -482,14 +482,7 @@ public: : std::runtime_error(e.what()), type(e.type), value(e.value), trace(e.trace) { e.type = e.value = e.trace = nullptr; } - ~error_already_set() { - if (value) { - PyGILState_STATE state = PyGILState_Ensure(); - PyErr_Restore(type, value, trace); - PyErr_Clear(); - PyGILState_Release(state); - } - } + inline ~error_already_set(); // implementation in pybind11.h error_already_set& operator=(const error_already_set &) = delete; diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index b7d75d98..37d61398 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -1647,6 +1647,14 @@ class gil_scoped_acquire { }; class gil_scoped_release { }; #endif +error_already_set::~error_already_set() { + if (value) { + gil_scoped_acquire gil; + PyErr_Restore(type, value, trace); + PyErr_Clear(); + } +} + inline function get_type_overload(const void *this_ptr, const detail::type_info *this_type, const char *name) { handle py_object = detail::get_object_handle(this_ptr, this_type); if (!py_object)