gdb: move gdbpy_gil into python-internal.h

Move gdbpy_gil class into python-internal.h, the next
commit wants to make use of this class from a file other
than python.c.

Approved-By: Tom Tromey <tom@tromey.com>
This commit is contained in:
Alexandra Hájková
2023-12-06 17:17:25 +01:00
parent 5c5e642dc0
commit 7ae9ecfd80
2 changed files with 24 additions and 24 deletions

View File

@@ -772,6 +772,30 @@ private:
PyThreadState *m_save;
};
/* A helper class to save and restore the GIL, but without touching
the other globals that are handled by gdbpy_enter. */
class gdbpy_gil
{
public:
gdbpy_gil ()
: m_state (PyGILState_Ensure ())
{
}
~gdbpy_gil ()
{
PyGILState_Release (m_state);
}
DISABLE_COPY_AND_ASSIGN (gdbpy_gil);
private:
PyGILState_STATE m_state;
};
/* Use this after a TRY_EXCEPT to throw the appropriate Python
exception. */
#define GDB_PY_HANDLE_EXCEPTION(Exception) \