Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .claude/CLAUDE.md

This file was deleted.

130 changes: 1 addition & 129 deletions Doc/c-api/interp-lifecycle.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ The following functions can be safely called before Python is initialized:
* :c:func:`PyMem_SetAllocator`
* :c:func:`PyMem_SetupDebugHooks`
* :c:func:`PyObject_SetArenaAllocator`
* :c:func:`Py_SetProgramName`
* :c:func:`Py_SetPythonHome`
* the configuration functions covered in :ref:`init-config`

* Informative functions:
Expand Down Expand Up @@ -74,8 +72,7 @@ The following functions can be safely called before Python is initialized:

Despite their apparent similarity to some of the functions listed above,
the following functions **should not be called** before the interpreter has
been initialized: :c:func:`Py_EncodeLocale`, :c:func:`PyEval_InitThreads`, and
:c:func:`Py_RunMain`.
been initialized: :c:func:`Py_EncodeLocale`, and :c:func:`Py_RunMain`.


.. _global-conf-vars:
Expand Down Expand Up @@ -355,7 +352,6 @@ Initializing and finalizing the interpreter
.. c:function:: void Py_Initialize()

.. index::
single: PyEval_InitThreads()
single: modules (in module sys)
single: path (in module sys)
pair: module; builtins
Expand Down Expand Up @@ -780,33 +776,6 @@ deleted. This can be done using interpreter views.
Process-wide parameters
-----------------------

.. c:function:: void Py_SetProgramName(const wchar_t *name)

.. index::
single: Py_Initialize()
single: main()

This API is kept for backward compatibility: setting
:c:member:`PyConfig.program_name` should be used instead, see :ref:`Python
Initialization Configuration <init-config>`.

This function should be called before :c:func:`Py_Initialize` is called for
the first time, if it is called at all. It tells the interpreter the value
of the ``argv[0]`` argument to the :c:func:`main` function of the program
(converted to wide characters).
This is used by some other functions below to find
the Python run-time libraries relative to the interpreter executable. The
default value is ``'python'``. The argument should point to a
zero-terminated wide character string in static storage whose contents will not
change for the duration of the program's execution. No code in the Python
interpreter will change the contents of this storage.

Use :c:func:`Py_DecodeLocale` to decode a bytes string to get a
:c:expr:`wchar_t*` string.

.. deprecated-removed:: 3.11 3.16


.. c:function:: const char* Py_GetVersion()

Return the version of this Python interpreter. This is a string that looks
Expand Down Expand Up @@ -875,100 +844,3 @@ Process-wide parameters
The returned string points into static storage; the caller should not modify its
value. The value is available to Python code as part of the variable
``sys.version``.


.. c:function:: void PySys_SetArgvEx(int argc, wchar_t **argv, int updatepath)

.. index::
single: main()
single: Py_FatalError()
single: argv (in module sys)

This API is kept for backward compatibility: setting
:c:member:`PyConfig.argv`, :c:member:`PyConfig.parse_argv` and
:c:member:`PyConfig.safe_path` should be used instead, see :ref:`Python
Initialization Configuration <init-config>`.

Set :data:`sys.argv` based on *argc* and *argv*. These parameters are
similar to those passed to the program's :c:func:`main` function with the
difference that the first entry should refer to the script file to be
executed rather than the executable hosting the Python interpreter. If there
isn't a script that will be run, the first entry in *argv* can be an empty
string. If this function fails to initialize :data:`sys.argv`, a fatal
condition is signalled using :c:func:`Py_FatalError`.

If *updatepath* is zero, this is all the function does. If *updatepath*
is non-zero, the function also modifies :data:`sys.path` according to the
following algorithm:

- If the name of an existing script is passed in ``argv[0]``, the absolute
path of the directory where the script is located is prepended to
:data:`sys.path`.
- Otherwise (that is, if *argc* is ``0`` or ``argv[0]`` doesn't point
to an existing file name), an empty string is prepended to
:data:`sys.path`, which is the same as prepending the current working
directory (``"."``).

