Skip to content

Commit eb2926d

Browse files
committed
resolve conflict with main
2 parents d5ebb0b + 0a1d601 commit eb2926d

50 files changed

Lines changed: 2826 additions & 691 deletions

Some content is hidden

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

‎Doc/c-api/gcsupport.rst‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,13 @@ The :c:member:`~PyTypeObject.tp_traverse` handler must have the following type:
253253
returned immediately.
254254
Otherwise, return zero.
255255
256+
The garbage collector can call :c:member:`~PyTypeObject.tp_traverse` more
257+
than once for the same object during a collection. If the object's
258+
references do not change, each traversal must visit the same references.
259+
In particular, do not skip a reference because a lock is busy.
260+
If one traversal visits a reference and a later traversal skips it, the
261+
collector can clear an object that is still reachable.
262+
256263
A typical :c:member:`!tp_traverse` function calls the :c:func:`Py_VISIT`
257264
convenience macro on each of the instance's members that are Python
258265
objects that the instance owns.
@@ -318,14 +325,6 @@ The :c:member:`~PyTypeObject.tp_traverse` handler must have the following type:
318325
For a list of safe functions, see a
319326
:ref:`separate section <duringgc-functions>` below.
320327
321-
If an error occurs during traversal, ignore it and return 0.
322-
If ``tp_traverse`` fails to visit some strong references, garbage reference
323-
cycles involving the skipped references will not be reliably broken,
324-
but correctness won't be affected.
325-
For example, if traversal requires a lock that cannot be acquired promptly,
326-
skip the traversal.
327-
The garbage collector will visit your object again in a future pass.
328-
329328
.. note::
330329
331330
The :c:func:`Py_VISIT` call may be skipped for those members that provably

‎Doc/library/logging.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ wire).
919919
:param exc_info: An exception tuple with the current exception information,
920920
as returned by :func:`sys.exc_info`,
921921
or ``None`` if no exception information is available.
922-
:type exc_info: tuple[type[BaseException], BaseException, types.TracebackType] | None
922+
:type exc_info: tuple[type[BaseException], BaseException, types.TracebackType | None] | tuple[None, None, None] | None
923923

924924
:param func: The name of the function or method
925925
from which the logging call was invoked.

