Skip to content

Commit 5fa7dc9

Browse files
authored
Merge branch 'main' into support-halffloat-arrays/146238
2 parents e8bb6f3 + f4d3c61 commit 5fa7dc9

File tree

69 files changed

+2582
-399
lines changed

Some content is hidden

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

69 files changed

+2582
-399
lines changed

Doc/library/getpass.rst

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,27 @@ The :mod:`!getpass` module provides two functions:
3939
On Unix systems, when *echo_char* is set, the terminal will be
4040
configured to operate in
4141
:manpage:`noncanonical mode <termios(3)#Canonical_and_noncanonical_mode>`.
42-
In particular, this means that line editing shortcuts such as
43-
:kbd:`Ctrl+U` will not work and may insert unexpected characters into
44-
the input.
42+
Common terminal control characters are supported:
43+
44+
* :kbd:`Ctrl+A` - Move cursor to beginning of line
45+
* :kbd:`Ctrl+E` - Move cursor to end of line
46+
* :kbd:`Ctrl+K` - Kill (delete) from cursor to end of line
47+
* :kbd:`Ctrl+U` - Kill (delete) entire line
48+
* :kbd:`Ctrl+W` - Erase previous word
49+
* :kbd:`Ctrl+V` - Insert next character literally (quote)
50+
* :kbd:`Backspace`/:kbd:`DEL` - Delete character before cursor
51+
52+
These shortcuts work by reading the terminal's configured control
53+
character mappings from termios settings.
4554

4655
.. versionchanged:: 3.14
4756
Added the *echo_char* parameter for keyboard feedback.
4857

58+
.. versionchanged:: next
59+
When using non-empty *echo_char* on Unix, keyboard shortcuts (including
60+
cursor movement and line editing) are now properly handled using the
61+
terminal's control character configuration.
62+
4963
.. exception:: GetPassWarning
5064

5165
A :exc:`UserWarning` subclass issued when password input may be echoed.

Doc/library/profiling.sampling.rst

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,47 @@ at the top indicate functions that consume significant time either directly
10031003
or through their callees.
10041004

10051005

1006+
Differential flame graphs
1007+
~~~~~~~~~~~~~~~~~~~~~~~~~
1008+
1009+
Differential flame graphs compare two profiling runs to highlight where
1010+
performance changed. This helps identify regressions introduced by code changes
1011+
and validate that optimizations achieved their intended effect::
1012+
1013+
# Capture baseline profile
1014+
python -m profiling.sampling run --binary -o baseline.bin script.py
1015+
1016+
# After modifying code, generate differential flamegraph
1017+
python -m profiling.sampling run --diff-flamegraph baseline.bin -o diff.html script.py
1018+
1019+
The visualization draws the current profile with frame widths showing current
1020+
time consumption, then applies color to indicate how each function changed
1021+
relative to the baseline.
1022+
1023+
**Color coding**:
1024+
1025+
- **Red**: Functions consuming more time (regressions). Lighter shades indicate
1026+
modest increases, while darker shades show severe regressions.
1027+
1028+
- **Blue**: Functions consuming less time (improvements). Lighter shades for
1029+
modest reductions, darker shades for significant speedups.
1030+
1031+
- **Gray**: Minimal or no change.
1032+
1033+
- **Purple**: New functions not present in the baseline.
1034+
1035+
Frame colors indicate changes in **direct time** (time when the function was at
1036+
the top of the stack, actively executing), not cumulative time including callees.
1037+
Hovering over a frame shows comparison details including baseline time, current
1038+
time, and the percentage change.
1039+
1040+
Some call paths may disappear entirely between profiles. These are called
1041+
**elided stacks** and occur when optimizations eliminate code paths or certain
1042+
branches stop executing. If elided stacks are present, an elided toggle appears
1043+
allowing you to switch between the main differential view and an elided-only
1044+
view that shows just the removed paths (colored purple).
1045+
1046+
10061047
Gecko format
10071048
------------
10081049

@@ -1488,6 +1529,10 @@ Output options
14881529

14891530
Generate self-contained HTML flame graph.
14901531

1532+
.. option:: --diff-flamegraph <baseline.bin>
1533+
1534+
Generate differential flamegraph comparing to a baseline binary profile.
1535+
14911536
.. option:: --gecko
14921537

14931538
Generate Gecko JSON format for Firefox Profiler.

Doc/library/select.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ The module defines the following:
6262

6363
*sizehint* informs epoll about the expected number of events to be
6464
registered. It must be positive, or ``-1`` to use the default. It is only
65-
used on older systems where :c:func:`!epoll_create1` is not available;
65+
used on older systems where :manpage:`epoll_create1(2)` is not available;
6666
otherwise it has no effect (though its value is still checked).
6767