Use :c:func:`Py_DecodeLocale` to decode a bytes string to get a
:c:expr:`wchar_t*` string.

See also :c:member:`PyConfig.orig_argv` and :c:member:`PyConfig.argv`
members of the :ref:`Python Initialization Configuration <init-config>`.

.. note::
It is recommended that applications embedding the Python interpreter
for purposes other than executing a single script pass ``0`` as *updatepath*,
and update :data:`sys.path` themselves if desired.
See :cve:`2008-5983`.

On versions before 3.1.3, you can achieve the same effect by manually
popping the first :data:`sys.path` element after having called
:c:func:`PySys_SetArgv`, for example using::

PyRun_SimpleString("import sys; sys.path.pop(0)\n");

.. versionadded:: 3.1.3

.. deprecated-removed:: 3.11 3.16


.. c:function:: void PySys_SetArgv(int argc, wchar_t **argv)

This API is kept for backward compatibility: setting
:c:member:`PyConfig.argv` and :c:member:`PyConfig.parse_argv` should be used
instead, see :ref:`Python Initialization Configuration <init-config>`.

This function works like :c:func:`PySys_SetArgvEx` with *updatepath* set
to ``1`` unless the :program:`python` interpreter was started with the
:option:`-I`.

Use :c:func:`Py_DecodeLocale` to decode a bytes string to get a
:c:expr:`wchar_t*` string.

See also :c:member:`PyConfig.orig_argv` and :c:member:`PyConfig.argv`
members of the :ref:`Python Initialization Configuration <init-config>`.

.. versionchanged:: 3.4 The *updatepath* value depends on :option:`-I`.

.. deprecated-removed:: 3.11 3.16


.. c:function:: void Py_SetPythonHome(const wchar_t *home)

This API is kept for backward compatibility: setting
:c:member:`PyConfig.home` should be used instead, see :ref:`Python
Initialization Configuration <init-config>`.

Set the default "home" directory, that is, the location of the standard
Python libraries. See :envvar:`PYTHONHOME` for the meaning of the
argument string.

The argument should point to a zero-terminated character string in static
storage whose contents will not change for the duration of the program's
execution. No code in the Python interpreter will change the contents of
this storage.

Use :c:func:`Py_DecodeLocale` to decode a bytes string to get a
:c:expr:`wchar_t*` string.

.. deprecated-removed:: 3.11 3.16
27 changes: 0 additions & 27 deletions Doc/c-api/threads.rst
Original file line number Diff line number Diff line change
Expand Up @@ -577,33 +577,6 @@ C extensions.
This thread's interpreter state.


.. c:function:: void PyEval_InitThreads()

.. index::
single: PyEval_AcquireThread()
single: PyEval_ReleaseThread()
single: PyEval_SaveThread()
single: PyEval_RestoreThread()

Deprecated function which does nothing.

In Python 3.6 and older, this function created the GIL if it didn't exist.

.. versionchanged:: 3.9
The function now does nothing.

.. versionchanged:: 3.7
This function is now called by :c:func:`Py_Initialize()`, so you don't
have to call it yourself anymore.

.. versionchanged:: 3.2
This function cannot be called before :c:func:`Py_Initialize()` anymore.

.. deprecated:: 3.9

.. index:: pair: module; _thread


.. c:function:: PyThreadState* PyEval_SaveThread()

Detach the :term:`attached thread state` and return it.
Expand Down
12 changes: 0 additions & 12 deletions Doc/data/refcounts.dat
Original file line number Diff line number Diff line change
Expand Up @@ -2265,15 +2265,6 @@ PySys_GetObject:const char*:name::

PySys_GetXOptions:PyObject*::0:

PySys_SetArgv:void:::
PySys_SetArgv:int:argc::
PySys_SetArgv:wchar_t**:argv::

