Skip to content

Commit 7428b15

Browse files
committed
Merge remote-tracking branch 'upstream/main' into bpo-45292-except_star
2 parents 9c18862 + 7989e9d commit 7428b15

48 files changed

Lines changed: 812 additions & 1081 deletions

Some content is hidden

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

Doc/library/dis.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,12 +584,14 @@ iterations of the loop.
584584

585585
.. opcode:: WITH_EXCEPT_START
586586

587-
Calls the function in position 7 on the stack with the top three
587+
Calls the function in position 8 on the stack with the top three
588588
items on the stack as arguments.
589589
Used to implement the call ``context_manager.__exit__(*exc_info())`` when an exception
590590
has occurred in a :keyword:`with` statement.
591591

592592
.. versionadded:: 3.9
593+
.. versionchanged:: 3.11
594+
The ``__exit__`` function is in position 8 of the stack rather than 7.
593595

594596

595597
.. opcode:: POP_EXCEPT_AND_RERAISE

Doc/library/logging.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ is the module's name in the Python package namespace.
8181
of ancestor loggers.
8282

8383
Spelling it out with an example: If the propagate attribute of the logger named
84-
`A.B.C` evaluates to true, any event logged to `A.B.C` via a method call such as
85-
`logging.getLogger('A.B.C').error(...)` will [subject to passing that logger's
84+
``A.B.C`` evaluates to true, any event logged to ``A.B.C`` via a method call such as
85+
``logging.getLogger('A.B.C').error(...)`` will [subject to passing that logger's
8686
level and filter settings] be passed in turn to any handlers attached to loggers
87-
named `A.B`, `A` and the root logger, after first being passed to any handlers
88-
attached to `A.B.C`. If any logger in the chain `A.B.C`, `A.B`, `A` has its
89-
`propagate` attribute set to false, then that is the last logger whose handlers
87+
named ``A.B``, ``A`` and the root logger, after first being passed to any handlers
88+
attached to ``A.B.C``. If any logger in the chain ``A.B.C``, ``A.B``, ``A`` has its
89+
``propagate`` attribute set to false, then that is the last logger whose handlers
9090
are offered the event to handle, and propagation stops at that point.
9191

9292
The constructor sets this attribute to ``True``.

Doc/reference/datamodel.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,7 +1823,7 @@ Class Binding
18231823

18241824
Super Binding
18251825
A dotted lookup such as ``super(A, a).x`` searches
1826-
``obj.__class__.__mro__`` for a base class ``B`` following ``A`` and then
1826+
``a.__class__.__mro__`` for a base class ``B`` following ``A`` and then
18271827
returns ``B.__dict__['x'].__get__(a, A)``. If not a descriptor, ``x`` is
18281828
returned unchanged.
18291829

@@ -1843,15 +1843,19 @@ Super Binding
18431843
x = 999
18441844

18451845
def m(self):
1846-
'Demonstrate these two calls are equivalent'
1847-
result1 = super(A, a).x
1848-
result2 = B.__dict__['x'].__get__(a, A)
1846+
'Demonstrate these two descriptor invocations are equivalent'
1847+
result1 = super(A, self).x
1848+
result2 = B.__dict__['x'].__get__(self, A)
18491849
return result1 == result2
18501850

18511851
.. doctest::
18521852
:hide:
18531853

18541854
>>> a = A()
1855+
>>> a.__class__.__mro__.index(B) > a.__class__.__mro__.index(A)
1856+
True
1857+
>>> super(A, a).x == B.__dict__['x'].__get__(a, A)
1858+
True
18551859
>>> a.m()
18561860
True
18571861

Include/cpython/object.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,6 @@ struct _typeobject {
270270

271271
destructor tp_finalize;
272272
vectorcallfunc tp_vectorcall;
273-
Py_ssize_t tp_inline_values_offset;
274273
};
275274

276275
/* The *real* layout of a type object when allocated on the heap */

Include/cpython/objimpl.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,6 @@ PyAPI_FUNC(int) PyObject_IS_GC(PyObject *obj);
9090
# define _PyGC_FINALIZED(o) PyObject_GC_IsFinalized(o)
9191
#endif
9292

93-
PyAPI_FUNC(PyObject *) _PyObject_GC_Malloc(size_t size);
94-
PyAPI_FUNC(PyObject *) _PyObject_GC_Calloc(size_t size);
95-
9693

9794
/* Test if a type supports weak references */
9895
#define PyType_SUPPORTS_WEAKREFS(t) ((t)->tp_weaklistoffset > 0)

Include/cpython/pystate.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ struct _ts {
7777
struct _ts *next;
7878
PyInterpreterState *interp;
7979

80+
/* Has been initialized to a safe state.
81+
82+
In order to be effective, this must be set to 0 during or right
83+
after allocation. */
84+
int _initialized;
85+
8086
int recursion_remaining;
8187
int recursion_limit;
8288
int recursion_headroom; /* Allow 50 more calls to handle any errors. */

Include/internal/pycore_ceval.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct _ceval_runtime_state;
1717

1818
extern void _Py_FinishPendingCalls(PyThreadState *tstate);
1919
extern void _PyEval_InitRuntimeState(struct _ceval_runtime_state *);
20-
extern int _PyEval_InitState(struct _ceval_state *ceval);
20+
extern void _PyEval_InitState(struct _ceval_state *, PyThread_type_lock);
2121
extern void _PyEval_FiniState(struct _ceval_state *ceval);
2222
PyAPI_FUNC(void) _PyEval_SignalReceived(PyInterpreterState *interp);
2323
PyAPI_FUNC(int) _PyEval_AddPendingCall(

Include/internal/pycore_interp.h

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,18 @@ struct type_cache {
238238
struct _is {
239239

240240
struct _is *next;
241-
struct _ts *tstate_head;
241+
242+
struct pythreads {
243+
uint64_t next_unique_id;
244+
struct _ts *head;
245+
/* Used in Modules/_threadmodule.c. */
246+
long count;
247+
/* Support for runtime thread stack size tuning.
248+
A value of 0 means using the platform's default stack size
249+
or the size specified by the THREAD_STACK_SIZE macro. */
250+
/* Used in Python/thread.c. */
251+
size_t stacksize;
252+
} threads;
242253

243254
/* Reference to the _PyRuntime global variable. This field exists
244255
to not have to pass runtime in addition to tstate to a function.
@@ -250,6 +261,11 @@ struct _is {
250261
int requires_idref;
251262
PyThread_type_lock id_mutex;
252263

264+
/* Has been initialized to a safe state.
265+
266+
In order to be effective, this must be set to 0 during or right
267+
after allocation. */
268+
int _initialized;
253269
int finalizing;
254270

255271
struct _ceval_state ceval;
@@ -268,14 +284,6 @@ struct _is {
268284
// (-1: "off", 1: "on", 0: no override)
269285
int override_frozen_modules;
270286

271-
/* Used in Modules/_threadmodule.c. */
272-
long num_threads;
273-
/* Support for runtime thread stack size tuning.
274-
A value of 0 means using the platform's default stack size
275-
or the size specified by the THREAD_STACK_SIZE macro. */
276-
/* Used in Python/thread.c. */
277-
size_t pythread_stacksize;
278-
279287
PyObject *codec_search_path;
280288
PyObject *codec_search_cache;
281289
PyObject *codec_error_registry;
@@ -302,8 +310,6 @@ struct _is {
302310
PyObject *after_forkers_child;
303311
#endif
304312

305-
uint64_t tstate_next_unique_id;
306-
307313
struct _warnings_runtime_state warnings;
308314
struct atexit_state atexit;
309315

Include/internal/pycore_object.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,15 @@ _PyObject_IS_GC(PyObject *obj)
168168
// Fast inlined version of PyType_IS_GC()
169169
#define _PyType_IS_GC(t) _PyType_HasFeature((t), Py_TPFLAGS_HAVE_GC)
170170

171+
static inline size_t
172+
_PyType_PreHeaderSize(PyTypeObject *tp)
173+
{
174+
return _PyType_IS_GC(tp) * sizeof(PyGC_Head) +
175+
_PyType_HasFeature(tp, Py_TPFLAGS_MANAGED_DICT) * 2 * sizeof(PyObject *);
176+
}
177+
178+
void _PyObject_GC_Link(PyObject *op);
179+
171180
// Usage: assert(_Py_CheckSlotResult(obj, "__getitem__", result != NULL));
172181
extern int _Py_CheckSlotResult(
173182
PyObject *obj,
@@ -185,7 +194,19 @@ extern int _PyObject_StoreInstanceAttribute(PyObject *obj, PyDictValues *values,
185194
PyObject *name, PyObject *value);
186195
PyObject * _PyObject_GetInstanceAttribute(PyObject *obj, PyDictValues *values,
187196
PyObject *name);
188-
PyDictValues ** _PyObject_ValuesPointer(PyObject *);
197+
198+
static inline PyDictValues **_PyObject_ValuesPointer(PyObject *obj)
199+
{
200+
assert(Py_TYPE(obj)->tp_flags & Py_TPFLAGS_MANAGED_DICT);
201+
return ((PyDictValues **)obj)-4;
202+
}
203+
204+
static inline PyObject **_PyObject_ManagedDictPointer(PyObject *obj)
205+
{
206+
assert(Py_TYPE(obj)->tp_flags & Py_TPFLAGS_MANAGED_DICT);
207+
return ((PyObject **)obj)-3;
208+
}
209+
189210
PyObject ** _PyObject_DictPointer(PyObject *);
190211
int _PyObject_VisitInstanceAttributes(PyObject *self, visitproc visit, void *arg);
191212
void _PyObject_ClearInstanceAttributes(PyObject *self);

Include/internal/pycore_pystate.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,23 @@ _Py_IsMainThread(void)
2121
}
2222

2323

24+
static inline PyInterpreterState *
25+
_PyInterpreterState_Main(void)
26+
{
27+
return _PyRuntime.interpreters.main;
28+
}
29+
2430
static inline int
2531
_Py_IsMainInterpreter(PyInterpreterState *interp)
2632
{
27-
/* Use directly _PyRuntime rather than tstate->interp->runtime, since
28-
this function is used in performance critical code path (ceval) */
29-
return (interp == _PyRuntime.interpreters.main);
33+
return (interp == _PyInterpreterState_Main());
3034
}
3135

3236

3337
static inline const PyConfig *
3438
_Py_GetMainConfig(void)
3539
{
36-
PyInterpreterState *interp = _PyRuntime.interpreters.main;
40+
PyInterpreterState *interp = _PyInterpreterState_Main();
3741
if (interp == NULL) {
3842
return NULL;
3943
}
@@ -45,7 +49,7 @@ _Py_GetMainConfig(void)
4549
static inline int
4650
_Py_ThreadCanHandleSignals(PyInterpreterState *interp)
4751
{
48-
return (_Py_IsMainThread() && interp == _PyRuntime.interpreters.main);
52+
return (_Py_IsMainThread() && _Py_IsMainInterpreter(interp));
4953
}
5054

5155

@@ -127,6 +131,8 @@ static inline PyInterpreterState* _PyInterpreterState_GET(void) {
127131

128132
// PyThreadState functions
129133

134+
PyAPI_FUNC(void) _PyThreadState_SetCurrent(PyThreadState *tstate);
135+
// We keep this around exclusively for stable ABI compatibility.
130136
PyAPI_FUNC(void) _PyThreadState_Init(
131137
PyThreadState *tstate);
132138
PyAPI_FUNC(void) _PyThreadState_DeleteExcept(

0 commit comments

Comments
 (0)