Skip to content

Commit 335820e

Browse files
committed
Merge branch 'main' into pythongh-116380-dir-fd
2 parents 151511d + 30f0643 commit 335820e

File tree

117 files changed

+5629
-2246
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+5629
-2246
lines changed

Doc/glossary.rst

+6-6
Original file line numberDiff line numberDiff line change
@@ -547,12 +547,12 @@ Glossary
547547
tasks such as compression or hashing. Also, the GIL is always released
548548
when doing I/O.
549549

550-
Past efforts to create a "free-threaded" interpreter (one which locks
551-
shared data at a much finer granularity) have not been successful
552-
because performance suffered in the common single-processor case. It
553-
is believed that overcoming this performance issue would make the
554-
implementation much more complicated and therefore costlier to maintain.
555-
550+
As of Python 3.13, the GIL can be disabled using the :option:`--disable-gil`
551+
build configuration. After building Python with this option, code must be
552+
run with :option:`-X gil 0 <-X>` or after setting the :envvar:`PYTHON_GIL=0 <PYTHON_GIL>`
553+
environment variable. This feature enables improved performance for
554+
multi-threaded applications and makes it easier to use multi-core CPUs
555+
efficiently. For more details, see :pep:`703`.
556556

557557
hash-based pyc
558558
A bytecode cache file that uses the hash rather than the last-modified

Doc/library/asyncio-stream.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ StreamReader
260260
buffer is reset. The :attr:`IncompleteReadError.partial` attribute
261261
may contain a portion of the separator.
262262

263-
The *separator* may also be an :term:`iterable` of separators. In this
263+
The *separator* may also be a tuple of separators. In this
264264
case the return value will be the shortest possible that has any
265265
separator as the suffix. For the purposes of :exc:`LimitOverrunError`,
266266
the shortest possible separator is considered to be the one that
@@ -270,7 +270,7 @@ StreamReader
270270

271271
.. versionchanged:: 3.13
272272

273-
The *separator* parameter may now be an :term:`iterable` of
273+
The *separator* parameter may now be a :class:`tuple` of
274274
separators.
275275

276276
.. method:: at_eof()

Doc/library/decimal.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1517,7 +1517,7 @@ are also included in the pure Python version for compatibility.
15171517
the C version uses a thread-local rather than a coroutine-local context and the value
15181518
is ``False``. This is slightly faster in some nested context scenarios.
15191519

1520-
.. versionadded:: 3.8.3
1520+
.. versionadded:: 3.8.3
15211521

15221522

15231523
Rounding modes

Doc/library/glob.rst

+8
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ The :mod:`glob` module defines the following functions:
7575
Using the "``**``" pattern in large directory trees may consume
7676
an inordinate amount of time.
7777

78+
.. note::
79+
This function may return duplicate path names if *pathname*
80+
contains multiple "``**``" patterns and *recursive* is true.
81+
7882
.. versionchanged:: 3.5
7983
Support for recursive globs using "``**``".
8084

@@ -94,6 +98,10 @@ The :mod:`glob` module defines the following functions:
9498
.. audit-event:: glob.glob pathname,recursive glob.iglob
9599
.. audit-event:: glob.glob/2 pathname,recursive,root_dir,dir_fd glob.iglob
96100

101+
.. note::
102+
This function may return duplicate path names if *pathname*
103+
contains multiple "``**``" patterns and *recursive* is true.
104+
97105
.. versionchanged:: 3.5
98106
Support for recursive globs using "``**``".
99107

Doc/library/ipaddress.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -334,14 +334,14 @@ write code that handles both IP versions correctly. Address objects are
334334
.. attribute:: is_multicast
335335
.. attribute:: is_private
336336
.. attribute:: is_global
337+
338+
.. versionadded:: 3.4
339+
337340
.. attribute:: is_unspecified
338341
.. attribute:: is_reserved
339342
.. attribute:: is_loopback
340343
.. attribute:: is_link_local
341344

342-
.. versionadded:: 3.4
343-
is_global
344-
345345
.. attribute:: is_site_local
346346

