Bug 28668 - Py_SetProgramName will be deprecated in Python 3.11
Summary: Py_SetProgramName will be deprecated in Python 3.11
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: python (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: 13.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-12-07 16:08 UTC by Kevin Buettner
Modified: 2023-03-17 18:34 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kevin Buettner 2021-12-07 16:08:16 UTC
Py_SetProgramName, which is called from gdb/python/python.c, will be deprecated in Python 3.11.  When that happens, we can expect to error messages like this when building GDB with -Werror:

../../gdb/python/python.c:1757:21: error: 'void Py_SetProgramName(const wchar_t*)' is deprecated [-Werror=deprecated-declarations]
 1757 |   Py_SetProgramName (progname_copy);
      |   ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
In file included from /usr/include/python3.11/Python.h:92,
                 from ../../gdb/python/python-internal.h:86,
                 from ../../gdb/python/python.c:92:
/usr/include/python3.11/pylifecycle.h:37:38: note: declared here
   37 | Py_DEPRECATED(3.11) PyAPI_FUNC(void) Py_SetProgramName(const wchar_t *);
      |                                      ^~~~~~~~~~~~~~~~~
cc1plus: all warnings being treated as errors

In order to work around this problem, -Wno-deprecated-declarations may be appended to the set of warning flags used to build GDB.

However, long term, we'll need to adjust do_start_initialization() in python.c to use the PyConfig mechanisms introduced in Python 3.8.

For reference, see:

https://bugs.python.org/issue44113
https://docs.python.org/3.11/whatsnew/3.11.html
https://docs.python.org/3.11/c-api/init_config.html#c.PyConfig

The latter link contains an example which shows how to call PyConfig_SetString() to set the program_name field in the PyConfig struct.

Sadly, we'll still need to support the use of Py_SetProgramName in gdb/python/python.c because (I anticipate that) the GDB community will want to support building against Python versions older than 3.8 for a while yet.

I recommend use of '#if Py_VERSION_HEX < 0x308000' to separate the new PyConfig calls from the existing calls to Py_SetProgramName.
Comment 1 Mark Wielaard 2022-07-01 08:16:19 UTC
Kevin posted a patch:
https://sourceware.org/pipermail/gdb-patches/2022-June/190460.html
Comment 2 Tom Tromey 2023-03-17 18:34:24 UTC
This was fixed.