PySys_SetArgvEx:void:::
PySys_SetArgvEx:int:argc::
PySys_SetArgvEx:wchar_t**:argv::
PySys_SetArgvEx:int:updatepath::

PySys_SetObject:int:::
PySys_SetObject:const char*:name::
PySys_SetObject:PyObject*:v:+1:
Expand Down Expand Up @@ -3085,9 +3076,6 @@ Py_ReprEnter:PyObject*:object:+1:
Py_ReprLeave:void:::
Py_ReprLeave:PyObject*:object:-1:

Py_SetProgramName:void:::
Py_SetProgramName:const wchar_t*:name::

Py_XDECREF:void:::
Py_XDECREF:PyObject*:o:-1:if o is not NULL

Expand Down
5 changes: 0 additions & 5 deletions Doc/data/stable_abi.dat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Doc/tools/removed-ids.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
# Remove from here in 3.16
c-api/allocation.html: deprecated-aliases
c-api/file.html: deprecated-api
c-api/interp-lifecycle.html: c.PySys_SetArgv
c-api/interp-lifecycle.html: c.PySys_SetArgvEx
c-api/interp-lifecycle.html: c.Py_SetProgramName
c-api/interp-lifecycle.html: c.Py_SetPythonHome
c-api/threads.html: c.PyEval_InitThreads

# Removed sections
library/asyncio-task.html: terminating-a-task-group
Expand Down
15 changes: 15 additions & 0 deletions Doc/whatsnew/3.16.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,21 @@ Deprecated C APIs
Removed C APIs
--------------

* Remove :c:func:`!PyEval_InitThreads` function which did nothing since Python
3.7 and was deprecated since Python 3.9.
(Contributed by Victor Stinner in :gh:`154757`.)

* Remove :c:func:`!Py_SetProgramName` and :c:func:`!Py_SetPythonHome`
functions, deprecated since Python 3.11. Instead, use :ref:`PyInitConfig C
API <pyinitconfig_api>` to set respectively ``"program_name"`` and
``"home"``.
(Contributed by Victor Stinner in :gh:`158001`.)

* Remove :c:func:`!PySys_SetArgv` and :c:func:`!PySys_SetArgvEx` functions,
deprecated since Python 3.11. Instead, set directly :data:`sys.argv`, and
maybe also :data:`sys.path`.
(Contributed by Victor Stinner in :gh:`158001`.)

* The :c:var:`!PyUnstable_ExecutableKinds` array, as well as the macros
:c:macro:`!PyUnstable_EXECUTABLE_KIND_SKIP`,
:c:macro:`!PyUnstable_EXECUTABLE_KIND_PY_FUNCTION`,
Expand Down
2 changes: 0 additions & 2 deletions Include/ceval.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ PyAPI_FUNC(PyObject *) PyEval_EvalFrameEx(PyFrameObject *f, int exc);
PyAPI_FUNC(PyThreadState *) PyEval_SaveThread(void);
PyAPI_FUNC(void) PyEval_RestoreThread(PyThreadState *);

Py_DEPRECATED(3.9) PyAPI_FUNC(void) PyEval_InitThreads(void);

PyAPI_FUNC(void) PyEval_AcquireThread(PyThreadState *tstate);
PyAPI_FUNC(void) PyEval_ReleaseThread(PyThreadState *tstate);

Expand Down
4 changes: 0 additions & 4 deletions Include/pylifecycle.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ PyAPI_FUNC(void) _Py_NO_RETURN Py_Exit(int);
PyAPI_FUNC(int) Py_Main(int argc, wchar_t **argv);
PyAPI_FUNC(int) Py_BytesMain(int argc, char **argv);

/* In pathconfig.c */
Py_DEPRECATED(3.11) PyAPI_FUNC(void) Py_SetProgramName(const wchar_t *);
Py_DEPRECATED(3.11) PyAPI_FUNC(void) Py_SetPythonHome(const wchar_t *);