347347
``True`` if the address is reserved for site-local usage. Note that

Doc/library/platform.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ Windows Platform
219219
default to an empty string).
220220

221221
As a hint: *ptype* is ``'Uniprocessor Free'`` on single processor NT machines
222-
and ``'Multiprocessor Free'`` on multi processor machines. The *'Free'* refers
223-
to the OS version being free of debugging code. It could also state *'Checked'*
222+
and ``'Multiprocessor Free'`` on multi processor machines. The ``'Free'`` refers
223+
to the OS version being free of debugging code. It could also state ``'Checked'``
224224
which means the OS version uses debugging code, i.e. code that checks arguments,
225225
ranges, etc.
226226

Doc/library/ssl.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1820,7 +1820,7 @@ to speed up repeated connections from the same clients.
18201820
.. versionchanged:: 3.6
18211821
*session* argument was added.
18221822

1823-
.. versionchanged:: 3.7
1823+
.. versionchanged:: 3.7
18241824
The method returns an instance of :attr:`SSLContext.sslsocket_class`
18251825
instead of hard-coded :class:`SSLSocket`.
18261826

Doc/library/urllib.request.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ The :mod:`urllib.request` module defines the following functions:
113113
``http/1.1`` when no *context* is given. Custom *context* should set
114114
ALPN protocols with :meth:`~ssl.SSLContext.set_alpn_protocols`.
115115

116-
.. versionchanged:: 3.13
117-
Remove *cafile*, *capath* and *cadefault* parameters: use the *context*
118-
parameter instead.
116+
.. versionchanged:: 3.13
117+
Remove *cafile*, *capath* and *cadefault* parameters: use the *context*
118+
parameter instead.
119119

120120

121121
.. function:: install_opener(opener)

Doc/library/xml.etree.elementtree.rst

+15-20
Original file line numberDiff line numberDiff line change
@@ -840,33 +840,28 @@ Functions
840840

841841
.. module:: xml.etree.ElementInclude
842842

843-
.. function:: xml.etree.ElementInclude.default_loader( href, parse, encoding=None)
844-
:module:
843+
.. function:: default_loader(href, parse, encoding=None)
845844

846-
Default loader. This default loader reads an included resource from disk. *href* is a URL.
847-
*parse* is for parse mode either "xml" or "text". *encoding*
848-
is an optional text encoding. If not given, encoding is ``utf-8``. Returns the
849-
expanded resource. If the parse mode is ``"xml"``, this is an ElementTree
850-
instance. If the parse mode is "text", this is a Unicode string. If the
851-
loader fails, it can return None or raise an exception.
845+
Default loader. This default loader reads an included resource from disk.
846+
*href* is a URL. *parse* is for parse mode either "xml" or "text".
847+
*encoding* is an optional text encoding. If not given, encoding is ``utf-8``.
848+
Returns the expanded resource.
849+
If the parse mode is ``"xml"``, this is an :class:`~xml.etree.ElementTree.Element` instance.
850+
If the parse mode is ``"text"``, this is a string.
851+
If the loader fails, it can return ``None`` or raise an exception.
852852

853853

854-
.. function:: xml.etree.ElementInclude.include( elem, loader=None, base_url=None, \
855-
max_depth=6)
856-
:module:
854+
.. function:: include(elem, loader=None, base_url=None, max_depth=6)
857855

858-
This function expands XInclude directives. *elem* is the root element. *loader* is
859-
an optional resource loader. If omitted, it defaults to :func:`default_loader`.
856+
This function expands XInclude directives in-place in tree pointed by *elem*.
857+
*elem* is either the root :class:`~xml.etree.ElementTree.Element` or an
858+
:class:`~xml.etree.ElementTree.ElementTree` instance to find such element.
859+
*loader* is an optional resource loader. If omitted, it defaults to :func:`default_loader`.
860860
If given, it should be a callable that implements the same interface as
861861
:func:`default_loader`. *base_url* is base URL of the original file, to resolve
862862
relative include file references. *max_depth* is the maximum number of recursive
863-
inclusions. Limited to reduce the risk of malicious content explosion. Pass a
864-
negative value to disable the limitation.
865-
866-
Returns the expanded resource. If the parse mode is
867-
``"xml"``, this is an ElementTree instance. If the parse mode is "text",
868-
this is a Unicode string. If the loader fails, it can return None or
869-
raise an exception.
863+
inclusions. Limited to reduce the risk of malicious content explosion.
864+
Pass ``None`` to disable the limitation.
870865

