Skip to content

Commit 73943cb

Browse files
committed
Merge the 3.12.0a2 release into main.
2 parents bd58b89 + f13f466 commit 73943cb

File tree

108 files changed

+3423
-3372
lines changed

Some content is hidden

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

108 files changed

+3423
-3372
lines changed

Doc/includes/custom2.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,12 @@ Custom_init(CustomObject *self, PyObject *args, PyObject *kwds)
5151

5252
if (first) {
5353
tmp = self->first;
54-
Py_INCREF(first);
55-
self->first = first;
54+
self->first = Py_NewRef(first);
5655
Py_XDECREF(tmp);
5756
}
5857
if (last) {
5958
tmp = self->last;
60-
Py_INCREF(last);
61-
self->last = last;
59+
self->last = Py_NewRef(last);
6260
Py_XDECREF(tmp);
6361
}
6462
return 0;
@@ -127,9 +125,7 @@ PyInit_custom2(void)
127125
if (m == NULL)
128126
return NULL;
129127

130-
Py_INCREF(&CustomType);
131-
if (PyModule_AddObject(m, "Custom", (PyObject *) &CustomType) < 0) {
132-
Py_DECREF(&CustomType);
128+
if (PyModule_AddObjectRef(m, "Custom", (PyObject *) &CustomType) < 0) {
133129
Py_DECREF(m);
134130
return NULL;
135131
}

Doc/includes/custom3.c

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,12 @@ Custom_init(CustomObject *self, PyObject *args, PyObject *kwds)
5151

5252
if (first) {
5353
tmp = self->first;
54-
Py_INCREF(first);
55-
self->first = first;
54+
self->first = Py_NewRef(first);
5655
Py_DECREF(tmp);
5756
}
5857
if (last) {
5958
tmp = self->last;
60-
Py_INCREF(last);
61-
self->last = last;
59+
self->last = Py_NewRef(last);
6260
Py_DECREF(tmp);
6361
}
6462
return 0;
@@ -73,8 +71,7 @@ static PyMemberDef Custom_members[] = {
7371
static PyObject *
7472
Custom_getfirst(CustomObject *self, void *closure)
7573
{
76-
Py_INCREF(self->first);
77-
return self->first;
74+
return Py_NewRef(self->first);
7875
}
7976

8077
static int
@@ -91,17 +88,15 @@ Custom_setfirst(CustomObject *self, PyObject *value, void *closure)
9188
return -1;
9289
}
9390
tmp = self->first;
94-
Py_INCREF(value);
95-
self->first = value;
91+
self->first = Py_NewRef(value);
9692
Py_DECREF(tmp);
9793
return 0;
9894
}
9995

10096
static PyObject *
10197
Custom_getlast(CustomObject *self, void *closure)
10298
{
103-
Py_INCREF(self->last);
104-
return self->last;
99+
return Py_NewRef(self->last);
105100
}
106101

107102
static int
@@ -118,8 +113,7 @@ Custom_setlast(CustomObject *self, PyObject *value, void *closure)
118113
return -1;
119114
}
120115
tmp = self->last;
121-
Py_INCREF(value);
122-
self->last = value;
116+
self->last = Py_NewRef(value);
123117
Py_DECREF(tmp);
124118
return 0;
125119
}
@@ -178,9 +172,7 @@ PyInit_custom3(void)
178172
if (m == NULL)
179173
return NULL;
180174

