Skip to content

Commit b25685e

Browse files
authored
Merge branch 'main' into libexpat-2.6.0
2 parents a9b3f45 + 57e4c81 commit b25685e

36 files changed

+1097
-947
lines changed

Doc/conf.py

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666

6767
rst_epilog = f"""
6868
.. |python_version_literal| replace:: ``Python {version}``
69+
.. |python_x_dot_y_literal| replace:: ``python{version}``
70+
.. |usr_local_bin_python_x_dot_y_literal| replace:: ``/usr/local/bin/python{version}``
6971
"""
7072

7173
# There are two options for replacing |today|: either, you set today to some

Doc/library/ftplib.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ FTP objects
104104
:param timeout:
105105
A timeout in seconds for blocking operations like :meth:`connect`
106106
(default: the global default timeout setting).
107-
:type timeout: int | None
107+
:type timeout: float | None
108108

109109
:param source_address:
110110
|param_doc_source_address|
@@ -178,7 +178,7 @@ FTP objects
178178
:param timeout:
179179
A timeout in seconds for the connection attempt
180180
(default: the global default timeout setting).
181-
:type timeout: int | None
181+
:type timeout: float | None
182182

183183
:param source_address:
184184
|param_doc_source_address|
@@ -483,7 +483,7 @@ FTP_TLS objects
483483
:param timeout:
484484
A timeout in seconds for blocking operations like :meth:`~FTP.connect`
485485
(default: the global default timeout setting).
486-
:type timeout: int | None
486+
:type timeout: float | None
487487

488488
:param source_address:
489489
|param_doc_source_address|

Doc/tutorial/interpreter.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Using the Python Interpreter
1010
Invoking the Interpreter
1111
========================
1212

13-
The Python interpreter is usually installed as :file:`/usr/local/bin/python3.13`
13+
The Python interpreter is usually installed as |usr_local_bin_python_x_dot_y_literal|
1414
on those machines where it is available; putting :file:`/usr/local/bin` in your
1515
Unix shell's search path makes it possible to start it by typing the command:
1616

@@ -24,7 +24,7 @@ Python guru or system administrator. (E.g., :file:`/usr/local/python` is a
2424
popular alternative location.)
2525