871866
.. versionchanged:: 3.9
872867
Added the *base_url* and *max_depth* parameters.

Doc/whatsnew/3.13.rst

+4
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,10 @@ asyncio
324324
:exc:`asyncio.QueueShutDown`) for queue termination.
325325
(Contributed by Laurie Opperman and Yves Duprat in :gh:`104228`.)
326326

327+
* Accept a tuple of separators in :meth:`asyncio.StreamReader.readuntil`,
328+
stopping when one of them is encountered.
329+
(Contributed by Bruce Merry in :gh:`81322`.)
330+
327331
base64
328332
------
329333

Include/Python.h

+5
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@
4545
# endif
4646
#endif
4747

48+
// gh-111506: The free-threaded build is not compatible with the limited API
49+
// or the stable ABI.
50+
#if defined(Py_LIMITED_API) && defined(Py_GIL_DISABLED)
51+
# error "The limited API is not currently supported in the free-threaded build"
52+
#endif
4853

4954
// Include Python header files
5055
#include "pyport.h"

Include/cpython/pylifecycle.h

+10-1
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,23 @@ typedef struct {
6363
.gil = PyInterpreterConfig_OWN_GIL, \
6464
}
6565

66+
// gh-117649: The free-threaded build does not currently support single-phase
67+
// init extensions in subinterpreters. For now, we ensure that
68+
// `check_multi_interp_extensions` is always `1`, even in the legacy config.
69+
#ifdef Py_GIL_DISABLED
70+
# define _PyInterpreterConfig_LEGACY_CHECK_MULTI_INTERP_EXTENSIONS 1
71+
#else
72+
# define _PyInterpreterConfig_LEGACY_CHECK_MULTI_INTERP_EXTENSIONS 0
73+
#endif
74+
6675
#define _PyInterpreterConfig_LEGACY_INIT \
6776
{ \
6877
.use_main_obmalloc = 1, \
6978
.allow_fork = 1, \
7079
.allow_exec = 1, \
7180
.allow_threads = 1, \
7281
.allow_daemon_threads = 1, \
73-
.check_multi_interp_extensions = 0, \
82+
.check_multi_interp_extensions = _PyInterpreterConfig_LEGACY_CHECK_MULTI_INTERP_EXTENSIONS, \
7483
.gil = PyInterpreterConfig_SHARED_GIL, \
7584
}
7685

Include/internal/pycore_bytes_methods.h

+10-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,16 @@ extern void _Py_bytes_title(char *result, const char *s, Py_ssize_t len);
2626
extern void _Py_bytes_capitalize(char *result, const char *s, Py_ssize_t len);
2727
extern void _Py_bytes_swapcase(char *result, const char *s, Py_ssize_t len);
2828

