* [PATCH] Fix compilation of python/python.c for Python 3.9
@ 2020-04-15 17:54 Kevin Buettner
2020-04-15 18:02 ` Paul Koning
0 siblings, 1 reply; 5+ messages in thread
From: Kevin Buettner @ 2020-04-15 17:54 UTC (permalink / raw)
To: gdb-patches
This commit fixes a compilation warning/error when building GDB
with Python 3.9:
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
../../gdb/python/python.c: In function 'bool do_start_initialization()':
../../gdb/python/python.c:1621:23: error: 'void PyEval_InitThreads()' is deprecated [-Werror=deprecated-declarations]
1621 | PyEval_InitThreads ();
| ^
In file included from /usr/include/python3.9/Python.h:141,
from ../../gdb/python/python-internal.h:86,
from ../../gdb/python/python.c:92:
/usr/include/python3.9/ceval.h:132:37: note: declared here
132 | Py_DEPRECATED(3.9) PyAPI_FUNC(void) PyEval_InitThreads(void);
| ^~~~~~~~~~~~~~~~~~
Information about the deprecated function can be found here:
https://docs.python.org/3.9/whatsnew/3.9.html#deprecated
Specifically, with regard to PyEval_InitThreads(), it says:
The PyEval_InitThreads() and PyEval_ThreadsInitialized() functions
are now deprecated and will be removed in Python 3.11. Calling
PyEval_InitThreads() now does nothing. The GIL is initialized by
Py_Initialize() since Python 3.7. (Contributed by Victor Stinner
in bpo-39877.)
I chose to disable the call with a #if test using PY_VERSION_HEX.
There is precedent for use of PY_VERSION_HEX; it's used in two places
in python-internal.h. I noticed that under certain circumstances
python-internal.h defines PyEval_InitThreads to be nothing, which
accomplishes the same thing. I considered doing something similar for
this case, but decided against it because, at some point in the future,
the presence of PyEval_InitThreads() without some explanation will be
confusing to a reader who won't be able to find PyEval_InitThreads in
the current (future for us) Python API. IMO, use of the #if along
with an accompanying comment seemed more straightforward.
gdb/ChangeLog:
* python/python.c (do_start_initialization): Don't call
PyEval_InitThreads for Python 3.9 and beyond.
Change-Id: I0679fc10b6b76761a99538568f13188c6d8014e0
---
gdb/python/python.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 02543aea71..e56520ab11 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1701,7 +1701,12 @@ do_start_initialization ()
#endif
Py_Initialize ();
+#if PY_VERSION_HEX < 0x03090000
+ /* PyEval_InitThreads became deprecated in Python 3.9 and will
+ be removed in Python 3.11. Prior to Python 3.7, this call was
+ required to initialize the GIL. */
PyEval_InitThreads ();
+#endif
#ifdef IS_PY3K
gdb_module = PyImport_ImportModule ("_gdb");
--
2.25.2
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix compilation of python/python.c for Python 3.9
2020-04-15 17:54 [PATCH] Fix compilation of python/python.c for Python 3.9 Kevin Buettner
@ 2020-04-15 18:02 ` Paul Koning
2020-04-15 18:14 ` Kevin Buettner
0 siblings, 1 reply; 5+ messages in thread
From: Paul Koning @ 2020-04-15 18:02 UTC (permalink / raw)
To: Kevin Buettner, Kevin Buettner via Gdb-patches
> On Apr 15, 2020, at 1:54 PM, Kevin Buettner via Gdb-patches <gdb-patches@sourceware.org> wrote:
>
> This commit fixes a compilation warning/error when building GDB
> with Python 3.9:
>
> ...
>
> Specifically, with regard to PyEval_InitThreads(), it says:
>
> The PyEval_InitThreads() and PyEval_ThreadsInitialized() functions
> are now deprecated and will be removed in Python 3.11. Calling
> PyEval_InitThreads() now does nothing. The GIL is initialized by
> Py_Initialize() since Python 3.7. (Contributed by Victor Stinner
> in bpo-39877.)
>
> I chose to disable the call with a #if test using PY_VERSION_HEX.
> ...
> Py_Initialize ();
> +#if PY_VERSION_HEX < 0x03090000
> + /* PyEval_InitThreads became deprecated in Python 3.9 and will
> + be removed in Python 3.11. Prior to Python 3.7, this call was
> + required to initialize the GIL. */
> PyEval_InitThreads ();
> +#endif
Since it is not needed as of 3.7, would it make sense for the #if to be on 0x03070000 instead?
paul
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix compilation of python/python.c for Python 3.9
2020-04-15 18:02 ` Paul Koning
@ 2020-04-15 18:14 ` Kevin Buettner
2020-04-15 21:11 ` Tom Tromey
0 siblings, 1 reply; 5+ messages in thread
From: Kevin Buettner @ 2020-04-15 18:14 UTC (permalink / raw)
To: gdb-patches; +Cc: Paul Koning
On Wed, 15 Apr 2020 14:02:32 -0400
Paul Koning <paulkoning@comcast.net> wrote:
> > On Apr 15, 2020, at 1:54 PM, Kevin Buettner via Gdb-patches <gdb-patches@sourceware.org> wrote:
> >
> > This commit fixes a compilation warning/error when building GDB
> > with Python 3.9:
> >
> > ...
> >
> > Specifically, with regard to PyEval_InitThreads(), it says:
> >
> > The PyEval_InitThreads() and PyEval_ThreadsInitialized() functions
> > are now deprecated and will be removed in Python 3.11. Calling
> > PyEval_InitThreads() now does nothing. The GIL is initialized by
> > Py_Initialize() since Python 3.7. (Contributed by Victor Stinner
> > in bpo-39877.)
> >
> > I chose to disable the call with a #if test using PY_VERSION_HEX.
>
> > ...
> > Py_Initialize ();
> > +#if PY_VERSION_HEX < 0x03090000
> > + /* PyEval_InitThreads became deprecated in Python 3.9 and will
> > + be removed in Python 3.11. Prior to Python 3.7, this call was
> > + required to initialize the GIL. */
> > PyEval_InitThreads ();
> > +#endif
>
> Since it is not needed as of 3.7, would it make sense for the #if to be on 0x03070000 instead?
It does make sense, and I'm willing to change it if that's the
consensus. I simply chose to use the version number where the call in
question became deprecated.
Kevin
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix compilation of python/python.c for Python 3.9
2020-04-15 18:14 ` Kevin Buettner
@ 2020-04-15 21:11 ` Tom Tromey
2020-04-16 12:19 ` Kevin Buettner
0 siblings, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2020-04-15 21:11 UTC (permalink / raw)
To: Kevin Buettner via Gdb-patches; +Cc: Kevin Buettner, Paul Koning
>>>>> "Kevin" == Kevin Buettner via Gdb-patches <gdb-patches@sourceware.org> writes:
>> Since it is not needed as of 3.7, would it make sense for the #if to
>> be on 0x03070000 instead?
Kevin> It does make sense, and I'm willing to change it if that's the
Kevin> consensus. I simply chose to use the version number where the call in
Kevin> question became deprecated.
Either one is fine by me. The patch looks good.
Tom
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix compilation of python/python.c for Python 3.9
2020-04-15 21:11 ` Tom Tromey
@ 2020-04-16 12:19 ` Kevin Buettner
0 siblings, 0 replies; 5+ messages in thread
From: Kevin Buettner @ 2020-04-16 12:19 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
On Wed, 15 Apr 2020 15:11:21 -0600
Tom Tromey <tom@tromey.com> wrote:
> >>>>> "Kevin" == Kevin Buettner via Gdb-patches <gdb-patches@sourceware.org> writes:
>
> >> Since it is not needed as of 3.7, would it make sense for the #if to
> >> be on 0x03070000 instead?
>
> Kevin> It does make sense, and I'm willing to change it if that's the
> Kevin> consensus. I simply chose to use the version number where the call in
> Kevin> question became deprecated.
>
> Either one is fine by me. The patch looks good.
Thanks for looking it over.
I've pushed this commit.
Kevin
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-04-16 12:19 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-15 17:54 [PATCH] Fix compilation of python/python.c for Python 3.9 Kevin Buettner
2020-04-15 18:02 ` Paul Koning
2020-04-15 18:14 ` Kevin Buettner
2020-04-15 21:11 ` Tom Tromey
2020-04-16 12:19 ` Kevin Buettner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).