‎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
@@ -241,6 +241,7 @@ struct _Py_global_strings {
241241
STRUCT_FOR_ID(__str__)
242242
STRUCT_FOR_ID(__sub__)
243243
STRUCT_FOR_ID(__subclasscheck__)
244+
STRUCT_FOR_ID(__subclasses__)
244245
STRUCT_FOR_ID(__subclasshook__)
245246
STRUCT_FOR_ID(__truediv__)
246247
STRUCT_FOR_ID(__trunc__)

‎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_unicodeobject_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.

‎InternalDocs/profiling_binary_format.md‎

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,12 @@ network streams.
119119

120120
## Sample Data
121121

122-
Sample data begins at offset 64 and extends to `string_table_offset`. Samples
123-
are grouped into blocks of at most 1 MiB of decoded data. Within a block,
124-
samples use delta compression to minimize redundancy when consecutive samples
125-
from the same thread have identical or similar call stacks. Each block can be
126-
decoded on its own once the string and frame tables are loaded, so a reader
127-
only needs to decode one block at a time.
122+
Sample data begins at offset 64 and extends to `string_table_offset`. Each
123+
block has a header followed by its columns. The columns together take at most
124+
1 MiB on disk and at most 1 MiB when decoded. Within a block, samples use
125+
delta compression to minimize redundancy when consecutive samples from the
126+
same thread have identical or similar call stacks. Once the reader loads the
127+
string and frame tables, it can decode each block on its own.
128128

129129
### Block Format
130130

@@ -659,16 +659,25 @@ patterns benefit from kernel read-ahead.
659659

660660
The implementation uses `madvise()` to hint the access pattern to the kernel:
661661
`MADV_SEQUENTIAL` indicates the file will be read linearly, enabling
662-
aggressive read-ahead. `MADV_WILLNEED` requests pre-faulting of pages.
663-
On Linux, `MAP_POPULATE` pre-faults all pages at mmap time rather than on
664-
first access, moving page fault overhead from the parsing loop to the
665-
initial mapping for more predictable performance. For large files (over
666-
32 MB), `MADV_HUGEPAGE` requests transparent huge pages (2 MB instead of
667-
4 KB) to reduce TLB pressure when accessing large amounts of data.
668-
669-
On Windows, the implementation falls back to standard file I/O with full
670-
file buffering. Profiling data files are typically small enough (tens to
671-
hundreds of megabytes) that this is acceptable.
662+
aggressive read-ahead. For large files (over 32 MB), `MADV_HUGEPAGE` requests
663+
transparent huge pages (2 MB instead of 4 KB) to reduce TLB pressure when
664+
accessing large amounts of data. Pages are not loaded up front, only when
665+
replay reaches them.
666+
667+
On Linux, the reader also gives back memory it no longer needs. Once the
668+
string and frame tables have been parsed, and after each sample block has
669+
been replayed, it uses `MADV_DONTNEED` to tell the kernel those pages can be
670+
dropped. The mapping is read-only, so if a dropped page is needed again, the
671+
kernel reads it back from the file. This keeps the memory used for sample
672+
data small, however large the file is.
673+
674+
On Windows, the reader uses standard file I/O instead. When a file is opened,
675+
it only reads the header and the part after the sample data, which holds the
676+
string and frame tables, the statistics and the footer. During replay,
677+
samples are read into a reusable buffer. The reader requests the smaller of
678+
2 MiB and the sample section size. A complete block, including its header,
679+
fits in this buffer. When the buffer runs low, the bytes not yet
680+
replayed are moved to the start and the rest is filled from the file.
672681

673682
The writer buffers samples in the current block and writes each completed
674683
block with a single call, so individual samples never cause a write.

‎Lib/_pyrepl/unix_console.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ def __plan_changed_line(
835835
planned_cells = diff.new_cells
836836
changed_cell = visible_new_cells[0]
837837
return LineUpdate(
838-
kind="insert_char",
838+
kind=("replace_char" if start_x == oldline.width else "insert_char"),
839839
y=y,
840840
start_cell=start_cell,
841841
start_x=start_x,

‎Lib/_pyrepl/utils.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,29 +280,29 @@ def is_soft_keyword_used(*tokens: TI | None) -> bool:
280280
trace("is_soft_keyword_used{t}", t=tokens)
281281
match tokens:
282282
case (
283-
None | TI(T.NEWLINE) | TI(T.INDENT) | TI(string=":"),
283+
None | TI(T.NEWLINE | T.NL | T.INDENT | T.DEDENT) | TI(string=":"),
284284
TI(string="match"),
285285
TI(T.NUMBER | T.STRING | T.FSTRING_START | T.TSTRING_START)
286286
| TI(T.OP, string="(" | "*" | "-" | "+" | "[" | "{" | "~" | "...")
287287
):
288288
return True
289289
case (
290-
None | TI(T.NEWLINE) | TI(T.INDENT) | TI(string=":"),
290+
None | TI(T.NEWLINE | T.NL | T.INDENT | T.DEDENT) | TI(string=":"),
291291
TI(string="match"),
292292
TI(T.NAME, string=s)
293293
):
294294
if keyword.iskeyword(s):
295295
return s in keyword_first_sets_match
296296
return True
297297
case (
298-
None | TI(T.NEWLINE) | TI(T.INDENT) | TI(T.DEDENT) | TI(string=":"),
298+
None | TI(T.NEWLINE | T.NL | T.INDENT | T.DEDENT) | TI(string=":"),
299299
TI(string="case"),
300300
TI(T.NUMBER | T.STRING | T.FSTRING_START | T.TSTRING_START)
301301
| TI(T.OP, string="(" | "*" | "-" | "+" | "[" | "{")
302302
):
303303
return True
304304
case (
305-
None | TI(T.NEWLINE) | TI(T.INDENT) | TI(T.DEDENT) | TI(string=":"),
305+
None | TI(T.NEWLINE | T.NL | T.INDENT | T.DEDENT) | TI(string=":"),
306306
TI(string="case"),
307307
TI(T.NAME, string=s)
308308
):
@@ -312,13 +312,13 @@ def is_soft_keyword_used(*tokens: TI | None) -> bool:
312312
case (TI(string="case"), TI(string="_"), TI(string=":")):
313313
return True
314314
case (
315-
None | TI(T.NEWLINE) | TI(T.INDENT) | TI(T.DEDENT) | TI(string=":"),
315+
None | TI(T.NEWLINE | T.NL | T.INDENT | T.DEDENT) | TI(string=":"),
316316
TI(string="type"),
317317
TI(T.NAME, string=s)
318318
):
319319
return not keyword.iskeyword(s)
320320
case (
321-
None | TI(T.NEWLINE) | TI(T.INDENT) | TI(T.DEDENT) | TI(string=":" | ";"),
321+
None | TI(T.NEWLINE | T.NL | T.INDENT | T.DEDENT) | TI(string=":" | ";"),
322322
TI(string="lazy"),
323323
TI(string="import") | TI(string="from")
324324
):

‎Lib/_pyrepl/windows_console.py‎

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -165,19 +165,16 @@ def __init__(
165165
trace('console supports virtual terminal')
166166

167167
# Save original console modes so we can recover on cleanup.
168-
original_input_mode = DWORD()
169-
if not GetConsoleMode(InHandle, original_input_mode):
170-
raise WinError(get_last_error())
171-
trace(f'saved original input mode 0x{original_input_mode.value:x}')
172-
self.__original_input_mode = original_input_mode.value
168+
assert _winapi is not None # to make mypy happy
169+
self.__original_input_mode = _winapi.GetConsoleMode(InHandle)
170+
trace(f'saved original input mode 0x{self.__original_input_mode:x}')
173171

174-
if not SetConsoleMode(
172+
_winapi.SetConsoleMode(
175173
OutHandle,
176174
ENABLE_WRAP_AT_EOL_OUTPUT
177175
| ENABLE_PROCESSED_OUTPUT
178176
| ENABLE_VIRTUAL_TERMINAL_PROCESSING,
179-
):
180-
raise WinError(get_last_error())
177+
)
181178

182179
self.width = 80
183180
self.height = 25
@@ -474,8 +471,8 @@ def prepare(self) -> None:
474471
self.sync_rendered_screen(RenderedScreen.empty(), self.posxy)
475472

476473
if self.__vt_support:
477-
if not SetConsoleMode(InHandle, self.__original_input_mode | ENABLE_VIRTUAL_TERMINAL_INPUT):
478-
raise WinError(get_last_error())
474+
assert _winapi is not None # to make mypy happy
475+
_winapi.SetConsoleMode(InHandle, self.__original_input_mode | ENABLE_VIRTUAL_TERMINAL_INPUT)
479476
self._enable_bracketed_paste()
480477

481478
def restore(self) -> None:
@@ -484,8 +481,8 @@ def restore(self) -> None:
484481
self.__write(ANSIColors.RESET)
485482
# Recover to original mode before running REPL
486483
self._disable_bracketed_paste()
487-
if not SetConsoleMode(InHandle, self.__original_input_mode):
488-
raise WinError(get_last_error())
484+
assert _winapi is not None # to make mypy happy
485+
_winapi.SetConsoleMode(InHandle, self.__original_input_mode)
489486

490487
def _move_relative(self, x: int, y: int) -> None:
491488
"""Moves relative to the current posxy"""
@@ -661,8 +658,8 @@ def flushoutput(self) -> None:
661658

662659
def forgetinput(self) -> None:
663660
"""Forget all pending, but not yet processed input."""
664-
if not FlushConsoleInputBuffer(InHandle):
665-
raise WinError(get_last_error())
661+
assert _winapi is not None # to make mypy happy
662+
_winapi.FlushConsoleInputBuffer(InHandle)
666663

667664
def getpending(self) -> Event:
668665
"""Return the characters that have been typed but not yet
@@ -815,23 +812,10 @@ class INPUT_RECORD(Structure):
815812
]
816813
ScrollConsoleScreenBuffer.restype = BOOL
817814

818-
GetConsoleMode = _KERNEL32.GetConsoleMode
819-
GetConsoleMode.argtypes = [HANDLE, POINTER(DWORD)]
820-
GetConsoleMode.restype = BOOL
821-
822-
SetConsoleMode = _KERNEL32.SetConsoleMode
823-
SetConsoleMode.argtypes = [HANDLE, DWORD]
824-
SetConsoleMode.restype = BOOL
825-
826815
ReadConsoleInput = _KERNEL32.ReadConsoleInputW
827816
ReadConsoleInput.argtypes = [HANDLE, POINTER(INPUT_RECORD), DWORD, POINTER(DWORD)]
828817
ReadConsoleInput.restype = BOOL
829818

830-
831-
FlushConsoleInputBuffer = _KERNEL32.FlushConsoleInputBuffer
832-
FlushConsoleInputBuffer.argtypes = [HANDLE]
833-
FlushConsoleInputBuffer.restype = BOOL
834-
835819
OutHandle = _winapi.GetStdHandle(_winapi.STD_OUTPUT_HANDLE)
836820
InHandle = _winapi.GetStdHandle(_winapi.STD_INPUT_HANDLE)
837821
else:
@@ -841,9 +825,6 @@ def _win_only(*args, **kwargs):
841825

842826
GetConsoleScreenBufferInfo = _win_only
843827
ScrollConsoleScreenBuffer = _win_only
844-
GetConsoleMode = _win_only
845-
SetConsoleMode = _win_only
846828
ReadConsoleInput = _win_only
847-
FlushConsoleInputBuffer = _win_only
848829
OutHandle = 0
849830
InHandle = 0

0 commit comments

Comments
 (0)