29-
extern PyObject *_Py_bytes_find(const char *str, Py_ssize_t len, PyObject *args);
30-
extern PyObject *_Py_bytes_index(const char *str, Py_ssize_t len, PyObject *args);
31-
extern PyObject *_Py_bytes_rfind(const char *str, Py_ssize_t len, PyObject *args);
32-
extern PyObject *_Py_bytes_rindex(const char *str, Py_ssize_t len, PyObject *args);
33-
extern PyObject *_Py_bytes_count(const char *str, Py_ssize_t len, PyObject *args);
29+
extern PyObject *_Py_bytes_find(const char *str, Py_ssize_t len, PyObject *sub,
30+
Py_ssize_t start, Py_ssize_t end);
31+
extern PyObject *_Py_bytes_index(const char *str, Py_ssize_t len, PyObject *sub,
32+
Py_ssize_t start, Py_ssize_t end);
33+
extern PyObject *_Py_bytes_rfind(const char *str, Py_ssize_t len, PyObject *sub,
34+
Py_ssize_t start, Py_ssize_t end);
35+
extern PyObject *_Py_bytes_rindex(const char *str, Py_ssize_t len, PyObject *sub,
36+
Py_ssize_t start, Py_ssize_t end);
37+
extern PyObject *_Py_bytes_count(const char *str, Py_ssize_t len, PyObject *sub,
38+
Py_ssize_t start, Py_ssize_t end);
3439
extern int _Py_bytes_contains(const char *str, Py_ssize_t len, PyObject *arg);
3540
extern PyObject *_Py_bytes_startswith(const char *str, Py_ssize_t len,
3641
PyObject *subobj, Py_ssize_t start,

Include/internal/pycore_crossinterp.h

+21
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,11 @@ typedef struct _excinfo {
217217
const char *errdisplay;
218218
} _PyXI_excinfo;
219219

220+
PyAPI_FUNC(int) _PyXI_InitExcInfo(_PyXI_excinfo *info, PyObject *exc);
221+
PyAPI_FUNC(PyObject *) _PyXI_FormatExcInfo(_PyXI_excinfo *info);
222+
PyAPI_FUNC(PyObject *) _PyXI_ExcInfoAsObject(_PyXI_excinfo *info);
223+
PyAPI_FUNC(void) _PyXI_ClearExcInfo(_PyXI_excinfo *info);
224+
220225

221226
typedef enum error_code {
222227
_PyXI_ERR_NO_ERROR = 0,
@@ -313,6 +318,22 @@ PyAPI_FUNC(PyObject *) _PyXI_ApplyCapturedException(_PyXI_session *session);
313318
PyAPI_FUNC(int) _PyXI_HasCapturedException(_PyXI_session *session);
314319

315320

321+
/*************/
322+
/* other API */
323+
/*************/
324+
325+
// Export for _testinternalcapi shared extension
326+
PyAPI_FUNC(PyInterpreterState *) _PyXI_NewInterpreter(
327+
PyInterpreterConfig *config,
328+
long *maybe_whence,
329+
PyThreadState **p_tstate,
330+
PyThreadState **p_save_tstate);
331+
PyAPI_FUNC(void) _PyXI_EndInterpreter(
332+
PyInterpreterState *interp,
333+
PyThreadState *tstate,
334+
PyThreadState **p_save_tstate);
335+
336+
316337
#ifdef __cplusplus
317338
}
318339
#endif

Include/internal/pycore_gc.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ static inline PyObject* _Py_FROM_GC(PyGC_Head *gc) {
3939

4040
/* Bit flags for ob_gc_bits (in Py_GIL_DISABLED builds) */
4141
#ifdef Py_GIL_DISABLED
42-
# define _PyGC_BITS_TRACKED (1)
43-
# define _PyGC_BITS_FINALIZED (2)
42+
# define _PyGC_BITS_TRACKED (1) // Tracked by the GC
43+
# define _PyGC_BITS_FINALIZED (2) // tp_finalize was called
4444
# define _PyGC_BITS_UNREACHABLE (4)
4545
# define _PyGC_BITS_FROZEN (8)
4646
# define _PyGC_BITS_SHARED (16)
4747
# define _PyGC_BITS_SHARED_INLINE (32)
48+
# define _PyGC_BITS_DEFERRED (64) // Use deferred reference counting
4849
#endif
4950

5051
/* True if the object is currently tracked by the GC. */

Include/internal/pycore_global_objects_fini_generated.h

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_global_strings.h

+1
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,7 @@ struct _Py_global_strings {
764764
STRUCT_FOR_ID(version)
765765
STRUCT_FOR_ID(volume)
766766
STRUCT_FOR_ID(wait_all)
767+
STRUCT_FOR_ID(warn_on_full_buffer)
767768
STRUCT_FOR_ID(warnings)
768769
STRUCT_FOR_ID(warnoptions)
769770
STRUCT_FOR_ID(wbits)

Include/internal/pycore_interp.h

+19
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,23 @@ struct _is {
103103
int requires_idref;
104104
PyThread_type_lock id_mutex;
105105

106+
#define _PyInterpreterState_WHENCE_NOTSET -1
107+
#define _PyInterpreterState_WHENCE_UNKNOWN 0
108+
#define _PyInterpreterState_WHENCE_RUNTIME 1
109+
#define _PyInterpreterState_WHENCE_LEGACY_CAPI 2
110+
#define _PyInterpreterState_WHENCE_CAPI 3
111+
#define _PyInterpreterState_WHENCE_XI 4
112+
#define _PyInterpreterState_WHENCE_STDLIB 5
113+
#define _PyInterpreterState_WHENCE_MAX 5
114+
long _whence;
115+
106116
/* Has been initialized to a safe state.
107117
108118
In order to be effective, this must be set to 0 during or right
109119
after allocation. */
110120
int _initialized;
121+
/* Has been fully initialized via pylifecycle.c. */
122+
int _ready;
111123
int finalizing;
112124

113125
uintptr_t last_restart_version;
@@ -305,6 +317,13 @@ PyAPI_FUNC(int) _PyInterpreterState_IDInitref(PyInterpreterState *);
305317
PyAPI_FUNC(int) _PyInterpreterState_IDIncref(PyInterpreterState *);
306318
PyAPI_FUNC(void) _PyInterpreterState_IDDecref(PyInterpreterState *);
307319

320+
PyAPI_FUNC(int) _PyInterpreterState_IsReady(PyInterpreterState *interp);
321+
322+
PyAPI_FUNC(long) _PyInterpreterState_GetWhence(PyInterpreterState *interp);
323+
extern void _PyInterpreterState_SetWhence(
324+
PyInterpreterState *interp,
325+
long whence);
326+
308327
extern const PyConfig* _PyInterpreterState_GetConfig(PyInterpreterState *interp);
309328

310329
// Get a copy of the current interpreter configuration.

Include/internal/pycore_object.h

+15
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,21 @@ static inline void _Py_ClearImmortal(PyObject *op)
158158
op = NULL; \
159159
} while (0)
160160

161+
// Mark an object as supporting deferred reference counting. This is a no-op
162+
// in the default (with GIL) build. Objects that use deferred reference
163+
// counting should be tracked by the GC so that they are eventually collected.
164+
extern void _PyObject_SetDeferredRefcount(PyObject *op);
165+
166+
static inline int
167+
_PyObject_HasDeferredRefcount(PyObject *op)
168+
{
169+
#ifdef Py_GIL_DISABLED
170+
return (op->ob_gc_bits & _PyGC_BITS_DEFERRED) != 0;
171+
#else
172+
return 0;
173+
#endif
174+
}
175+
161176
#if !defined(Py_GIL_DISABLED)
162177
static inline void
163178
_Py_DECREF_SPECIALIZED(PyObject *op, const destructor destruct)

Include/internal/pycore_pystate.h

+3
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ _Py_IsMainInterpreterFinalizing(PyInterpreterState *interp)
7777
interp == &_PyRuntime._main_interpreter);
7878
}
7979

80+
// Export for _xxsubinterpreters module.
81+
PyAPI_FUNC(PyObject *) _PyInterpreterState_GetIDObject(PyInterpreterState *);
82+
8083
// Export for _xxsubinterpreters module.
8184
PyAPI_FUNC(int) _PyInterpreterState_SetRunningMain(PyInterpreterState *);
8285
PyAPI_FUNC(void) _PyInterpreterState_SetNotRunningMain(PyInterpreterState *);

Include/internal/pycore_runtime_init.h

+1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ extern PyTypeObject _PyExc_MemoryError;
162162
#define _PyInterpreterState_INIT(INTERP) \
163163
{ \
164164
.id_refcount = -1, \
165+
._whence = _PyInterpreterState_WHENCE_NOTSET, \
165166
.imports = IMPORTS_INIT, \
166167
.ceval = { \
167168
.recursion_limit = Py_DEFAULT_RECURSION_LIMIT, \

Include/internal/pycore_runtime_init_generated.h

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)