Blame SOURCES/gdb-rhbz1822715-fix-python-deprecation.patch

b2f73e
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
b2f73e
From: Kevin Buettner <kevinb@redhat.com>
b2f73e
Date: Thu, 16 Apr 2020 05:27:26 -0700
b2f73e
Subject: gdb-rhbz1822715-fix-python-deprecation.patch
b2f73e
b2f73e
;; Backport fix for deprecation of PyEval_InitThreads in Python 3.9.
b2f73e
b2f73e
Fix compilation of python/python.c for Python 3.9
b2f73e
b2f73e
This commit fixes a compilation warning/error when building GDB
b2f73e
with Python 3.9:
b2f73e
b2f73e
g++ -x c++  -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection  -DDNF_DEBUGINFO_INSTALL   -I. -I../../gdb -I../../gdb/config -DLOCALEDIR="\"/usr/share/locale\"" -DHAVE_CONFIG_H -I../../gdb/../include/opcode   -I../bfd -I../../gdb/../bfd -I../../gdb/../include -I../libdecnumber -I../../gdb/../libdecnumber  -I../../gdb/../gnulib/import -I../gnulib/import  -DTUI=1    -I/usr/include/guile/2.0 -pthread  -I/usr/include/python3.9 -I/usr/include/python3.9  -I../../gdb/.. -pthread -Wall -Wpointer-arith -Wno-unused -Wunused-value -Wunused-variable -Wunused-function -Wno-switch -Wno-char-subscripts -Wempty-body -Wunused-but-set-parameter -Wunused-but-set-variable -Wno-sign-compare -Wno-error=maybe-uninitialized -Wno-mismatched-tags -Wsuggest-override -Wimplicit-fallthrough=3 -Wduplicated-cond -Wshadow=local -Wdeprecated-copy -Wdeprecated-copy-dtor -Wredundant-move -Wformat -Wformat-nonliteral -Wno-unused -Werror -c -o ser-tcp.o -MT ser-tcp.o -MMD -MP -MF ./.deps/ser-tcp.Tpo ../../gdb/ser-tcp.c
b2f73e
../../gdb/python/python.c: In function 'bool do_start_initialization()':
b2f73e
../../gdb/python/python.c:1621:23: error: 'void PyEval_InitThreads()' is deprecated [-Werror=deprecated-declarations]
b2f73e
 1621 |   PyEval_InitThreads ();
b2f73e
      |                       ^
b2f73e
In file included from /usr/include/python3.9/Python.h:141,
b2f73e
                 from ../../gdb/python/python-internal.h:86,
b2f73e
                 from ../../gdb/python/python.c:92:
b2f73e
/usr/include/python3.9/ceval.h:132:37: note: declared here
b2f73e
  132 | Py_DEPRECATED(3.9) PyAPI_FUNC(void) PyEval_InitThreads(void);
b2f73e
      |                                     ^~~~~~~~~~~~~~~~~~
b2f73e
b2f73e
Information about the deprecated function can be found here:
b2f73e
b2f73e
https://docs.python.org/3.9/whatsnew/3.9.html#deprecated
b2f73e
b2f73e
Specifically, with regard to PyEval_InitThreads(), it says:
b2f73e
b2f73e
    The PyEval_InitThreads() and PyEval_ThreadsInitialized() functions
b2f73e
    are now deprecated and will be removed in Python 3.11.  Calling
b2f73e
    PyEval_InitThreads() now does nothing.  The GIL is initialized by
b2f73e
    Py_Initialize() since Python 3.7.  (Contributed by Victor Stinner
b2f73e
    in bpo-39877.)
b2f73e
b2f73e
I chose to disable the call with a #if test using PY_VERSION_HEX.
b2f73e
There is precedent for use of PY_VERSION_HEX; it's used in two places
b2f73e
in python-internal.h.  I noticed that under certain circumstances
b2f73e
python-internal.h defines PyEval_InitThreads to be nothing, which
b2f73e
accomplishes the same thing.  I considered doing something similar for
b2f73e
this case, but decided against it because, at some point in the future,
b2f73e
the presence of PyEval_InitThreads() without some explanation will be
b2f73e
confusing to a reader who won't be able to find PyEval_InitThreads in
b2f73e
the current (future for us) Python API.  IMO, use of the #if along
b2f73e
with an accompanying comment seemed more straightforward.
b2f73e
b2f73e
gdb/ChangeLog:
b2f73e
b2f73e
	* python/python.c (do_start_initialization): Don't call
b2f73e
	PyEval_InitThreads for Python 3.9 and beyond.
b2f73e
b2f73e
Change-Id: I0679fc10b6b76761a99538568f13188c6d8014e0
b2f73e
b2f73e
diff --git a/gdb/python/python.c b/gdb/python/python.c
b2f73e
--- a/gdb/python/python.c
b2f73e
+++ b/gdb/python/python.c
b2f73e
@@ -1618,7 +1618,12 @@ do_start_initialization ()
b2f73e
 #endif
b2f73e
 
b2f73e
   Py_Initialize ();
b2f73e
+#if PY_VERSION_HEX < 0x03090000
b2f73e
+  /* PyEval_InitThreads became deprecated in Python 3.9 and will
b2f73e
+     be removed in Python 3.11.  Prior to Python 3.7, this call was
b2f73e
+     required to initialize the GIL.  */
b2f73e
   PyEval_InitThreads ();
b2f73e
+#endif
b2f73e
 
b2f73e
 #ifdef IS_PY3K
b2f73e
   gdb_module = PyImport_ImportModule ("_gdb");