Skip to content

Commit e8498dd

Browse files
committed
Merge branch 'main' into gh-146311-nonzero-padding-bits
2 parents b618655 + c64baff commit e8498dd

17 files changed

+707
-11
lines changed

Doc/library/subprocess.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,12 @@ functions.
627627
the value in ``pw_uid`` will be used. If the value is an integer, it will
628628
be passed verbatim. (POSIX only)
629629

630+
.. note::
631+
632+
Specifying *user* will not drop existing supplementary group memberships!
633+
The caller must also pass ``extra_groups=()`` to reduce the group membership
634+
of the child process for security purposes.
635+
630636
.. availability:: POSIX
631637
.. versionadded:: 3.9
632638

Doc/using/cmdline.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,13 @@ conflict.
13381338

13391339
.. versionadded:: 3.13
13401340

1341+
.. envvar:: PYTHON_BASIC_COMPLETER
1342+
1343+
If this variable is set to any value, PyREPL will use :mod:`rlcompleter` to
1344+
implement tab completion, instead of the default one which uses colors.
1345+
1346+
.. versionadded:: 3.15
1347+
13411348
.. envvar:: PYTHON_HISTORY
13421349

13431350
This environment variable can be used to set the location of a

Include/internal/pycore_obmalloc.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,11 @@ struct _obmalloc_state {
691691

692692

693693
/* Allocate memory directly from the O/S virtual memory system,
694-
* where supported. Otherwise fallback on malloc */
694+
* where supported. Otherwise fallback on malloc.
695+
*
696+
* Large-page and huge-page backends may round the mapped size up
697+
* internally, so pass the original requested size back to
698+
* _PyObject_VirtualFree(). */
695699
void *_PyObject_VirtualAlloc(size_t size);
696700
void _PyObject_VirtualFree(void *, size_t size);
697701

InternalDocs/interpreter.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,38 @@ After the last `DEOPT_IF` has passed, a hit should be recorded with
507507
After an optimization has been deferred in the adaptive instruction,
508508
that should be recorded with `STAT_INC(BASE_INSTRUCTION, deferred)`.
509509

510+
## Interpreter types
511+
There are three different types of interpreters to choose from based on compiler support:
512+
513+
* traditional switch-case interpreter
514+
515+
Supported by all compilers covered in PEP 7.
516+
517+
* computed-gotos interpreter
518+
519+
Enabled using configure option `--with-computed-gotos` and used by default on supported compilers.
520+
It uses [Labels as Values](https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html)
521+
for more efficient dispatching.
522+
523+
* tail-calling interpreter
524+
525+
Enabled using configure option `--with-tail-call-interp` (or `--tail-call-interp` for build.bat on Windows).
526+
It uses [tail calls](https://clang.llvm.org/docs/AttributeReference.html#musttail) and the
527+
[preserve_none](https://clang.llvm.org/docs/AttributeReference.html#preserve-none)
528+
calling convention between the small C functions that implement individual Python opcodes.
529+
530+
Not all compilers support these and if they do not all targets might be supported (for example,
531+
MSVC currently only supports x64 and only in optimized builds).
532+
533+
In addition, compilers must do [escape analysis](https://gcc.gnu.org/onlinedocs/gcc/Common-Attributes.html#index-musttail)
534+
of the lifetimes of automatic variables, function parameters, and temporaries to ensure proper tail-calls. They
535+
emit a compile error in case of a violation or detection failure. The ability to detect this varies depending on the compiler and
536+
also on the optimization level. Following techniques are particularly helpful to the MSVC compiler in this regard
537+
* [Introducing additional scopes](https://github.com/python/cpython/blob/3908593039bde9d4b591ab09919003ee57418d64/Python/bytecodes.c#L2526)
538+
* [extracting problematic code paths into a separate function](https://github.com/python/cpython/pull/143068/files#diff-729a985b0cb8b431cb291f1edb561bbbfea22e3f8c262451cd83328a0936a342R3724)
539+
* [returning a pointer instead of taking it as an output parameter](https://github.com/python/cpython/blob/3908593039bde9d4b591ab09919003ee57418d64/Include/internal/pycore_ceval.h#L489-L492)
540+
541+
Using `restrict` is another (currently unused) remedy.
510542

511543
Additional resources
512544
--------------------

Lib/_colorize.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
class ANSIColors:
1717
RESET = "\x1b[0m"
18-
1918
BLACK = "\x1b[30m"
2019
BLUE = "\x1b[34m"
2120
CYAN = "\x1b[36m"
@@ -200,6 +199,30 @@ class Difflib(ThemeSection):
200199
reset: str = ANSIColors.RESET
201200

202201

202+
@dataclass(frozen=True, kw_only=True)
203+
class FancyCompleter(ThemeSection):
204+
# functions and methods
205+
function: str = ANSIColors.BOLD_BLUE
206+
builtin_function_or_method: str = ANSIColors.BOLD_BLUE
207+
method: str = ANSIColors.BOLD_CYAN
208+
method_wrapper: str = ANSIColors.BOLD_CYAN
209+
wrapper_descriptor: str = ANSIColors.BOLD_CYAN
210+
method_descriptor: str = ANSIColors.BOLD_CYAN
211+
212+
# numbers
213+
int: str = ANSIColors.BOLD_YELLOW
214+
float: str = ANSIColors.BOLD_YELLOW
215+
complex: str = ANSIColors.BOLD_YELLOW
216+
bool: str = ANSIColors.BOLD_YELLOW
217+
218+
# others
219+
type: str = ANSIColors.BOLD_MAGENTA
220+
module: str = ANSIColors.CYAN
221+
NoneType: str = ANSIColors.GREY
222+
bytes: str = ANSIColors.BOLD_GREEN
223+
str: str = ANSIColors.BOLD_GREEN
224+
225+
203226
@dataclass(frozen=True, kw_only=True)
204227
class LiveProfiler(ThemeSection):
205228
"""Theme section for the live profiling TUI (Tachyon profiler).
@@ -354,6 +377,7 @@ class Theme:
354377
"""
355378
argparse: Argparse = field(default_factory=Argparse)
356379
difflib: Difflib = field(default_factory=Difflib)
380+
fancycompleter: FancyCompleter = field(default_factory=FancyCompleter)
357381
live_profiler: LiveProfiler = field(default_factory=LiveProfiler)
358382
syntax: Syntax = field(default_factory=Syntax)
359383
traceback: Traceback = field(default_factory=Traceback)
@@ -364,6 +388,7 @@ def copy_with(
364388
*,
365389
argparse: Argparse | None = None,
366390
difflib: Difflib | None = None,
391+
fancycompleter: FancyCompleter | None = None,
367392
live_profiler: LiveProfiler | None = None,
368393
syntax: Syntax | None = None,
369394
traceback: Traceback | None = None,
@@ -377,6 +402,7 @@ def copy_with(
377402
return type(self)(
378403
argparse=argparse or self.argparse,
379404
difflib=difflib or self.difflib,
405+
fancycompleter=fancycompleter or self.fancycompleter,
380406
live_profiler=live_profiler or self.live_profiler,
381407
syntax=syntax or self.syntax,
382408
traceback=traceback or self.traceback,
@@ -394,6 +420,7 @@ def no_colors(cls) -> Self:
394420
return cls(
395421
argparse=Argparse.no_colors(),
396422
difflib=Difflib.no_colors(),
423+
fancycompleter=FancyCompleter.no_colors(),
397424
live_profiler=LiveProfiler.no_colors(),
398425
syntax=Syntax.no_colors(),
399426
traceback=Traceback.no_colors(),

Lib/_pyrepl/_module_completer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
# Standard library submodules that are not detected by pkgutil.iter_modules
2424
# but can be imported, so should be proposed in completion
2525
"collections": ["abc"],
26+
"math": ["integer"],
2627
"os": ["path"],
2728
"xml.parsers.expat": ["errors", "model"],
2829
}

Lib/_pyrepl/completing_reader.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,14 @@ def do(self) -> None:
178178
if not completions:
179179
r.error("no matches")
180180
elif len(completions) == 1:
181-
if completions_unchangable and len(completions[0]) == len(stem):
181+
completion = stripcolor(completions[0])
182+
if completions_unchangable and len(completion) == len(stem):
182183
r.msg = "[ sole completion ]"
183184
r.dirty = True
184-
r.insert(completions[0][len(stem):])
185+
r.insert(completion[len(stem):])
185186
else:
186-
p = prefix(completions, len(stem))
187+
clean_completions = [stripcolor(word) for word in completions]
188+
p = prefix(clean_completions, len(stem))
187189
if p:
188190
r.insert(p)
189191
if last_is_completer:
@@ -195,7 +197,7 @@ def do(self) -> None:
195197
r.dirty = True
196198
elif not r.cmpltn_menu_visible:
197199
r.cmpltn_message_visible = True
198-
if stem + p in completions:
200+
if stem + p in clean_completions:
199201
r.msg = "[ complete but not unique ]"
200202
r.dirty = True
201203
else:
@@ -215,7 +217,7 @@ def do(self) -> None:
215217
r.cmpltn_reset()
216218
else:
217219
completions = [w for w in r.cmpltn_menu_choices
218-
if w.startswith(stem)]
220+
if stripcolor(w).startswith(stem)]
219221
if completions:
220222
r.cmpltn_menu, r.cmpltn_menu_end = build_menu(
221223
r.console, completions, 0,

0 commit comments

Comments
 (0)