2626
On Windows machines where you have installed Python from the :ref:`Microsoft Store
27-
<windows-store>`, the :file:`python3.13` command will be available. If you have
27+
<windows-store>`, the |python_x_dot_y_literal| command will be available. If you have
2828
the :ref:`py.exe launcher <launcher>` installed, you can use the :file:`py`
2929
command. See :ref:`setting-envvars` for other ways to launch Python.
3030

Doc/tutorial/stdlib.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ operating system::
1515

1616
>>> import os
1717
>>> os.getcwd() # Return the current working directory
18-
'C:\\Python312'
18+
'C:\\Python313'
1919
>>> os.chdir('/server/accesslogs') # Change current working directory
2020
>>> os.system('mkdir today') # Run the command mkdir in the system shell
2121
0

Doc/tutorial/stdlib2.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ applications include caching objects that are expensive to create::
279279
Traceback (most recent call last):
280280
File "<stdin>", line 1, in <module>
281281
d['primary'] # entry was automatically removed
282-
File "C:/python312/lib/weakref.py", line 46, in __getitem__
282+
File "C:/python313/lib/weakref.py", line 46, in __getitem__
283283
o = self.data[key]()
284284
KeyError: 'primary'
285285

Include/internal/pycore_code.h

+9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ extern "C" {
88
# error "this header requires Py_BUILD_CORE define"
99
#endif
1010

11+
12+
// We hide some of the newer PyCodeObject fields behind macros.
13+
// This helps with backporting certain changes to 3.12.
14+
#define _PyCode_HAS_EXECUTORS(CODE) \
15+
(CODE->co_executors != NULL)
16+
#define _PyCode_HAS_INSTRUMENTATION(CODE) \
17+
(CODE->_co_instrumentation_version > 0)
18+
19+
1120
#define CODE_MAX_WATCHERS 8
1221

1322
/* PEP 659

Include/internal/pycore_crossinterp.h

+26
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ struct _xid {
8787
PyAPI_FUNC(_PyCrossInterpreterData *) _PyCrossInterpreterData_New(void);
8888
PyAPI_FUNC(void) _PyCrossInterpreterData_Free(_PyCrossInterpreterData *data);
8989

90+
#define _PyCrossInterpreterData_DATA(DATA) ((DATA)->data)
91+
#define _PyCrossInterpreterData_OBJ(DATA) ((DATA)->obj)
92+
#define _PyCrossInterpreterData_INTERPID(DATA) ((DATA)->interpid)
93+
// Users should not need getters for "new_object" or "free".
94+
9095

9196
/* defining cross-interpreter data */
9297

@@ -101,6 +106,25 @@ PyAPI_FUNC(int) _PyCrossInterpreterData_InitWithSize(
101106
PyAPI_FUNC(void) _PyCrossInterpreterData_Clear(
102107
PyInterpreterState *, _PyCrossInterpreterData *);
103108

109+
// Normally the Init* functions are sufficient. The only time
110+
// additional initialization might be needed is to set the "free" func,
111+
// though that should be infrequent.
112+
#define _PyCrossInterpreterData_SET_FREE(DATA, FUNC) \
113+
do { \
114+
(DATA)->free = (FUNC); \
115+
} while (0)
116+
// Additionally, some shareable types are essentially light wrappers
117+
// around other shareable types. The crossinterpdatafunc of the wrapper
118+
// can often be implemented by calling the wrapped object's
119+
// crossinterpdatafunc and then changing the "new_object" function.
120+
// We have _PyCrossInterpreterData_SET_NEW_OBJECT() here for that,
121+
// but might be better to have a function like
122+
// _PyCrossInterpreterData_AdaptToWrapper() instead.
123+
#define _PyCrossInterpreterData_SET_NEW_OBJECT(DATA, FUNC) \
124+
do { \
125+
(DATA)->new_object = (FUNC); \
126+
} while (0)
127+
104128

105129
/* using cross-interpreter data */
106130

@@ -170,6 +194,8 @@ extern void _PyXI_Fini(PyInterpreterState *interp);
170194
extern PyStatus _PyXI_InitTypes(PyInterpreterState *interp);
171195
extern void _PyXI_FiniTypes(PyInterpreterState *interp);
172196

197+
#define _PyInterpreterState_GetXIState(interp) (&(interp)->xi)
198+
173199

174200
/***************************/
175201
/* short-term data sharing */

Include/internal/pycore_dict.h

-6
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,6 @@ typedef struct {
6767
extern PyObject* _PyDictView_New(PyObject *, PyTypeObject *);
6868
extern PyObject* _PyDictView_Intersect(PyObject* self, PyObject *other);
6969

70-
71-
/* runtime lifecycle */
72-
73-
extern void _PyDict_Fini(PyInterpreterState *state);
74-
75-
7670
/* other API */
7771

7872
typedef struct {

Include/internal/pycore_freelist.h

+26-26
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ extern "C" {
3333
# define _PyObjectStackChunk_MAXFREELIST 0
3434
#endif
3535

36-
struct _Py_list_state {
36+
struct _Py_list_freelist {
3737
#ifdef WITH_FREELISTS
3838
PyListObject *free_list[PyList_MAXFREELIST];
3939
int numfree;
4040
#endif
4141
};
4242

43-
struct _Py_tuple_state {
43+
struct _Py_tuple_freelist {
4444
#if WITH_FREELISTS
4545
/* There is one freelist for each size from 1 to PyTuple_MAXSAVESIZE.
4646
The empty tuple is handled separately.
@@ -57,7 +57,7 @@ struct _Py_tuple_state {
5757
#endif
5858
};
5959

60-
struct _Py_float_state {
60+
struct _Py_float_freelist {
6161
#ifdef WITH_FREELISTS
6262
/* Special free list
6363
free_list is a singly-linked list of available PyFloatObjects,
@@ -77,23 +77,23 @@ struct _Py_dict_freelist {
7777
#endif
7878
};
7979

80-
struct _Py_slice_state {
80+
struct _Py_slice_freelist {
8181
#ifdef WITH_FREELISTS
8282
/* Using a cache is very effective since typically only a single slice is
8383
created and then deleted again. */
8484
PySliceObject *slice_cache;
8585
#endif
8686
};
8787

88-
struct _Py_context_state {
88+
struct _Py_context_freelist {
8989
#ifdef WITH_FREELISTS
9090
// List of free PyContext objects
9191
PyContext *freelist;
9292
int numfree;
9393
#endif
9494
};
9595

96-
struct _Py_async_gen_state {
96+
struct _Py_async_gen_freelist {
9797
#ifdef WITH_FREELISTS
9898
/* Freelists boost performance 6-10%; they also reduce memory
9999
fragmentation, as _PyAsyncGenWrappedValue and PyAsyncGenASend
@@ -109,31 +109,31 @@ struct _Py_async_gen_state {
109109

110110
struct _PyObjectStackChunk;
111111

112-
struct _Py_object_stack_state {
112+
struct _Py_object_stack_freelist {
113113
struct _PyObjectStackChunk *free_list;
114114
Py_ssize_t numfree;
115115
};
116116

117-
typedef struct _Py_freelist_state {
118-
struct _Py_float_state floats;
119-
struct _Py_tuple_state tuples;
120-
struct _Py_list_state lists;
117+
struct _Py_object_freelists {
118+
struct _Py_float_freelist floats;
119+
struct _Py_tuple_freelist tuples;
120+
struct _Py_list_freelist lists;
121121
struct _Py_dict_freelist dicts;
122-
struct _Py_slice_state slices;
123-
struct _Py_context_state contexts;
124-
struct _Py_async_gen_state async_gens;
125-
struct _Py_object_stack_state object_stacks;
126-
} _PyFreeListState;
127-
128-
extern void _PyObject_ClearFreeLists(_PyFreeListState *state, int is_finalization);
129-
extern void _PyTuple_ClearFreeList(_PyFreeListState *state, int is_finalization);
130-
extern void _PyFloat_ClearFreeList(_PyFreeListState *state, int is_finalization);
131-
extern void _PyList_ClearFreeList(_PyFreeListState *state, int is_finalization);
132-
extern void _PySlice_ClearFreeList(_PyFreeListState *state, int is_finalization);
133-
extern void _PyDict_ClearFreeList(_PyFreeListState *state, int is_finalization);
134-
extern void _PyAsyncGen_ClearFreeLists(_PyFreeListState *state, int is_finalization);
135-
extern void _PyContext_ClearFreeList(_PyFreeListState *state, int is_finalization);
136-
extern void _PyObjectStackChunk_ClearFreeList(_PyFreeListState *state, int is_finalization);
122+
struct _Py_slice_freelist slices;
123+
struct _Py_context_freelist contexts;
124+
struct _Py_async_gen_freelist async_gens;
125+
struct _Py_object_stack_freelist object_stacks;
126+
};
127+
128+
extern void _PyObject_ClearFreeLists(struct _Py_object_freelists *freelists, int is_finalization);
129+
extern void _PyTuple_ClearFreeList(struct _Py_object_freelists *freelists, int is_finalization);
130+
extern void _PyFloat_ClearFreeList(struct _Py_object_freelists *freelists, int is_finalization);
131+
extern void _PyList_ClearFreeList(struct _Py_object_freelists *freelists, int is_finalization);
132+
extern void _PySlice_ClearFreeList(struct _Py_object_freelists *freelists, int is_finalization);
133+
extern void _PyDict_ClearFreeList(struct _Py_object_freelists *freelists, int is_finalization);
134+
extern void _PyAsyncGen_ClearFreeLists(struct _Py_object_freelists *freelists, int is_finalization);
135+
extern void _PyContext_ClearFreeList(struct _Py_object_freelists *freelists, int is_finalization);
136+
extern void _PyObjectStackChunk_ClearFreeList(struct _Py_object_freelists *freelists, int is_finalization);
137137

138138
#ifdef __cplusplus
139139
}

Include/internal/pycore_interp.h

-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ extern "C" {
2020
#include "pycore_dtoa.h" // struct _dtoa_state
2121
#include "pycore_exceptions.h" // struct _Py_exc_state
2222
#include "pycore_floatobject.h" // struct _Py_float_state
23-
#include "pycore_freelist.h" // struct _Py_freelist_state
2423
#include "pycore_function.h" // FUNC_MAX_WATCHERS
2524
#include "pycore_gc.h" // struct _gc_runtime_state
2625
#include "pycore_genobject.h" // struct _Py_async_gen_state
@@ -222,9 +221,6 @@ struct _is {
222221
// One bit is set for each non-NULL entry in code_watchers
223222
uint8_t active_code_watchers;
224223

225-
#if !defined(Py_GIL_DISABLED)
226-
struct _Py_freelist_state freelist_state;
227-
#endif
228224
struct _py_object_state object_state;
229225
struct _Py_unicode_state unicode;
230226
struct _Py_long_state long_state;

Include/internal/pycore_object_state.h

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ extern "C" {
88
# error "this header requires Py_BUILD_CORE define"
99
#endif
1010

11+
#include "pycore_freelist.h" // _PyObject_freelists
1112
#include "pycore_hashtable.h" // _Py_hashtable_t
1213

1314
struct _py_object_runtime_state {
@@ -18,6 +19,9 @@ struct _py_object_runtime_state {
1819
};
1920

2021
struct _py_object_state {
22+
#if !defined(Py_GIL_DISABLED)
23+
struct _Py_object_freelists freelists;
24+
#endif
2125
#ifdef Py_REF_DEBUG
2226
Py_ssize_t reftotal;
2327
#endif

Include/internal/pycore_pystate.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -268,17 +268,17 @@ PyAPI_FUNC(const PyConfig*) _Py_GetConfig(void);
268268
// See also PyInterpreterState_Get() and _PyInterpreterState_GET().
269269
extern PyInterpreterState* _PyGILState_GetInterpreterStateUnsafe(void);
270270

271-
static inline _PyFreeListState* _PyFreeListState_GET(void)
271+
static inline struct _Py_object_freelists* _Py_object_freelists_GET(void)
272272
{
273273
PyThreadState *tstate = _PyThreadState_GET();
274274
#ifdef Py_DEBUG
275275
_Py_EnsureTstateNotNULL(tstate);
276276
#endif
277277

278278
#ifdef Py_GIL_DISABLED
279-
return &((_PyThreadStateImpl*)tstate)->freelist_state;
279+
return &((_PyThreadStateImpl*)tstate)->freelists;
280280
#else
281-
return &tstate->interp->freelist_state;
281+
return &tstate->interp->object_state.freelists;
282282
#endif
283283
}
284284

Include/internal/pycore_tstate.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ extern "C" {
1313
#include "pycore_brc.h" // struct _brc_thread_state
1414

1515

16+
static inline void
17+
_PyThreadState_SetWhence(PyThreadState *tstate, int whence)
18+
{
19+
tstate->_whence = whence;
20+
}
21+
22+
1623
// Every PyThreadState is actually allocated as a _PyThreadStateImpl. The
1724
// PyThreadState fields are exposed as part of the C API, although most fields
1825
// are intended to be private. The _PyThreadStateImpl fields not exposed.
@@ -22,7 +29,7 @@ typedef struct _PyThreadStateImpl {
2229

2330
#ifdef Py_GIL_DISABLED
2431
struct _mimalloc_thread_state mimalloc;
25-
struct _Py_freelist_state freelist_state;
32+
struct _Py_object_freelists freelists;
2633
struct _brc_thread_state brc;
2734
#endif
2835

0 commit comments

Comments
 (0)