6868
*flags* is deprecated and completely ignored. However, when supplied, its
@@ -89,6 +89,11 @@ The module defines the following:
8989
The *flags* parameter. ``select.EPOLL_CLOEXEC`` is used by default now.
9090
Use :func:`os.set_inheritable` to make the file descriptor inheritable.
9191

92+
.. versionchanged:: next
93+
94+
When CPython is built, this function may be disabled using
95+
:option:`--disable-epoll`.
96+
9297

9398
.. function:: poll()
9499

Doc/library/socket.rst

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ is implicit on send operations.
3939
A TLS/SSL wrapper for socket objects.
4040

4141

42+
.. _socket-addresses:
43+
4244
Socket families
4345
---------------
4446

@@ -903,7 +905,7 @@ The following functions all create :ref:`socket objects <socket-objects>`.
903905

904906
Build a pair of connected socket objects using the given address family, socket
905907
type, and protocol number. Address family, socket type, and protocol number are
906-
as for the :func:`~socket.socket` function above. The default family is :const:`AF_UNIX`
908+
as for the :func:`~socket.socket` function. The default family is :const:`AF_UNIX`
907909
if defined on the platform; otherwise, the default is :const:`AF_INET`.
908910

909911
The newly created sockets are :ref:`non-inheritable <fd_inheritance>`.
@@ -999,8 +1001,8 @@ The following functions all create :ref:`socket objects <socket-objects>`.
9991001

