8000 Merge branch 'main' into 3.14-zstd-c-code · python/cpython@e45c22a · GitHub
[go: up one dir, main page]

Skip to content

Commit e45c22a

Browse files
authored
Merge branch 'main' into 3.14-zstd-c-code
2 parents cadf6e4 + 732d1b0 commit e45c22a

File tree

78 files changed

+1872
-1097
lines changed

Some content is hidden

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

78 files changed

+1872
-1097
lines changed

.github/workflows/mypy.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ on:
88
pull_request:
99
paths:
1010
- ".github/workflows/mypy.yml"
11+
- "Lib/_colorize.py"
1112
- "Lib/_pyrepl/**"
1213
- "Lib/test/libregrtest/**"
14+
- "Misc/mypy/**"
1315
- "Tools/build/generate_sbom.py"
1416
- "Tools/cases_generator/**"
1517
- "Tools/clinic/**"

Doc/c-api/unicode.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,14 @@ Python:
3333

3434
.. c:var:: PyTypeObject PyUnicode_Type
3535
36-
This instance of :c:type:`PyTypeObject` represents the Python Unicode type. It
37-
is exposed to Python code as :py:class:`str`.
36+
This instance of :c:type:`PyTypeObject` represents the Python Unicode type.
37+
It is exposed to Python code as :py:class:`str`.
38+
39+
40+
.. c:var:: PyTypeObject PyUnicodeIter_Type
41+
42+
This instance of :c:type:`PyTypeObject` represents the Python Unicode
43+
iterator type. It is used to iterate over Unicode string objects.
3844

3945

4046
.. c:type:: Py_UCS4

Doc/deprecations/pending-removal-in-future.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ although there is currently no date scheduled for their removal.
1313
deprecated.
1414
* The :class:`argparse.FileType` type converter is deprecated.
1515

16-
* :mod:`array`'s ``'u'`` format code (:gh:`57281`)
17-
1816
* :mod:`builtins`:
1917

2018
* ``bool(NotImplemented)``.

Doc/library/pdb.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,21 @@ slightly different way:
188188
.. versionadded:: 3.14
189189
The *commands* argument.
190190

191+
192+
.. awaitablefunction:: set_trace_async(*, header=None, commands=None)
193+
194+
async version of :func:`set_trace`. This function should be used inside an
195+
async function with :keyword:`await`.
196+
197+
.. code-block:: python
198+
199+
async def f():
200+
await pdb.set_trace_async()
201+
202+
:keyword:`await` statements are supported if the debugger is invoked by this function.
203+
204+
.. versionadded:: 3.14
205+
191206
.. function:: post_mortem(t=None)
192207

193208
Enter post-mortem debugging of the given exception or

Doc/whatsnew/3.14.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,11 @@ pdb
11681168
backend by default, which is configurable.
11691169
(Contributed by Tian Gao in :gh:`124533`.)
11701170

1171+
* :func:`pdb.set_trace_async` is added to support debugging asyncio
1172+
coroutines. :keyword:`await` statements are supported with this
1173+
function.
1174+
(Contributed by Tian Gao in :gh:`132576`.)
1175+
11711176

11721177
pickle
11731178
------
@@ -1637,6 +1642,13 @@ Deprecated
16371642
Deprecate :meth:`symtable.Class.get_methods` due to the lack of interest.
16381643
(Contributed by Bénédikt Tran in :gh:`119698`.)
16391644

