Skip to content

Commit a5a4659

Browse files
authored
gh-158001: Remove Py_SetProgramName() function (#158024)
Remove Py_SetProgramName(), Py_SetPythonHome(), PySys_SetArgv() and PySys_SetArgvEx() functions, deprecated since Python 3.11. Mark the 4 functions as abi_only in stable_abi.toml.
1 parent 8293654 commit a5a4659

12 files changed

Lines changed: 34 additions & 156 deletions

File tree

‎Doc/c-api/interp-lifecycle.rst‎

Lines changed: 0 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ The following functions can be safely called before Python is initialized:
3737
* :c:func:`PyMem_SetAllocator`
3838
* :c:func:`PyMem_SetupDebugHooks`
3939
* :c:func:`PyObject_SetArenaAllocator`
40-
* :c:func:`Py_SetProgramName`
41-
* :c:func:`Py_SetPythonHome`
4240
* the configuration functions covered in :ref:`init-config`
4341

4442
* Informative functions:
@@ -778,33 +776,6 @@ deleted. This can be done using interpreter views.
778776
Process-wide parameters
779777
-----------------------
780778
781-
.. c:function:: void Py_SetProgramName(const wchar_t *name)
782-
783-
.. index::
784-
single: Py_Initialize()
785-
single: main()
786-
787-
This API is kept for backward compatibility: setting
788-
:c:member:`PyConfig.program_name` should be used instead, see :ref:`Python
789-
Initialization Configuration <init-config>`.
790-
791-
This function should be called before :c:func:`Py_Initialize` is called for
792-
the first time, if it is called at all. It tells the interpreter the value
793-
of the ``argv[0]`` argument to the :c:func:`main` function of the program
794-
(converted to wide characters).
795-
This is used by some other functions below to find
796-
the Python run-time libraries relative to the interpreter executable. The
797-
default value is ``'python'``. The argument should point to a
798-
zero-terminated wide character string in static storage whose contents will not
799-
change for the duration of the program's execution. No code in the Python
800-
interpreter will change the contents of this storage.
801-
802-
Use :c:func:`Py_DecodeLocale` to decode a bytes string to get a
803-
:c:expr:`wchar_t*` string.
804-
805-
.. deprecated-removed:: 3.11 3.16
806-
807-
808779
.. c:function:: const char* Py_GetVersion()
809780
810781
Return the version of this Python interpreter. This is a string that looks
@@ -873,100 +844,3 @@ Process-wide parameters
873844
The returned string points into static storage; the caller should not modify its
874845
value. The value is available to Python code as part of the variable
875846
``sys.version``.
876-
877-
878-
.. c:function:: void PySys_SetArgvEx(int argc, wchar_t **argv, int updatepath)
879-
880-
.. index::
881-
single: main()
882-
single: Py_FatalError()
883-
single: argv (in module sys)
884-
885-
This API is kept for backward compatibility: setting
886-
:c:member:`PyConfig.argv`, :c:member:`PyConfig.parse_argv` and
887-
:c:member:`PyConfig.safe_path` should be used instead, see :ref:`Python
888-
Initialization Configuration <init-config>`.
889-
890-
Set :data:`sys.argv` based on *argc* and *argv*. These parameters are
891-
similar to those passed to the program's :c:func:`main` function with the
892-
difference that the first entry should refer to the script file to be
893-
executed rather than the executable hosting the Python interpreter. If there
894-
isn't a script that will be run, the first entry in *argv* can be an empty
895-
string. If this function fails to initialize :data:`sys.argv`, a fatal
896-
condition is signalled using :c:func:`Py_FatalError`.
897-
898-
If *updatepath* is zero, this is all the function does. If *updatepath*
899-
is non-zero, the function also modifies :data:`sys.path` according to the
900-
following algorithm:
901-
902-
- If the name of an existing script is passed in ``argv[0]``, the absolute
903-
path of the directory where the script is located is prepended to
904-
:data:`sys.path`.
905-
- Otherwise (that is, if *argc* is ``0`` or ``argv[0]`` doesn't point
906-
to an existing file name), an empty string is prepended to
907-
:data:`sys.path`, which is the same as prepending the current working
908-
directory (``"."``).
909-
910-
Use :c:func:`Py_DecodeLocale` to decode a bytes string to get a
911-
:c:expr:`wchar_t*` string.
912-
913-
See also :c:member:`PyConfig.orig_argv` and :c:member:`PyConfig.argv`
914-
members of the :ref:`Python Initialization Configuration <init-config>`.
915-
916-
.. note::
917-
It is recommended that applications embedding the Python interpreter
918-
for purposes other than executing a single script pass ``0`` as *updatepath*,
919-
and update :data:`sys.path` themselves if desired.
920-
See :cve:`2008-5983`.
921-
922-
On versions before 3.1.3, you can achieve the same effect by manually
923-
popping the first :data:`sys.path` element after having called
924-
:c:func:`PySys_SetArgv`, for example using::
925-
926-
PyRun_SimpleString("import sys; sys.path.pop(0)\n");
927-
928-
.. versionadded:: 3.1.3
929-
930-
.. deprecated-removed:: 3.11 3.16
931-
932-
933-
.. c:function:: void PySys_SetArgv(int argc, wchar_t **argv)
934-
935-
This API is kept for backward compatibility: setting
936-
:c:member:`PyConfig.argv` and :c:member:`PyConfig.parse_argv` should be used
937-
instead, see :ref:`Python Initialization Configuration <init-config>`.
938-
939-
This function works like :c:func:`PySys_SetArgvEx` with *updatepath* set
940-
to ``1`` unless the :program:`python` interpreter was started with the
941-
:option:`-I`.
942-
943-
Use :c:func:`Py_DecodeLocale` to decode a bytes string to get a
944-
:c:expr:`wchar_t*` string.
945-
946-
See also :c:member:`PyConfig.orig_argv` and :c:member:`PyConfig.argv`
947-
members of the :ref:`Python Initialization Configuration <init-config>`.
948-
949-
.. versionchanged:: 3.4 The *updatepath* value depends on :option:`-I`.
950-
951-
.. deprecated-removed:: 3.11 3.16
952-
953-
954-
.. c:function:: void Py_SetPythonHome(const wchar_t *home)
955-
956-
This API is kept for backward compatibility: setting
957-
:c:member:`PyConfig.home` should be used instead, see :ref:`Python
958-
Initialization Configuration <init-config>`.
959-
960-
Set the default "home" directory, that is, the location of the standard
961-
Python libraries. See :envvar:`PYTHONHOME` for the meaning of the
962-
argument string.
963-
964-
The argument should point to a zero-terminated character string in static
965-
storage whose contents will not change for the duration of the program's
966-
execution. No code in the Python interpreter will change the contents of
967-
this storage.
968-
969-
Use :c:func:`Py_DecodeLocale` to decode a bytes string to get a
970-
:c:expr:`wchar_t*` string.
971-
972-
.. deprecated-removed:: 3.11 3.16

‎Doc/data/refcounts.dat‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2265,15 +2265,6 @@ PySys_GetObject:const char*:name::
22652265

22662266
PySys_GetXOptions:PyObject*::0:
22672267

2268-
PySys_SetArgv:void:::
2269-
PySys_SetArgv:int:argc::
2270-
PySys_SetArgv:wchar_t**:argv::
2271-
2272-
PySys_SetArgvEx:void:::
2273-
PySys_SetArgvEx:int:argc::
2274-
PySys_SetArgvEx:wchar_t**:argv::
2275-
PySys_SetArgvEx:int:updatepath::
2276-
22772268
PySys_SetObject:int:::
22782269
PySys_SetObject:const char*:name::
22792270
PySys_SetObject:PyObject*:v:+1:
@@ -3085,9 +3076,6 @@ Py_ReprEnter:PyObject*:object:+1:
30853076
Py_ReprLeave:void:::
30863077
Py_ReprLeave:PyObject*:object:-1:
30873078

3088-
Py_SetProgramName:void:::
3089-
Py_SetProgramName:const wchar_t*:name::
3090-
30913079
Py_XDECREF:void:::
30923080
Py_XDECREF:PyObject*:o:-1:if o is not NULL
30933081

‎Doc/data/stable_abi.dat‎

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Doc/tools/removed-ids.txt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
# Remove from here in 3.16
44
c-api/allocation.html: deprecated-aliases
55
c-api/file.html: deprecated-api
6+
c-api/interp-lifecycle.html: c.PySys_SetArgv
7+
c-api/interp-lifecycle.html: c.PySys_SetArgvEx
8+
c-api/interp-lifecycle.html: c.Py_SetProgramName
9+
c-api/interp-lifecycle.html: c.Py_SetPythonHome
610
c-api/threads.html: c.PyEval_InitThreads
711

812
# Removed sections

‎Doc/whatsnew/3.16.rst‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,17 @@ Removed C APIs
11451145
3.7 and was deprecated since Python 3.9.
11461146
(Contributed by Victor Stinner in :gh:`154757`.)
11471147

1148+
* Remove :c:func:`!Py_SetProgramName` and :c:func:`!Py_SetPythonHome`
1149+
functions, deprecated since Python 3.11. Instead, use :ref:`PyInitConfig C
1150+
API <pyinitconfig_api>` to set respectively ``"program_name"`` and
1151+
``"home"``.
1152+
(Contributed by Victor Stinner in :gh:`158001`.)
1153+
1154+
* Remove :c:func:`!PySys_SetArgv` and :c:func:`!PySys_SetArgvEx` functions,
1155+
deprecated since Python 3.11. Instead, set directly :data:`sys.argv`, and
1156+
maybe also :data:`sys.path`.
1157+
(Contributed by Victor Stinner in :gh:`158001`.)
1158+
11481159
* The :c:var:`!PyUnstable_ExecutableKinds` array, as well as the macros
11491160
:c:macro:`!PyUnstable_EXECUTABLE_KIND_SKIP`,
11501161
:c:macro:`!PyUnstable_EXECUTABLE_KIND_PY_FUNCTION`,

‎Include/pylifecycle.h‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ PyAPI_FUNC(void) _Py_NO_RETURN Py_Exit(int);
3333
PyAPI_FUNC(int) Py_Main(int argc, wchar_t **argv);
3434
PyAPI_FUNC(int) Py_BytesMain(int argc, char **argv);
3535

36-
/* In pathconfig.c */
37-
Py_DEPRECATED(3.11) PyAPI_FUNC(void) Py_SetProgramName(const wchar_t *);
38-
Py_DEPRECATED(3.11) PyAPI_FUNC(void) Py_SetPythonHome(const wchar_t *);
39-
4036
#ifdef MS_WINDOWS
4137
int _Py_CheckPython3(void);
4238
#endif

‎Include/sysmodule.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ PyAPI_FUNC(int) PySys_GetOptionalAttrString(const char *, PyObject **);
1313
PyAPI_FUNC(PyObject *) PySys_GetObject(const char *);
1414
PyAPI_FUNC(int) PySys_SetObject(const char *, PyObject *);
1515

16-
Py_DEPRECATED(3.11) PyAPI_FUNC(void) PySys_SetArgv(int, wchar_t **);
17-
Py_DEPRECATED(3.11) PyAPI_FUNC(void) PySys_SetArgvEx(int, wchar_t **, int);
18-
1916
PyAPI_FUNC(void) PySys_WriteStdout(const char *format, ...)
2017
Py_GCC_ATTRIBUTE((format(printf, 1, 2)));
2118
PyAPI_FUNC(void) PySys_WriteStderr(const char *format, ...)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Remove :c:func:`!Py_SetProgramName`, :c:func:`!Py_SetPythonHome`,
2+
:c:func:`!PySys_SetArgv` and :c:func:`!PySys_SetArgvEx` functions, deprecated
3+
since Python 3.11. Patch by Victor Stinner.

‎Misc/stable_abi.toml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,8 +1350,10 @@
13501350
abi_only = true
13511351
[function.PySys_SetArgv]
13521352
added = '3.2'
1353+
abi_only = true
13531354
[function.PySys_SetArgvEx]
13541355
added = '3.2'
1356+
abi_only = true
13551357
[function.PySys_SetObject]
13561358
added = '3.2'
13571359
[function.PySys_SetPath]
@@ -1695,8 +1697,10 @@
16951697
added = '3.2'
16961698
[function.Py_SetProgramName]
16971699
added = '3.2'
1700+
abi_only = true
16981701
[function.Py_SetPythonHome]
16991702
added = '3.2'
1703+
abi_only = true
17001704
[function.Py_SetRecursionLimit]
17011705
added = '3.2'
17021706
[function.Py_VaBuildValue]

‎Programs/_testembed.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ extern void PySys_AddWarnOption(const wchar_t *s);
2323
extern void PySys_AddXOption(const wchar_t *s);
2424
extern void Py_SetPath(const wchar_t *path);
2525

26+
// Functions removed from Python 3.16 API but still exported for the stable
27+
// ABI.
28+
extern void Py_SetPythonHome(const wchar_t *);
29+
2630
// These functions were removed from Python 3.15 API but are still exported
2731
// for the stable ABI. We want to test them in this program.
2832
extern void PySys_ResetWarnOptions(void);

0 commit comments

Comments
 (0)