181-
Py_INCREF(&CustomType);
182-
if (PyModule_AddObject(m, "Custom", (PyObject *) &CustomType) < 0) {
183-
Py_DECREF(&CustomType);
175+
if (PyModule_AddObjectRef(m, "Custom", (PyObject *) &CustomType) < 0) {
184176
Py_DECREF(m);
185177
return NULL;
186178
}

Doc/includes/custom4.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,12 @@ Custom_init(CustomObject *self, PyObject *args, PyObject *kwds)
6767

6868
if (first) {
6969
tmp = self->first;
70-
Py_INCREF(first);
71-
self->first = first;
70+
self->first = Py_NewRef(first);
7271
Py_DECREF(tmp);
7372
}
7473
if (last) {
7574
tmp = self->last;
76-
Py_INCREF(last);
77-
self->last = last;
75+
self->last = Py_NewRef(last);
7876
Py_DECREF(tmp);
7977
}
8078
return 0;
@@ -89,8 +87,7 @@ static PyMemberDef Custom_members[] = {
8987
static PyObject *
9088
Custom_getfirst(CustomObject *self, void *closure)
9189
{
92-
Py_INCREF(self->first);
93-
return self->first;
90+
return Py_NewRef(self->first);
9491
}
9592

9693
static int
@@ -114,8 +111,7 @@ Custom_setfirst(CustomObject *self, PyObject *value, void *closure)
114111
static PyObject *
115112
Custom_getlast(CustomObject *self, void *closure)
116113
{
117-
Py_INCREF(self->last);
118-
return self->last;
114+
return Py_NewRef(self->last);
119115
}
120116

121117
static int
@@ -192,9 +188,7 @@ PyInit_custom4(void)
192188
if (m == NULL)
193189
return NULL;
194190

195-
Py_INCREF(&CustomType);
196-
if (PyModule_AddObject(m, "Custom", (PyObject *) &CustomType) < 0) {
197-
Py_DECREF(&CustomType);
191+
if (PyModule_AddObjectRef(m, "Custom", (PyObject *) &CustomType) < 0) {
198192
Py_DECREF(m);
199193
return NULL;
200194
}

Doc/library/asyncio-runner.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ to simplify async code usage for common wide-spread scenarios.
2222
Running an asyncio Program
2323
==========================
2424

25-
.. function:: run(coro, *, debug=None)
25+
.. function:: run(coro, *, debug=None, loop_factory=None)
2626

2727
Execute the :term:`coroutine` *coro* and return the result.
2828

@@ -37,9 +37,11 @@ Running an asyncio Program
3737
debug mode explicitly. ``None`` is used to respect the global
3838
:ref:`asyncio-debug-mode` settings.
3939

40-
This function always creates a new event loop and closes it at
41-
the end. It should be used as a main entry point for asyncio
42-
programs, and should ideally only be called once.
40+
If *loop_factory* is not ``None``, it is used to create a new event loop;
41+
otherwise :func:`asyncio.new_event_loop` is used. The loop is closed at the end.
42+
This function should be used as a main entry point for asyncio programs,
43+
and should ideally only be called once. It is recommended to use
44+
*loop_factory* to configure the event loop instead of policies.
4345

4446
The executor is given a timeout duration of 5 minutes to shutdown.
4547
If the executor hasn't finished within that duration, a warning is
@@ -62,6 +64,10 @@ Running an asyncio Program
6264

6365
*debug* is ``None`` by default to respect the global debug mode settings.
6466

67+
.. versionchanged:: 3.12
68+
69+
Added *loop_factory* parameter.
70+
6571

6672
Runner context manager
6773
======================

Doc/using/configure.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,13 @@ Compiler flags
767767

768768
.. versionadded:: 3.5
769769

770+
.. envvar:: COMPILEALL_OPTS
771+
772+
Options passed to the :mod:`compileall` command line when building PYC files
773+
in ``make install``. Default: ``-j0``.
774+
775+
.. versionadded:: 3.12
776+
770777
.. envvar:: EXTRA_CFLAGS
771778

772779
Extra C compiler flags.

Doc/whatsnew/3.12.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,11 @@ asyncio
217217
and will be removed in Python 3.14.
218218
(Contributed by Kumar Aditya in :gh:`94597`.)
219219

220+
* Add *loop_factory* parameter to :func:`asyncio.run` to allow specifying
221+
a custom event loop factory.
222+
(Contributed by Kumar Aditya in :gh:`99388`.)
223+
224+
220225
pathlib
221226
-------
222227

@@ -675,6 +680,12 @@ Build Changes
675680
if the Clang compiler accepts the flag.
676681
(Contributed by Dong-hee Na in :gh:`89536`.)
677682

683+
* Add ``COMPILEALL_OPTS`` variable in Makefile to override :mod:`compileall`
684+
options (default: ``-j0``) in ``make install``. Also merged the 3
685+
``compileall`` commands into a single command to build .pyc files for all
686+
optimization levels (0, 1, 2) at once.
687+
(Contributed by Victor Stinner in :gh:`99289`.)
688+
678689

679690
C API Changes
680691
=============

Include/cpython/pystate.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,6 @@ struct _ts {
120120
after allocation. */
121121
int _initialized;
122122

123-
/* Was this thread state statically allocated? */
124-
int _static;
125-
126123
int py_recursion_remaining;
127124
int py_recursion_limit;
128125

Include/internal/pycore_compile.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ extern int _PyAST_Optimize(
4040
_PyASTOptimizeState *state);
4141

4242
/* Access compiler internals for unit testing */
43+
44+
PyAPI_FUNC(PyObject*) _PyCompile_CodeGen(
45+
PyObject *ast,
46+
PyObject *filename,
47+
PyCompilerFlags *flags,
48+
int optimize);
49+
4350
PyAPI_FUNC(PyObject*) _PyCompile_OptimizeCfg(
4451
PyObject *instructions,
4552
PyObject *consts);

Include/internal/pycore_global_objects.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ extern "C" {
1010

1111
#include "pycore_gc.h" // PyGC_Head
1212
#include "pycore_global_strings.h" // struct _Py_global_strings
13+
#include "pycore_typeobject.h" // pytype_slotdef
1314

1415

1516
// These would be in pycore_long.h if it weren't for an include cycle.
@@ -20,6 +21,13 @@ extern "C" {
2021
// Only immutable objects should be considered runtime-global.
2122
// All others must be per-interpreter.
2223

24+
#define _Py_CACHED_OBJECT(NAME) \
25+
_PyRuntime.cached_objects.NAME
26+
27+
struct _Py_cached_objects {
28+
PyObject *str_replace_inf;
29+
};
30+
2331
#define _Py_GLOBAL_OBJECT(NAME) \
2432
_PyRuntime.global_objects.NAME
2533
#define _Py_SINGLETON(NAME) \
@@ -54,6 +62,10 @@ struct _Py_global_objects {
5462

5563
struct _Py_interp_cached_objects {
5664
int _not_set;
65+
/* object.__reduce__ */
66+
PyObject *objreduce;
67+
PyObject *type_slots_pname;
68+
pytype_slotdef *type_slots_ptrs[MAX_EQUIV];
5769
};
5870

5971
#define _Py_INTERP_STATIC_OBJECT(interp, NAME) \

Include/internal/pycore_global_objects_fini_generated.h

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

Include/internal/pycore_global_strings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ struct _Py_global_strings {
267267
STRUCT_FOR_ID(arguments)
268268
STRUCT_FOR_ID(argv)
269269
STRUCT_FOR_ID(as_integer_ratio)
270+
STRUCT_FOR_ID(ast)
270271
STRUCT_FOR_ID(attribute)
271272
STRUCT_FOR_ID(authorizer_callback)
272273
STRUCT_FOR_ID(autocommit)

Include/internal/pycore_import.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ struct _import_runtime_state {
2121
This is initialized lazily in _PyImport_FixupExtensionObject().
2222
Modules are added there and looked up in _imp.find_extension(). */
2323
PyObject *extensions;
24+
/* The global import lock. */
25+
struct {
26+
PyThread_type_lock mutex;
27+
unsigned long thread;
28+
int level;
29+
} lock;
30+
struct {
31+
int import_level;
32+
_PyTime_t accumulated;
33+
int header;
34+
} find_and_load;
2435
};
2536

2637

Include/internal/pycore_interp.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,6 @@ struct _is {
116116
int _initialized;
117117
int finalizing;
118118

119-
/* Was this interpreter statically allocated? */
120-
bool _static;
121-
122119
struct _ceval_state ceval;
123120
struct _gc_runtime_state gc;
124121

Include/internal/pycore_runtime.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,15 @@ typedef struct pyruntimestate {
136136

137137
struct _Py_unicode_runtime_ids unicode_ids;
138138

139+
struct {
140+
/* Used to set PyTypeObject.tp_version_tag */
141+
// bpo-42745: next_version_tag remains shared by all interpreters
142+
// because of static types.
143+
unsigned int next_version_tag;
144+
} types;
145+
139146
/* All the objects that are shared by the runtime's interpreters. */
147+
struct _Py_cached_objects cached_objects;
140148
struct _Py_global_objects global_objects;
141149

142150
/* The following fields are here to avoid allocation during init.

Include/internal/pycore_runtime_init.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@ extern "C" {
3636
until _PyInterpreterState_Enable() is called. */ \
3737
.next_id = -1, \
3838
}, \
39+
.types = { \
40+
.next_version_tag = 1, \
41+
}, \
42+
.imports = { \
43+
.lock = { \
44+
.mutex = NULL, \
45+
.thread = PYTHREAD_INVALID_THREAD_ID, \
46+
.level = 0, \
47+
}, \
48+
.find_and_load = { \
49+
.header = 1, \
50+
}, \
51+
}, \
3952
.global_objects = { \
4053
.singletons = { \
4154
.small_ints = _Py_small_ints_INIT, \
@@ -70,7 +83,6 @@ extern "C" {
7083

7184
#define _PyInterpreterState_INIT \
7285
{ \
73-
._static = 1, \
7486
.id_refcount = -1, \
7587
DLOPENFLAGS_INIT \
7688
.ceval = { \
@@ -95,7 +107,6 @@ extern "C" {
95107

96108
#define _PyThreadState_INIT \
97109
{ \
98-
._static = 1, \
99110
.py_recursion_limit = Py_DEFAULT_RECURSION_LIMIT, \
100111
.context_ver = 1, \
101112
}

Include/internal/pycore_runtime_init_generated.h

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

Include/internal/pycore_typeobject.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ extern void _PyTypes_Fini(PyInterpreterState *);
1818

1919
/* other API */
2020

21+
/* Length of array of slotdef pointers used to store slots with the
22+
same __name__. There should be at most MAX_EQUIV-1 slotdef entries with
23+
the same __name__, for any __name__. Since that's a static property, it is
24+
appropriate to declare fixed-size arrays for this. */
25+
#define MAX_EQUIV 10
26+
27+
typedef struct wrapperbase pytype_slotdef;
28+
29+
2130
// Type attribute lookup cache: speed up attribute and method lookups,
2231
// see _PyType_Lookup().
2332
struct type_cache_entry {

0 commit comments

Comments
 (0)