Skip to content

Commit b35ba13

Browse files
committed
Merge branch 'main' into tstrings
2 parents 8b0c132 + c4b7f7c commit b35ba13

File tree

68 files changed

+1266
-687
lines changed

Some content is hidden

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

68 files changed

+1266
-687
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ Tools/unicode/data/
143143
/profile-clean-stamp
144144
/profile-run-stamp
145145
/profile-bolt-stamp
146+
/profile-gen-stamp
146147
/pybuilddir.txt
147148
/pyconfig.h
148149
/python-config

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: 2 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)``.
@@ -49,6 +47,8 @@ although there is currently no date scheduled for their removal.
4947
:data:`calendar.FEBRUARY`.
5048
(Contributed by Prince Roshan in :gh:`103636`.)
5149

50+
* :mod:`codecs`: use :func:`open` instead of :func:`codecs.open`. (:gh:`133038`)
51+
5252
* :attr:`codeobject.co_lnotab`: use the :meth:`codeobject.co_lines` method
5353
instead.
5454

Doc/library/codecs.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ wider range of codecs when working with binary files:
208208
.. versionchanged:: 3.11
209209
The ``'U'`` mode has been removed.
210210

211+
.. deprecated:: next
212+
213+
:func:`codecs.open` has been superseded by :func:`open`.
214+
211215

212216
.. function:: EncodedFile(file, data_encoding, file_encoding=None, errors='strict')
213217

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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,11 @@ pdb
12391239
backend by default, which is configurable.
12401240
(Contributed by Tian Gao in :gh:`124533`.)
12411241

1242+
* :func:`pdb.set_trace_async` is added to support debugging asyncio
1243+
coroutines. :keyword:`await` statements are supported with this
1244+
function.
1245+
(Contributed by Tian Gao in :gh:`132576`.)
1246+
12421247

12431248
pickle
12441249
------
@@ -1663,6 +1668,10 @@ Deprecated
16631668
as a single positional argument.
16641669
(Contributed by Serhiy Storchaka in :gh:`109218`.)
16651670

1671+
* :mod:`codecs`:
1672+
:func:`codecs.open` is now deprecated. Use :func:`open` instead.
1673+
(Contributed by Inada Naoki in :gh:`133036`.)
1674+
16661675
* :mod:`functools`:
16671676
Calling the Python implementation of :func:`functools.reduce` with *function*
16681677
or *sequence* as keyword arguments is now deprecated.
@@ -1708,6 +1717,13 @@ Deprecated
17081717
Deprecate :meth:`symtable.Class.get_methods` due to the lack of interest.
17091718
(Contributed by Bénédikt Tran in :gh:`119698`.)
17101719

1720+
* :mod:`tkinter`:
1721+
The :class:`!tkinter.Variable` methods :meth:`!trace_variable`,
1722+
:meth:`!trace_vdelete` and :meth:`!trace_vinfo` are now deprecated.
1723+
Use :meth:`!trace_add`, :meth:`!trace_remove` and :meth:`!trace_info`
1724+
instead.
1725+
(Contributed by Serhiy Storchaka in :gh:`120220`.)
1726+
17111727
* :mod:`urllib.parse`:
17121728
Accepting objects with false values (like ``0`` and ``[]``) except empty
17131729
strings, byte-like objects and ``None`` in :mod:`urllib.parse` functions
@@ -2351,3 +2367,10 @@ Removed
23512367
* Remove the private ``_Py_InitializeMain()`` function. It was a
23522368
:term:`provisional API` added to Python 3.8 by :pep:`587`.
23532369
(Contributed by Victor Stinner in :gh:`129033`.)
2370+
2371+
* The undocumented APIs :c:macro:`!Py_C_RECURSION_LIMIT` and
2372+
:c:member:`!PyThreadState.c_recursion_remaining`, added in 3.13, are removed
2373+
without a deprecation period.
2374+
Please use :c:func:`Py_EnterRecursiveCall` to guard against runaway recursion
2375+
in C code.
2376+
(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_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_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; \

InternalDocs/garbage_collector.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ used as follows. If the buffer has reached the maximum size, new object
622622
pointers found while following references are pushed to the stack, rather than
623623
put in the buffer. When dequeuing objects from the buffer, we will "prime" the
624624
buffer if the current length drops below the low threshold. Priming means
625-
popping objects from the stack and enqueing them into the buffer. While
625+
popping objects from the stack and enqueuing them into the buffer. While
626626
priming, we will fill it only until the high threshold is reached.
627627

628628
To measure the effectiveness of the buffer, some benchmark programs were run

0 commit comments

Comments
 (0)