gdb/python: convert gdbpy_err_fetch to use gdbpy_ref

Convert the gdbpy_err_fetch class to make use of gdbpy_ref, this
removes the need for manual reference count management, and allows the
destructor to be removed.

There should be no functional change after this commit.

I think this cleanup is worth doing on its own, however, in a later
commit I will want to copy instances of gdbpy_err_fetch, and switching
to using gdbpy_ref means that I can rely on the default copy
constructor, without having to add one that handles the reference
counts, so this is good preparation for that upcoming change.
This commit is contained in:
Andrew Burgess
2022-05-24 11:54:40 +01:00
parent 5fb28d2607
commit 8a0b60471a
2 changed files with 14 additions and 17 deletions

View File

@ -549,14 +549,12 @@ public:
gdbpy_err_fetch ()
{
PyErr_Fetch (&m_error_type, &m_error_value, &m_error_traceback);
}
PyObject *error_type, *error_value, *error_traceback;
~gdbpy_err_fetch ()
{
Py_XDECREF (m_error_type);
Py_XDECREF (m_error_value);
Py_XDECREF (m_error_traceback);
PyErr_Fetch (&error_type, &error_value, &error_traceback);
m_error_type.reset (error_type);
m_error_value.reset (error_value);
m_error_traceback.reset (error_traceback);
}
/* Call PyErr_Restore using the values stashed in this object.
@ -565,10 +563,9 @@ public:
void restore ()
{
PyErr_Restore (m_error_type, m_error_value, m_error_traceback);
m_error_type = nullptr;
m_error_value = nullptr;
m_error_traceback = nullptr;
PyErr_Restore (m_error_type.release (),
m_error_value.release (),
m_error_traceback.release ());
}
/* Return the string representation of the exception represented by
@ -587,12 +584,12 @@ public:
bool type_matches (PyObject *type) const
{
return PyErr_GivenExceptionMatches (m_error_type, type);
return PyErr_GivenExceptionMatches (m_error_type.get (), type);
}
private:
PyObject *m_error_type, *m_error_value, *m_error_traceback;
gdbpy_ref<> m_error_type, m_error_value, m_error_traceback;
};
/* Called before entering the Python interpreter to install the