1645+
* :mod:`tkinter`:
1646+
The :class:`!tkinter.Variable` methods :meth:`!trace_variable`,
1647+
:meth:`!trace_vdelete` and :meth:`!trace_vinfo` are now deprecated.
1648+
Use :meth:`!trace_add`, :meth:`!trace_remove` and :meth:`!trace_info`
1649+
instead.
1650+
(Contributed by Serhiy Storchaka in :gh:`120220`.)
1651+
16401652
* :mod:`urllib.parse`:
16411653
Accepting objects with false values (like ``0`` and ``[]``) except empty
16421654
strings, byte-like objects and ``None`` in :mod:`urllib.parse` functions
@@ -2280,3 +2292,10 @@ Removed
22802292
* Remove the private ``_Py_InitializeMain()`` function. It was a
22812293
:term:`provisional API` added to Python 3.8 by :pep:`587`.
22822294
(Contributed by Victor Stinner in :gh:`129033`.)
2295+
2296+
* The undocumented APIs :c:macro:`!Py_C_RECURSION_LIMIT` and
2297+
:c:member:`!PyThreadState.c_recursion_remaining`, added in 3.13, are removed
2298+
without a deprecation period.
2299+
Please use :c:func:`Py_EnterRecursiveCall` to guard against runaway recursion
2300+
in C code.
2301+
(Removed in :gh:`133079`, see also :gh:`130396`.)