#ifdef MS_WINDOWS
int _Py_CheckPython3(void);
#endif
Expand Down
3 changes: 0 additions & 3 deletions Include/sysmodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ PyAPI_FUNC(int) PySys_GetOptionalAttrString(const char *, PyObject **);
PyAPI_FUNC(PyObject *) PySys_GetObject(const char *);
PyAPI_FUNC(int) PySys_SetObject(const char *, PyObject *);

Py_DEPRECATED(3.11) PyAPI_FUNC(void) PySys_SetArgv(int, wchar_t **);
Py_DEPRECATED(3.11) PyAPI_FUNC(void) PySys_SetArgvEx(int, wchar_t **, int);

PyAPI_FUNC(void) PySys_WriteStdout(const char *format, ...)
Py_GCC_ATTRIBUTE((format(printf, 1, 2)));
PyAPI_FUNC(void) PySys_WriteStderr(const char *format, ...)
Expand Down
20 changes: 20 additions & 0 deletions Lib/test/test_ctypes/test_numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,26 @@ def test_float_overflow(self):
if (hasattr(t, "__ctype_le__")):
self.assertRaises(OverflowError, t.__ctype_le__, big_int)

# gh-156865: be silent in overflows of C types
self.assertEqual(ctypes.c_float(3e300).value, float('inf'))
self.assertEqual(ctypes.c_float.__ctype_le__(3e300).value, float('inf'))
self.assertEqual(ctypes.c_float.__ctype_be__(3e300).value, float('inf'))

@unittest.skipUnless(hasattr(ctypes, "c_float_complex"),
"requires C11 complex type")
def test_complex_overflow(self):
# gh-156865: be silent in overflows of C types
self.assertEqual(ctypes.c_float_complex(3e300).value, complex('inf'))
self.assertEqual(ctypes.c_float_complex.__ctype_le__(3e300).value,
complex('inf'))
self.assertEqual(ctypes.c_float_complex.__ctype_be__(3e300).value,
complex('inf'))
self.assertEqual(ctypes.c_float_complex(3e300j).value, complex('infj'))
self.assertEqual(ctypes.c_float_complex.__ctype_le__(3e300j).value,
complex('infj'))
self.assertEqual(ctypes.c_float_complex.__ctype_be__(3e300j).value,
complex('infj'))


if __name__ == '__main__':
unittest.main()
14 changes: 14 additions & 0 deletions Lib/test/test_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,20 @@ def test_705836(self):
self.assertRaises(OverflowError, struct.pack, "<e", big)
self.assertRaises(OverflowError, struct.pack, "e", big)

def test_float_complex_overflow(self):
for value in (
1e300 + 0.5j, # big real
1.5 + 1e300j, # big imag
):
for format in (">Zf", "<Zf", "Zf"):
with self.subTest(value=value, format=format):
self.assertRaises(OverflowError, struct.pack, format, value)

ba = bytearray(8)
with self.assertRaises(OverflowError):
struct.Struct(format).pack_into(ba, 0, value)
self.assertEqual(ba, bytearray(8))

def test_1530559(self):
for code, byteorder in iter_integer_formats():
format = byteorder + code
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Remove :c:func:`!Py_SetProgramName`, :c:func:`!Py_SetPythonHome`,
:c:func:`!PySys_SetArgv` and :c:func:`!PySys_SetArgvEx` functions, deprecated
since Python 3.11. Patch by Victor Stinner.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Remove :c:func:`!PyEval_InitThreads` function which did nothing since Python
3.7 and was deprecated since Python 3.9. Patch by Victor Stinner.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Raise :exc:`OverflowError`'s for native ``'Zf'`` format in :func:`struct.pack`,
like for ``'f'`` format. Previously overflows in the :c:expr:`float complex`
type were silent. Patch by Sergey B Kirpichev.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Don't raise exceptions on overflows in :class:`ctypes.c_float_complex`.
Patch by Sergey B Kirpichev.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The iOS testbed has been updated for compatibilty with Xcode 27.
Loading
Loading