Using str (aka PyObject_Str) will fetch the error message from
gdb.GdbError ("message"). */
- if (m_error_value && m_error_value != Py_None)
- return gdbpy_obj_to_string (m_error_value);
+ if (m_error_value.get () != nullptr && m_error_value.get () != Py_None)
+ return gdbpy_obj_to_string (m_error_value.get ());
else
- return gdbpy_obj_to_string (m_error_type);
+ return gdbpy_obj_to_string (m_error_type.get ());
}
/* See python-internal.h. */
gdb::unique_xmalloc_ptr<char>
gdbpy_err_fetch::type_to_string () const
{
- return gdbpy_obj_to_string (m_error_type);
+ return gdbpy_obj_to_string (m_error_type.get ());
}
/* Convert a GDB exception to the appropriate Python exception.
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.
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
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