Include/cpython/pystate.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ struct _ts {
118118

119119
int py_recursion_remaining;
120120
int py_recursion_limit;
121-
122-
int c_recursion_remaining; /* Retained for backwards compatibility. Do not use */
123121
int recursion_headroom; /* Allow 50 more calls to handle any errors. */
124122

125123
/* 'tracing' keeps track of the execution depth when tracing/profiling.
@@ -210,8 +208,6 @@ struct _ts {
210208
_PyRemoteDebuggerSupport remote_debugger_support;
211209
};
212210

213-
# define Py_C_RECURSION_LIMIT 5000
214-
215211
/* other API */
216212

217213
/* Similar to PyThreadState_Get(), but don't issue a fatal error

Include/internal/pycore_code.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,14 @@ typedef struct {
177177
*/
178178

179179
// Note that these all fit within a byte, as do combinations.
180-
// Later, we will use the smaller numbers to differentiate the different
181-
// kinds of locals (e.g. pos-only arg, varkwargs, local-only).
182-
#define CO_FAST_HIDDEN 0x10
183-
#define CO_FAST_LOCAL 0x20
184-
#define CO_FAST_CELL 0x40
185-
#define CO_FAST_FREE 0x80
180+
#define CO_FAST_ARG_POS (0x02) // pos-only, pos-or-kw, varargs
181+
#define CO_FAST_ARG_KW (0x04) // kw-only, pos-or-kw, varkwargs
182+
#define CO_FAST_ARG_VAR (0x08) // varargs, varkwargs
183+
#define CO_FAST_ARG (CO_FAST_ARG_POS | CO_FAST_ARG_KW | CO_FAST_ARG_VAR)
184+
#define CO_FAST_HIDDEN (0x10)
185+
#define CO_FAST_LOCAL (0x20)
186+
#define CO_FAST_CELL (0x40)
187+
#define CO_FAST_FREE (0x80)
186188

187189
typedef unsigned char _PyLocals_Kind;
188190

@@ -315,6 +317,7 @@ extern void _Py_Specialize_ForIter(_PyStackRef iter, _Py_CODEUNIT *instr, int op
315317
extern void _Py_Specialize_Send(_PyStackRef receiver, _Py_CODEUNIT *instr);
316318
extern void _Py_Specialize_ToBool(_PyStackRef value, _Py_CODEUNIT *instr);
317319
extern void _Py_Specialize_ContainsOp(_PyStackRef value, _Py_CODEUNIT *instr);
320+
extern void _Py_GatherStats_GetIter(_PyStackRef iterable);
318321

319322
// Utility functions for reading/writing 32/64-bit values in the inline caches.
320323
// Great care should be taken to ensure that these functions remain correct and
@@ -561,6 +564,10 @@ extern void _Py_ClearTLBCIndex(_PyThreadStateImpl *tstate);
561564
extern int _Py_ClearUnusedTLBC(PyInterpreterState *interp);
562565
#endif
563566

567+
568+
PyAPI_FUNC(int) _PyCode_ReturnsOnlyNone(PyCodeObject *);
569+
570+
564571
#ifdef __cplusplus
565572
}
566573
#endif

Include/internal/pycore_interp_structs.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -667,11 +667,8 @@ struct _Py_interp_cached_objects {
667667

668668
/* object.__reduce__ */
669669
PyObject *objreduce;
670-
#ifndef Py_GIL_DISABLED
671-
/* resolve_slotdups() */
672670
PyObject *type_slots_pname;
673671
pytype_slotdef *type_slots_ptrs[MAX_EQUIV];
674-
#endif
675672

676673
/* TypeVar and related types */
677674
PyTypeObject *generic_type;

Include/internal/pycore_interpframe.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ extern "C" {
1818
((int)((IF)->instr_ptr - _PyFrame_GetBytecode((IF))))
1919

2020
static inline PyCodeObject *_PyFrame_GetCode(_PyInterpreterFrame *f) {
21+
assert(!PyStackRef_IsNull(f->f_executable));
2122
PyObject *executable = PyStackRef_AsPyObjectBorrow(f->f_executable);
2223
assert(PyCode_Check(executable));
2324
return (PyCodeObject *)executable;

Include/internal/pycore_object.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ extern int _PyDict_CheckConsistency(PyObject *mp, int check_content);
313313
// Fast inlined version of PyType_HasFeature()
314314
static inline int
315315
_PyType_HasFeature(PyTypeObject *type, unsigned long feature) {
316-
return ((type->tp_flags) & feature) != 0;
316+
return ((FT_ATOMIC_LOAD_ULONG_RELAXED(type->tp_flags) & feature) != 0);
317317
}
318318

319319
extern void _PyType_InitCache(PyInterpreterState *interp);

Include/internal/pycore_opcode_utils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ extern "C" {
5454
(opcode) == RAISE_VARARGS || \
5555
(opcode) == RERAISE)
5656

57+
#define IS_RETURN_OPCODE(opcode) \
58+
(opcode == RETURN_VALUE)
59+
5760

5861
/* Flags used in the oparg for MAKE_FUNCTION */
5962
#define MAKE_FUNCTION_DEFAULTS 0x01

Include/internal/pycore_stackref.h

Lines changed: 68 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,13 @@ extern void _Py_stackref_associate(PyInterpreterState *interp, PyObject *obj, _P
6363

6464
static const _PyStackRef PyStackRef_NULL = { .index = 0 };
6565

66-
#define PyStackRef_None ((_PyStackRef){ .index = 1 } )
67-
#define PyStackRef_False ((_PyStackRef){ .index = 2 })
68-
#define PyStackRef_True ((_PyStackRef){ .index = 3 })
66+
// Use the first 3 even numbers for None, True and False.
67+
// Odd numbers are reserved for (tagged) integers
68+
#define PyStackRef_None ((_PyStackRef){ .index = 2 } )
69+
#define PyStackRef_False ((_PyStackRef){ .index = 4 })
70+
#define PyStackRef_True ((_PyStackRef){ .index = 6 })
6971

70-
#define LAST_PREDEFINED_STACKREF_INDEX 3
72+
#define INITIAL_STACKREF_INDEX 8
7173

7274
static inline int
7375
PyStackRef_IsNull(_PyStackRef ref)
@@ -96,6 +98,7 @@ PyStackRef_IsNone(_PyStackRef ref)
9698
static inline PyObject *
9799
_PyStackRef_AsPyObjectBorrow(_PyStackRef ref, const char *filename, int linenumber)
98100
{
101+
assert((ref.index & 1) == 0);
99102
_Py_stackref_record_borrow(ref, filename, linenumber);
100103
return _Py_stackref_get_object(ref);
101104
}
@@ -132,31 +135,45 @@ _PyStackRef_FromPyObjectImmortal(PyObject *obj, const char *filename, int linenu
132135
}
133136
#define PyStackRef_FromPyObjectImmortal(obj) _PyStackRef_FromPyObjectImmortal(_PyObject_CAST(obj), __FILE__, __LINE__)
134137

138+
static inline bool
139+
PyStackRef_IsTaggedInt(_PyStackRef ref)
140+
{
141+
return (ref.index & 1) == 1;
142+
}
143+
135144
static inline void
136145
_PyStackRef_CLOSE(_PyStackRef ref, const char *filename, int linenumber)
137146
{
147+
if (PyStackRef_IsTaggedInt(ref)) {
148+
return;
149+
}
138150
PyObject *obj = _Py_stackref_close(ref, filename, linenumber);
139151
Py_DECREF(obj);
140152
}
141153
#define PyStackRef_CLOSE(REF) _PyStackRef_CLOSE((REF), __FILE__, __LINE__)
142154

155+
143156
static inline void
144157
_PyStackRef_XCLOSE(_PyStackRef ref, const char *filename, int linenumber)
145158
{
146159
if (PyStackRef_IsNull(ref)) {
147160
return;
148161
}
149-
PyObject *obj = _Py_stackref_close(ref, filename, linenumber);
150-
Py_DECREF(obj);
162+
_PyStackRef_CLOSE(ref, filename, linenumber);
151163
}
152164
#define PyStackRef_XCLOSE(REF) _PyStackRef_XCLOSE((REF), __FILE__, __LINE__)
153165

154166
static inline _PyStackRef
155167
_PyStackRef_DUP(_PyStackRef ref, const char *filename, int linenumber)
156168
{
157-
PyObject *obj = _Py_stackref_get_object(ref);
158-
Py_INCREF(obj);
159-
return _Py_stackref_create(obj, filename, linenumber);
169+
if (PyStackRef_IsTaggedInt(ref)) {
170+
return ref;
171+
}
172+
else {
173+
PyObject *obj = _Py_stackref_get_object(ref);
174+
Py_INCREF(obj);
175+
return _Py_stackref_create(obj, filename, linenumber);
176+
}
160177
}
161178
#define PyStackRef_DUP(REF) _PyStackRef_DUP(REF, __FILE__, __LINE__)
162179

@@ -210,8 +227,40 @@ _PyStackRef_FromPyObjectNewMortal(PyObject *obj, const char *filename, int linen
210227

211228
extern int PyStackRef_Is(_PyStackRef a, _PyStackRef b);
212229

230+
extern bool PyStackRef_IsTaggedInt(_PyStackRef ref);
231+
232+
extern intptr_t PyStackRef_UntagInt(_PyStackRef ref);
233+
234+
extern _PyStackRef PyStackRef_TagInt(intptr_t i);
235+
236+
extern bool
237+
PyStackRef_IsNullOrInt(_PyStackRef ref);
238+
213239
#else
214240

241+
#define Py_INT_TAG 3
242+
243+
static inline bool
244+
PyStackRef_IsTaggedInt(_PyStackRef i)
245+
{
246+
return (i.bits & Py_INT_TAG) == Py_INT_TAG;
247+
}
248+
249+
static inline _PyStackRef
250+
PyStackRef_TagInt(intptr_t i)
251+
{
252+
assert(Py_ARITHMETIC_RIGHT_SHIFT(intptr_t, (i << 2), 2) == i);
253+
return (_PyStackRef){ .bits = ((((uintptr_t)i) << 2) | Py_INT_TAG) };
254+
}
255+
256+
static inline intptr_t
257+
PyStackRef_UntagInt(_PyStackRef i)
258+
{
259+
assert((i.bits & Py_INT_TAG) == Py_INT_TAG);
260+
intptr_t val = (intptr_t)i.bits;
261+
return Py_ARITHMETIC_RIGHT_SHIFT(intptr_t, val, 2);
262+
}
263+
215264

216265
#ifdef Py_GIL_DISABLED
217266

@@ -232,6 +281,8 @@ static const _PyStackRef PyStackRef_NULL = { .bits = Py_TAG_DEFERRED};
232281
#define PyStackRef_IsTrue(ref) (PyStackRef_AsPyObjectBorrow(ref) == Py_True)
233282
#define PyStackRef_IsFalse(ref) (PyStackRef_AsPyObjectBorrow(ref) == Py_False)
234283

284+
#define PyStackRef_IsNullOrInt(stackref) (PyStackRef_IsNull(stackref) || PyStackRef_IsTaggedInt(stackref))
285+
235286
static inline PyObject *
236287
PyStackRef_AsPyObjectBorrow(_PyStackRef stackref)
237288
{
@@ -451,6 +502,7 @@ PyStackRef_RefcountOnObject(_PyStackRef ref)
451502
static inline PyObject *
452503
PyStackRef_AsPyObjectBorrow(_PyStackRef ref)
453504
{
505+
assert(!PyStackRef_IsTaggedInt(ref));
454506
return BITS_TO_PTR_MASKED(ref);
455507
}
456508

@@ -587,6 +639,12 @@ PyStackRef_CLOSE(_PyStackRef ref)
587639
}
588640
#endif
589641

642+
static inline bool
643+
PyStackRef_IsNullOrInt(_PyStackRef ref)
644+
{
645+
return PyStackRef_IsNull(ref) || PyStackRef_IsTaggedInt(ref);
646+
}
647+
590648
static inline void
591649
PyStackRef_CLOSE_SPECIALIZED(_PyStackRef ref, destructor destruct)
592650
{
@@ -726,7 +784,7 @@ _Py_TryXGetStackRef(PyObject **src, _PyStackRef *out)
726784
// Like Py_VISIT but for _PyStackRef fields
727785
#define _Py_VISIT_STACKREF(ref) \
728786
do { \
729-
if (!PyStackRef_IsNull(ref)) { \
787+
if (!PyStackRef_IsNullOrInt(ref)) { \
730788
int vret = _PyGC_VisitStackRef(&(ref), visit, arg); \
731789
if (vret) \
732790
return vret; \

Include/internal/pycore_typeobject.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ extern int _PyType_AddMethod(PyTypeObject *, PyMethodDef *);
134134
extern void _PyType_SetFlagsRecursive(PyTypeObject *self, unsigned long mask,
135135
unsigned long flags);
136136

137+
extern unsigned int _PyType_GetVersionForCurrentState(PyTypeObject *tp);
137138
PyAPI_FUNC(void) _PyType_SetVersion(PyTypeObject *tp, unsigned int version);
138139
PyTypeObject *_PyType_LookupByVersion(unsigned int version);
139140

Include/object.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -620,12 +620,6 @@ given type object has a specified feature.
620620
#define Py_TPFLAGS_HAVE_FINALIZE (1UL << 0)
621621
#define Py_TPFLAGS_HAVE_VERSION_TAG (1UL << 18)
622622

623-
// Flag values for ob_flags (16 bits available, if SIZEOF_VOID_P > 4).
624-
#define _Py_IMMORTAL_FLAGS (1 << 0)
625-
#define _Py_STATICALLY_ALLOCATED_FLAG (1 << 2)
626-
#if defined(Py_GIL_DISABLED) && defined(Py_DEBUG)
627-
#define _Py_TYPE_REVEALED_FLAG (1 << 3)
628-
#endif
629623

630624
#define Py_CONSTANT_NONE 0
631625
#define Py_CONSTANT_FALSE 1
@@ -782,7 +776,11 @@ PyType_HasFeature(PyTypeObject *type, unsigned long feature)
782776
// PyTypeObject is opaque in the limited C API
783777
flags = PyType_GetFlags(type);
784778
#else
785-
flags = type->tp_flags;
779+
# ifdef Py_GIL_DISABLED
780+
flags = _Py_atomic_load_ulong_relaxed(&type->tp_flags);
781+
# else
782+
flags = type->tp_flags;
783+
# endif
786784
#endif
787785
return ((flags & feature) != 0);
788786
}

Include/refcount.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ immortal. The latter should be the only instances that require
1919
cleanup during runtime finalization.
2020
*/
2121

22+
#define _Py_STATICALLY_ALLOCATED_FLAG 4
23+
#define _Py_IMMORTAL_FLAGS 1
24+
2225
#if SIZEOF_VOID_P > 4
2326
/*
2427
In 64+ bit systems, any object whose 32 bit reference count is >= 2**31

0 commit comments

Comments
 (0)
0