diff options
Diffstat (limited to 'sources/shiboken6/libshiboken/sbkerrors.cpp')
| -rw-r--r-- | sources/shiboken6/libshiboken/sbkerrors.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/sources/shiboken6/libshiboken/sbkerrors.cpp b/sources/shiboken6/libshiboken/sbkerrors.cpp index 247fbefc4..6b0600082 100644 --- a/sources/shiboken6/libshiboken/sbkerrors.cpp +++ b/sources/shiboken6/libshiboken/sbkerrors.cpp @@ -164,6 +164,17 @@ static void restoreError(ErrorStore &s) #endif } +static void releaseError(ErrorStore &s) +{ + Py_XDECREF(s.exc); + s.exc = nullptr; +#ifdef PEP_OLD_ERR_API + Py_XDECREF(s.type); + Py_XDECREF(s.traceback); + s.type = s.traceback = nullptr; +#endif +} + static thread_local ErrorStore savedError; static bool hasPythonContext() @@ -209,6 +220,37 @@ PyObject *occurred() return PyErr_Occurred(); } +Stash::Stash() : m_store(std::make_unique<ErrorStore>()) +{ + fetchError(*m_store); +} + +Stash::~Stash() +{ + restore(); +} + +PyObject *Stash::getException() const +{ + return m_store ? m_store->exc : nullptr; +} + +void Stash::restore() +{ + if (m_store) { + restoreError(*m_store); + m_store.reset(); + } +} + +void Stash::release() +{ + if (m_store) { + releaseError(*m_store); + m_store.reset(); + } +} + } // namespace Errors namespace Warnings |
