]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/python: avoid use of _PyOS_ReadlineTState
authorAndrew Burgess <aburgess@redhat.com>
Wed, 6 Dec 2023 15:57:11 +0000 (16:57 +0100)
committerAlexandra Hájková <ahajkova@redhat.com>
Wed, 13 Dec 2023 09:46:44 +0000 (10:46 +0100)
In python/py-gdb-readline.c we make use of _PyOS_ReadlineTState,
however, this variable is no longer public in Python 3.13, and so GDB
no longer builds.

We are making use of _PyOS_ReadlineTState in order to re-acquire the
Python Global Interpreter Lock (GIL).  The _PyOS_ReadlineTState
variable is set in Python's outer readline code prior to calling the
user (GDB) supplied readline callback function, which for us is
gdbpy_readline_wrapper.  The gdbpy_readline_wrapper function is called
without the GIL held.

Instead of using _PyOS_ReadlineTState, I propose that we switch to
calling PyGILState_Ensure() and PyGILState_Release().  These functions
will acquire the GIL based on the current thread.  I think this should
be sufficient; I can't imagine why we'd be running
gdbpy_readline_wrapper on one thread on behalf of a different Python
thread.... that would be unexpected I think.

Approved-By: Tom Tromey <tom@tromey.com>
gdb/python/py-gdb-readline.c

index 124cec8055d0f0bc10ca179adafd7183d2e9ff5e..699d396dd194cfdea4593141ef363d93b426afd1 100644 (file)
@@ -56,13 +56,11 @@ gdbpy_readline_wrapper (FILE *sys_stdin, FILE *sys_stdout,
       if (except.reason == RETURN_QUIT)
        return NULL;
 
-      /* The thread state is nulled during gdbpy_readline_wrapper,
-        with the original value saved in the following undocumented
-        variable (see Python's Parser/myreadline.c and
-        Modules/readline.c).  */
-      PyEval_RestoreThread (_PyOS_ReadlineTState);
+
+      /* This readline callback is called without the GIL held.  */
+      gdbpy_gil gil;
+
       gdbpy_convert_exception (except);
-      PyEval_SaveThread ();
       return NULL;
     }