[1/2] gdb: move gdbpy_gil into python-internal.h

Message ID 20231207110240.1853760-1-ahajkova@redhat.com
State New
Headers
Series [1/2] gdb: move gdbpy_gil into python-internal.h |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed

Commit Message

Alexandra Petlanova Hajkova Dec. 7, 2023, 11:02 a.m. UTC
  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.
---
 gdb/python/python-internal.h | 24 ++++++++++++++++++++++++
 gdb/python/python.c          | 24 ------------------------
 2 files changed, 24 insertions(+), 24 deletions(-)
  

Comments

Tom Tromey Dec. 8, 2023, 6:04 p.m. UTC | #1
>>>>> "Alexandra" == Alexandra Hájková <ahajkova@redhat.com> writes:

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

Thank you.
Approved-By: Tom Tromey <tom@tromey.com>

Tom
  

Patch

diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 86eb5436f2a..14e15574685 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -772,6 +772,30 @@  class gdbpy_allow_threads
   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)	\
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 8a36673a3e4..f9df57b9fd5 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -264,30 +264,6 @@  gdbpy_enter::finalize ()
   python_gdbarch = current_inferior ()->arch ();
 }
 
-/* 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;
-};
-
 /* Set the quit flag.  */
 
 static void