10001002
Duplicate the file descriptor *fd* (an integer as returned by a file object's
10011003
:meth:`~io.IOBase.fileno` method) and build a socket object from the result. Address
1002-
family, socket type and protocol number are as for the :func:`~socket.socket` function
1003-
above. The file descriptor should refer to a socket, but this is not checked ---
1004+
family, socket type and protocol number are as for the :func:`~socket.socket` function.
1005+
The file descriptor should refer to a socket, but this is not checked ---
10041006
subsequent operations on the object may fail if the file descriptor is invalid.
10051007
This function is rarely needed, but can be used to get or set socket options on
10061008
a socket passed to a program as standard input or output (such as a server
@@ -1564,8 +1566,8 @@ to sockets.
15641566

15651567
.. method:: socket.bind(address)
15661568

1567-
Bind the socket to *address*. The socket must not already be bound. (The format
1568-
of *address* depends on the address family --- see above.)
1569+
Bind the socket to *address*. The socket must not already be bound. The format
1570+
of *address* depends on the address family --- see :ref:`socket-addresses`.
15691571

15701572
.. audit-event:: socket.bind self,address socket.socket.bind
15711573

@@ -1598,8 +1600,8 @@ to sockets.
15981600

15991601
.. method:: socket.connect(address)
16001602

1601-
Connect to a remote socket at *address*. (The format of *address* depends on the
1602-
address family --- see above.)
1603+
Connect to a remote socket at *address*. The format of *address* depends on the
1604+
address family --- see :ref:`socket-addresses`.
16031605

16041606
If the connection is interrupted by a signal, the method waits until the
16051607
connection completes, or raises a :exc:`TimeoutError` on timeout, if the
@@ -1674,16 +1676,16 @@ to sockets.
16741676
.. method:: socket.getpeername()
16751677

16761678
Return the remote address to which the socket is connected. This is useful to
1677-
find out the port number of a remote IPv4/v6 socket, for instance. (The format
1678-
of the address returned depends on the address family --- see above.) On some
1679-
systems this function is not supported.
1679+
find out the port number of a remote IPv4/v6 socket, for instance. The format
1680+
of the address returned depends on the address family --- see :ref:`socket-addresses`.
1681+
On some systems this function is not supported.
16801682

16811683

16821684
.. method:: socket.getsockname()
16831685

16841686
Return the socket's own address. This is useful to find out the port number of
1685-
an IPv4/v6 socket, for instance. (The format of the address returned depends on
1686-
the address family --- see above.)
1687+
an IPv4/v6 socket, for instance. The format of the address returned depends on
1688+
the address family --- see :ref:`socket-addresses`.
16871689

16881690

16891691
.. method:: socket.getsockopt(level, optname[, buflen])
@@ -1795,7 +1797,8 @@ to sockets.
17951797
where *bytes* is a bytes object representing the data received and *address* is the
17961798
address of the socket sending the data. See the Unix manual page
17971799
:manpage:`recv(2)` for the meaning of the optional argument *flags*; it defaults
1798-
to zero. (The format of *address* depends on the address family --- see above.)
1800+
to zero. The format of *address* depends on the address family --- see
1801+
:ref:`socket-addresses`.
17991802

18001803
.. versionchanged:: 3.5
18011804
If the system call is interrupted and the signal handler does not raise
@@ -1925,8 +1928,8 @@ to sockets.
19251928
new bytestring. The return value is a pair ``(nbytes, address)`` where *nbytes* is
19261929
the number of bytes received and *address* is the address of the socket sending
19271930
the data. See the Unix manual page :manpage:`recv(2)` for the meaning of the
1928-
optional argument *flags*; it defaults to zero. (The format of *address*
1929-
depends on the address family --- see above.)
1931+
optional argument *flags*; it defaults to zero. The format of *address*
1932+
depends on the address family --- see :ref:`socket-addresses`.
19301933

19311934

19321935
.. method:: socket.recv_into(buffer[, nbytes[, flags]])
@@ -1941,7 +1944,7 @@ to sockets.
19411944
.. method:: socket.send(bytes[, flags])
19421945

19431946
Send data to the socket. The socket must be connected to a remote socket. The
1944-
optional *flags* argument has the same meaning as for :meth:`recv` above.
1947+
optional *flags* argument has the same meaning as for :meth:`recv`.
19451948
Returns the number of bytes sent. Applications are responsible for checking that
19461949
all data has been sent; if only some of the data was transmitted, the
19471950
application needs to attempt delivery of the remaining data. For further
@@ -1956,7 +1959,7 @@ to sockets.
19561959
.. method:: socket.sendall(bytes[, flags])
19571960

19581961
Send data to the socket. The socket must be connected to a remote socket. The
1959-
optional *flags* argument has the same meaning as for :meth:`recv` above.
1962+
optional *flags* argument has the same meaning as for :meth:`recv`.
19601963
Unlike :meth:`send`, this method continues to send data from *bytes* until
19611964
either all data has been sent or an error occurs. ``None`` is returned on
19621965
success. On error, an exception is raised, and there is no way to determine how
@@ -1977,9 +1980,9 @@ to sockets.
19771980

19781981
Send data to the socket. The socket should not be connected to a remote socket,
19791982
since the destination socket is specified by *address*. The optional *flags*
1980-
argument has the same meaning as for :meth:`recv` above. Return the number of
1981-
bytes sent. (The format of *address* depends on the address family --- see
1982-
above.)
1983+
argument has the same meaning as for :meth:`recv`. Return the number of
1984+
bytes sent. The format of *address* depends on the address family --- see
1985+
:ref:`socket-addresses`.
19831986

19841987
.. audit-event:: socket.sendto self,address socket.socket.sendto
19851988

Doc/using/configure.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,17 @@ General Options
463463

464464
``pkg-config`` options.
465465

466+
.. option:: --disable-epoll
467+
468+
Build without ``epoll``, meaning that :py:func:`select.epoll` will not be
469+
present even if the system provides an
470+
:manpage:`epoll_create <epoll_create(2)>` function.
471+
This may be used on systems where :manpage:`!epoll_create` or
472+
:manpage:`epoll_create1 <epoll_create1(2)>` is available
473+
but incompatible with Linux semantics.
474+
475+
.. versionadded:: next
476+
466477

467478
C compiler options
468479
------------------

Include/internal/pycore_ceval.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ PyAPI_FUNC(int) _PyEval_ExceptionGroupMatch(_PyInterpreterFrame *, PyObject* exc
302302
PyAPI_FUNC(void) _PyEval_FormatAwaitableError(PyThreadState *tstate, PyTypeObject *type, int oparg);
303303
PyAPI_FUNC(void) _PyEval_FormatExcCheckArg(PyThreadState *tstate, PyObject *exc, const char *format_str, PyObject *obj);
304304
PyAPI_FUNC(void) _PyEval_FormatExcUnbound(PyThreadState *tstate, PyCodeObject *co, int oparg);
305-
PyAPI_FUNC(void) _PyEval_FormatKwargsError(PyThreadState *tstate, PyObject *func, PyObject *kwargs);
305+
PyAPI_FUNC(void) _PyEval_FormatKwargsError(PyThreadState *tstate, PyObject *func, PyObject *kwargs, PyObject *dupkey);
306306
PyAPI_FUNC(PyObject *) _PyEval_ImportFrom(PyThreadState *, PyObject *, PyObject *);
307307

308308
PyAPI_FUNC(PyObject *) _PyEval_LazyImportName(

Include/internal/pycore_debug_offsets.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ typedef struct _Py_DebugOffsets {
222222
uint64_t size;
223223
uint64_t collecting;
224224
uint64_t frame;
225+
uint64_t generation_stats_size;
226+
uint64_t generation_stats;
225227
} gc;
226228

227229
// Generator object offset;
@@ -373,6 +375,8 @@ typedef struct _Py_DebugOffsets {
373375
.size = sizeof(struct _gc_runtime_state), \
374376
.collecting = offsetof(struct _gc_runtime_state, collecting), \
375377
.frame = offsetof(struct _gc_runtime_state, frame), \
378+
.generation_stats_size = sizeof(struct gc_stats), \
379+
.generation_stats = offsetof(struct _gc_runtime_state, generation_stats), \
376380
}, \
377381
.gen_object = { \
378382
.size = sizeof(PyGenObject), \

Include/internal/pycore_dict.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ extern Py_ssize_t _PyDict_SizeOf_LockHeld(PyDictObject *);
5555
of a key wins, if override is 2, a KeyError with conflicting key as
5656
argument is raised.
5757
*/
58-
PyAPI_FUNC(int) _PyDict_MergeEx(PyObject *mp, PyObject *other, int override);
58+
PyAPI_FUNC(int) _PyDict_MergeUniq(PyObject *mp, PyObject *other, PyObject **dupkey);
5959

6060
extern void _PyDict_DebugMallocStats(FILE *out);
6161

Include/internal/pycore_interp_structs.h

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -177,31 +177,54 @@ struct gc_generation {
177177
generations */
178178
};
179179

180-
struct gc_collection_stats {
181-
/* number of collected objects */
182-
Py_ssize_t collected;
183-
/* total number of uncollectable objects (put into gc.garbage) */
184-
Py_ssize_t uncollectable;
185-
// Total number of objects considered for collection and traversed:
186-
Py_ssize_t candidates;
187-
// Duration of the collection in seconds:
188-
double duration;
189-
};
190-
191180
/* Running stats per generation */
192181
struct gc_generation_stats {
182+
PyTime_t ts_start;
183+
PyTime_t ts_stop;
184+
185+
/* heap_size on the start of the collection */
186+
Py_ssize_t heap_size;
187+
188+
/* work_to_do on the start of the collection */
189+
Py_ssize_t work_to_do;
190+
193191
/* total number of collections */
194192
Py_ssize_t collections;
193+
194+
/* total number of visited objects */
195+
Py_ssize_t object_visits;
196+
195197
/* total number of collected objects */
196198
Py_ssize_t collected;
197199
/* total number of uncollectable objects (put into gc.garbage) */
198200
Py_ssize_t uncollectable;
199201
// Total number of objects considered for collection and traversed:
200202
Py_ssize_t candidates;
201-
// Duration of the collection in seconds:
203+
204+
Py_ssize_t objects_transitively_reachable;
205+
Py_ssize_t objects_not_transitively_reachable;
206+
207+
// Total duration of the collection in seconds:
202208
double duration;
203209
};
204210

211+
#ifdef Py_GIL_DISABLED
212+
#define GC_YOUNG_STATS_SIZE 1
213+
#define GC_OLD_STATS_SIZE 1
214+
#else
215+
#define GC_YOUNG_STATS_SIZE 11
216+
#define GC_OLD_STATS_SIZE 3
217+
#endif
218+
struct gc_young_stats_buffer {
219+
struct gc_generation_stats items[GC_YOUNG_STATS_SIZE];
220+
int8_t index;
221+
};
222+
223+
struct gc_old_stats_buffer {
224+
struct gc_generation_stats items[GC_OLD_STATS_SIZE];
225+
int8_t index;
226+
};
227+
205228
enum _GCPhase {
206229
GC_PHASE_MARK = 0,
207230
GC_PHASE_COLLECT = 1
@@ -211,6 +234,11 @@ enum _GCPhase {
211234
signature of gc.collect and change the size of PyStats.gc_stats */
212235
#define NUM_GENERATIONS 3
213236

237+
struct gc_stats {
238+
struct gc_young_stats_buffer young;
239+
struct gc_old_stats_buffer old[2];
240+
};
241+
214242
struct _gc_runtime_state {
215243
/* Is automatic collection enabled? */
216244
int enabled;
@@ -220,7 +248,7 @@ struct _gc_runtime_state {
220248
struct gc_generation old[2];
221249
/* a permanent generation which won't be collected */
222250
struct gc_generation permanent_generation;
223-
struct gc_generation_stats generation_stats[NUM_GENERATIONS];
251+
struct gc_stats generation_stats;
224252
/* true if we are currently running the collector */
225253
int collecting;
226254
// The frame that started the current collection. It might be NULL even when

Lib/_pyrepl/pager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def pipe_pager(text: str, cmd: str, title: str = '') -> None:
138138
'.'
139139
'?e (END):?pB %pB\\%..'
140140
' (press h for help or q to quit)')
141-
env['LESS'] = '-RmPm{0}$PM{0}$'.format(prompt_string)
141+
env['LESS'] = '-RcmPm{0}$PM{0}$'.format(prompt_string)
142142
proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
143143
errors='backslashreplace', env=env)
144144
assert proc.stdin is not None

0 commit comments

Comments
 (0)