Commit Graph
10655 Commits
Author SHA1 Message Date
Itamar Oren 04862280a2 gh-157384: Set package context in PyImport_CreateModuleFromInitfunc() (GH-157387)
A single-phase init function that creates its module using only the
last component of a dotted name (as pybind11 does for submodules) got
a module whose __name__ was the short name.  Set the package context
while calling the init function, as the dynamic loader does, so the
module gets the full name from the spec.
2026-10-13 13:35:19 +00:00
Pablo Galindo Salgado f892b11f22 gh-153569: Simplify tokenizer source views and reader ownership (#158849)
Move source access and logical spans into the tokenizer source API, and keep input and encoding ownership in the reader. Export the incremental decoder helper for parser generator extensions.
2026-10-13 13:01:17 +00:00
Gregory P. Smith 627eabf31c gh-129724: Intern string constants in the compiler, not per code object (GH-159193)
The compiler merges equal constants of a module through its constant
cache.  intern_constants() then ran on each code object and rebuilt a
frozenset (or, in the free-threaded build, a slice) when one of its
strings was replaced by an already interned one, so a constant shared by
several functions was copied for some of them depending on which strings
happened to be interned in the process.  The class body's __qualname__
constant and co_qualname had the same problem.  marshal then wrote
different bytes for the same source.

Intern the eligible strings of the final constants of each code unit
after optimization and before the code object is created.  Tuples are
updated in place; a frozenset or slice is rebuilt once and stored in the
constant cache so that later units get the same object.  The same code
is used in both builds.

Which strings are interned does not change, except that identifier-like
strings in slice constants are now interned in the default build too.

TestConstantsIdentity compares the identity graph and the marshal
output of code compiled in differently prepared processes, including
names tuples shared with constants.
2026-10-12 21:37:55 -07:00
Gregory P. Smith 48f18f0adb gh-129724: gh-156504: Make marshal output independent of reference counts (GH-159192)
The marshal writer decided whether an object can be referenced later
(FLAG_REF) from its reference count, so the output for the same value
depended on what else in the process held a reference to its parts, and
differed between the default and the free-threaded builds' view of the
same objects.  This is the remaining cause of gh-129724 and the cause of
gh-156504.

FLAG_REF is now set exactly on the objects which are written more than
once in the dump.  The writer still makes one pass: it records the
position of the type byte of each object it remembers and of each
TYPE_REF, and when the dump is complete it sets the flags and renumbers
the references.  A reference count of one is only used to skip the
hashtable.  Interned strings are no longer flagged unconditionally.

The reader is unchanged and the format version is not bumped: both the
old and the new output are loaded by old and new readers.

PyMarshal_WriteObjectToFile() now builds the data in memory and writes
it with one fwrite(), since the flags are only known at the end.
Nothing is written if the object cannot be marshalled.
2026-10-13 04:22:29 +00:00
Victor Stinner 8992704916 gh-144175: Remove internal _PyArg_ParseStack() function (#159150)
Replace internal _PyArg_ParseStack() with public PyArg_ParseArray()
in Argument Clinic.
2026-10-12 19:56:53 +02:00
Suren Nihalani 0babcdd547 gh-152315: Add a suggestion for missing self parameters (GH-152326) 2026-10-12 11:23:35 -04:00
Gregory P. Smith 1967a87ad3 gh-159184: Do not compare set elements when marshalling a set (GH-159196)
Set elements are written in the order of their dumps.  They were sorted
as (dump, element) pairs, so elements with the same dump were compared.
That raised TypeError for a set of several complex NaNs, which the
compiler can produce by constant folding, making the module impossible
to marshal.

Sort (dump, index, element) tuples, in which the indexes are all
different.  Elements with the same dump stay in the order of the set,
as float NaNs did before.
2026-10-11 15:53:04 -07:00
Gregory P. Smith cd71799c47 gh-159185: Fix marshalling of a set modified while its elements are marshalled (GH-159195)
Marshalling a set element can run Python code (__buffer__, an audit
hook) which changes the set.  The number of elements was read before
the loop, so a set which grew was written past the end of the list and
one which shrank left NULL items in the list which was then sorted.
Raise RuntimeError("set changed size during iteration") instead.
2026-10-11 14:09:04 -07:00
Pablo Galindo Salgado e878e1e968 gh-159137: Untrack tuples and count survivors in move_unreachable() (#159154) 2026-10-11 16:01:50 +00:00
Pablo Galindo Salgado fbbf4f48c4 gh-159137: Skip redundant GC resurrection analysis (#159138) 2026-10-10 22:46:49 +00:00
Hood Chatham 0ec3aee262 gh-129040: Use wasm-gc to handle pointer casts in wasi (GH-158617)
This makes it so that in wasi builds if `-DPY_CALL_TRAMPOLINE` is passed, a call trampoline adaptor is used to prevent traps when there is a call signature mismatch between a C slot handler and the signature that the interpreter uses to call it.

This requires Clang >= 22. PEP 11 specifies that builds of Python 3.15 use WASI SDK version 33 which includes clang 23.1.0, so this could be used with Python 3.15 WASI builds but not earlier ones.

It requires a WebAssembly runtime that supports wasm-gc. Wasmtime has supported wasm-gc since version 27.0 released November 25, 2024. Some other runtimes still don't support it, but for those runtimes people can use builds with the trampoline disabled.

This also removed the Emscripten trampoline support for JS runtimes with no wasm-gc support. This removes a lot of implementation complexity and allows WASI and Emscripten to share code. The main concern is that it drops support for some very old iPhones, but every iPhone model released since 2018 is compatible with versions of Safari that support wasm-gc.

Tests were added that define handlers with various wrong numbers of arguments. The tests also run on non-webassembly platforms since they should work there as well.
2026-10-09 22:25:44 +00:00
Brittany Reynoso a6e636148e gh-158820: Add null checks to avoid segfaults with lazy imports at shutdown (GH-158821)
Destructors can run after finalization has cleared the interpreter's
lazy_modules set and lazy_pending_submodules dict. Declaring or
resolving a lazy import from one of them passed NULL to PySet_Add(),
PySet_Discard() or the pending-submodules lookup.

Treat the bookkeeping as a no-op once the state is gone, as the other
readers of this state already do.
2026-10-09 13:57:05 +02:00
Victor Stinner 15dd7356f3 gh-158893: Add internal _Py_strerror() function (#158982)
Add a new internal _Py_strerror() function to Python/fileutils.c. It
uses strerror_r() if available, or use strerror() otherwise.

Replace all strerror(code) calls with _Py_strerror(code).
2026-10-07 20:31:27 +00:00
Bhuvansh 7d3fca4e04 gh-153354: Fix bool conversion in generated __annotate__ (#153360) 2026-10-06 19:34:54 -07:00
Victor Stinner 6318730aee gh-158893: Make os.strerror() thread-safe (#158927)
Make os.strerror() thread-safe: use the reentrant strerror_r()
function if available.

* The configure script now checks if strerror_r() is supported.
* Add a stress test to test_free_threading.test_os (new module).
* Add a comment on decode_current_locale() assertion which fails if
  the input string is mutated.
* Add an assertion to _Py_DecodeLocale() to detect if the input
  string was mutated during the function call.
2026-10-06 23:02:13 +02:00
Pablo Galindo Salgado 114de198c0 gh-156545, gh-158539: Fix deep flamegraph export on small C stacks and macOS runtime lookup (#158874) 2026-10-05 20:56:24 +01:00
3f9118f1d1 gh-151157: Speed up PyObject_CallMethod via _PyObject_GetMethod (#151158)
* Speed up PyObject_CallMethod via _PyObject_GetMethod

PyObject_CallMethod (and _PyObject_CallMethod, PyEval_CallMethod,
_PyObject_CallMethodId and the _SizeT variant) resolved the method with
PyObject_GetAttr, which builds a temporary bound-method object on every call,
then called it.

Resolve the method with _PyObject_GetMethod instead (the same lookup the
interpreter uses for obj.name(...)) and call it directly via
_PyObject_VectorcallPrepend, skipping the bound-method allocation.  Behaviour
is unchanged: same attribute semantics, same "attribute of type ... is not
callable" error, and the historical
PyObject_CallMethod(o, m, "O", tuple) -> o.m(*tuple) unpacking.

The shared helper callmethod() and _PyObject_CallMethodFormat() are no longer
needed: their only caller (traceback.c) now uses PyObject_CallFunction, so both
are removed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Use _PyObject_GetMethodStackRef so method calls scale in free-threading

Resolve the method in callmethod_va() via _PyObject_GetMethodStackRef()
instead of _PyObject_GetMethod(). The StackRef variant returns the method
as a deferred reference, avoiding the per-call atomic refcount on the
shared method object that otherwise serializes threads in the
free-threaded build.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* rename to callmethod

* review comments

* review comments

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Co-authored-by: Inada Naoki <songofacandy@gmail.com>
2026-10-05 18:44:28 +00:00
cfd6cf7154 gh-157407: Use _PyUnicode_AsUTF8NoNUL for AC 's' and 'z' converters (#158210)
* gh-157407: Use _PyUnicode_AsUTF8NoNUL for AC 's' and 'z' converters

The code was doing the same as the helper added in GH-111957 but inline.
That resulted in significantly more `.text` for most functions. Refactor
the Arguemnt Clinic converters code to deduplicate a bit while keeping
generated code close to original.

On my Linux x64 box this reduces `.text` by ~6200 bytes in a clang
release build (no PGO or LTO). Performance is flat.

The helper was already exported for `_sqlite3`, update the comment that
it is used in AC generated code as well.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* Update Include/internal/pycore_unicodeobject.h

Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>

* Remove NEWS, add period

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
2026-10-05 17:03:27 +00:00
Pablo Galindo Salgado 0b8aa89a05 gh-153569: Simplify tokenizer state (#158124)
* Use diagnostic line for missing-brace errors

* Keep implicit prepared newline metadata in the reader

* Reuse parsed formatted string kind in lexer

* Transfer owned tokenizer encoding strings

* Remove unused tokenizer state and redundant branches

* Avoid rescanning partial decoded tokenizer lines

* Reuse prepared tokenizer line terminators for CR detection

* Reuse interactive tokenizer chunks without carriage returns

* Release tokenizer constructor resources on allocation failure

* Narrow interactive newline normalization wrapper

* Close duplicated tokenizer descriptors when fdopen fails

* Preserve cached tokenizer lines when newline allocation fails

* Collect cycles involving tokenizer readline callbacks

* Preserve buffered text when decoding source files

* Clear the transferred syntax error line before cleanup

* Propagate tokenizer column conversion failures

* Allocate parser repetition buffers on first match

* Allocate type comment storage only when needed

* Reuse decoded multiline text when counting token columns

* Skip empty decoded tokenizer chunks

* Check parser array growth before allocating

* Name tokenizer bounds and derive byte lengths from their data

* Set the tokenizer exception when file input size overflows

* gh-153569: Send exact line endings in the REPL test

* Share parser repetition buffer growth

* Fold Unicode input coverage into the existing REPL test

* Keep parser array growth policy private

* Drop obsolete bitmap stress from source discard test

* Preserve input failures while scanning string literals

* fixup! Preserve input failures while scanning string literals

* fixup! fixup! Preserve input failures while scanning string literals

* gh-153569: Remove assertion-only lexer bookkeeping
2026-10-05 14:28:51 +01:00
Victor Stinner 30ce3d462d gh-158585: Simplify PyBytesWriter_Finish() (#158822)
PyBytesWriter_Finish() doesn't need to check the size. It's known to
be valid.

PyBytesWriter_Create() now only calls byteswriter_resize() if the
size is larger than the small buffer.

Remove byteswriter_data() function: call static inline
_PyBytesWriter_GetData() function directly.
2026-10-05 04:47:04 +02:00
Maurycy Pawłowski-WierońskiandPablo Galindo Salgado 5fecd448bb gh-155811: Add a seqcount to gc_stats to prevent torn reads (#155828)
* update_seq

* no need for XCHGL, MOVL is enough?

* gh-155811: Retry an inconsistent GC snapshot once

---------

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2026-10-05 01:49:56 +00:00
Stan UlbrychandVictor Stinner b93fb19a6e Run a job that the test suite with MSan to the CI (#158625)
* Run the test suite with MSan in CI

* Additional fixes

* Add `_Py_MSAN_UNPOISON_STRING`

* Apply Victor's suggestions

Co-authored-by: Victor Stinner <victor.stinner@gmail.com>

* Apply Victor's suggestions

Co-authored-by: Victor Stinner <victor.stinner@gmail.com>

---------

Co-authored-by: Victor Stinner <victor.stinner@gmail.com>
2026-10-05 02:11:42 +01:00
Maurycy Pawłowski-WierońskiandPablo Galindo Salgado 7d25916b41 gh-154194: Degrade frames in Tachyon instead of failing the sample (#154195)
* degrade gracefully

* news

* better NEWS wording

* do not raise on MAX_REMOTE_STR_READ

* bye MAX_REMOTE_STR_READ

* fix -m asyncio ps|pstree

* test truncation and linetable sentinel

* simpler

* simpler

* redundant now

* respect #157790 in the news

---------

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2026-10-05 00:37:21 +00:00
Victor Stinner d19febb00c Rework locale encoding C functions (#158680)
Add output_length to _Py_EncodeLocale(), _Py_EncodeUTF8(),
encode_current_locale() and encode_ascii(). So unicode_encode_locale() and
wstr_to_utf8() can now use the output_length, instead of having to compute
strlen().

* Rename functions:

  * _Py_DecodeUTF8Ex() => _Py_DecodeUTF8()
  * _Py_EncodeUTF8Ex() => _Py_EncodeUTF8()
  * _Py_EncodeLocaleEx() => _Py_EncodeLocale()
  * _Py_DecodeLocaleEx() => _Py_DecodeLocale()

* Add tests on Py_DecodeLocale() and Py_EncodeLocale() in test_codecs.
  Clarify also their documentation.
* _Py_EncodeLocale() and _Py_DecodeLocale() now sets all output parameters on
  error. Add more tests on these output parameters.
* Add encode_current_locale_impl() to simplify encode_current_locale().
* Remove reason parameter of _Py_EncodeLocale() and _Py_DecodeLocale() to
  simplify the code. Only the UTF-8 decoder used specific reasons.
* _Py_EncodeUTF8() now uses size_t instead of Py_ssize_t to iterate
  on the input string.
* On error, encode_current_locale_impl() now returns ENCODE_ERROR (new
  constant) instead of DECODE_ERROR.
* Mark _Py_EncodeLocaleRaw() as static (it's not used outside fileutils.c).
2026-10-04 23:22:18 +02:00
Pengyu Lee 1b015e66f0 gh-157906: fix an incorrect architecture macro check in free-threaded GC (gh-157907)
Fix typo in free-threaded GC prefetch check for 32-bit x86 MSVC.
2026-10-03 11:36:01 -07:00
Victor Stinner b42fdf6b44 Fix _PyOS_GetOpt() error message for non-ASCII characters (#158626)
Replace %c with %lc.
2026-10-03 15:37:58 +02:00
Victor Stinner f5e913c7f7 gh-158445: Allocate memory in the heap in Py_GetVersion() (#158608)
Py_GetVersion() now allocates memory on the heap, instead of using a
static buffer, to no longer truncate the version if it's longer than
299 bytes.

Update Py_GetCompiler() and Py_GetBuildInfo() tests: they are now
always a part of sys.version.
2026-10-03 15:15:08 +02:00
Bhuvansh 20d5e67fc5 gh-156204: Guard recursion in PyErr_GivenExceptionMatches (GH-156205) 2026-10-02 16:22:05 -04:00
00a1c3a0c9 gh-158140: Resolve lazily imported sibling submodules independently (#158521)
* gh-158140: Resolve lazy siblings through the pending-child registry

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: T. Wouters <thomas@python.org>
2026-10-02 19:20:04 +02:00
be87a85e2f gh-155695: Remove resolved names from sys.lazy_modules more consistently (#157714)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
2026-10-02 19:17:48 +03:00
a6a63b6f5b gh-142349: Simplify lazy import resolution (#158282)
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2026-10-01 16:20:45 +00:00
Victor Stinner 82fcaf881c Cleanup Python/getopt.c: add _PyOS_GetOpt structure (#158362)
Replace global variables with a new _PyOS_GetOpt structure:

* _PyOS_opterr => getopt->error
* _PyOS_optind => getopt->index
* _PyOS_optarg => getopt->arg

Changes:

* Add tests to test_cmd_line.
* Rename _PyOS_ResetGetOpt() to _PyOS_GetOpt_Init(). Add argc and
  argv parameters.
* Don't expose longindex in the structure, it's only used internally.
* Move _PyOS_LongOption structure from the internal C API to
  getopt.c.
2026-10-01 14:58:55 +00:00
John 0906d2ab93 gh-157468: Validate correct builtins used under JIT (GH-157766)
* Expose two possible builtin JIT gaps

* Add trace and runtime guard for builtin dict

* Check _GUARD_BUILTINS_IS_CANONICAL once per frame

* Add check and fix for globals being folded
2026-10-01 12:15:51 +01:00
An Long 1071f7400e gh-155823: Fix stale stack on _SEND_VIRTUAL_TIER_TWO exhausted exit (GH-155844) 2026-10-01 12:08:48 +01:00
Jun Luo 069c74a6b7 gh-157833: Fix specialized C calls with additional method flags (GH-157834) 2026-09-30 14:37:24 +01:00
Lukas Geiger 83de667b25 gh-158072: Fix JIT crash with omitted default arguments (GH-158128) 2026-09-30 14:32:18 +01:00
Hai Zhu b98c065756 gh-158380: Fix the stack operand used by JIT dict access guards (GH-158381) 2026-09-30 14:18:13 +01:00
Gregory P. Smith b7b4f3ecf2 gh-158446: Reject float format precision near INT_MAX (GH-158474)
Formatting a float or complex with a precision within about 1000 of
INT_MAX could crash or produce incorrect output.
PyOS_double_to_string() now raises ValueError("precision too big") for
such precisions, as the format string parsers already do for
precisions above INT_MAX.

The limit applies regardless of presentation type or value, so a few
calls that previously succeeded (inf, nan, or 'g' with such a
precision) now raise as well.
2026-09-30 05:22:37 +00:00
Himesh Rupchandani c3cb46870b gh-158364: Don't report other interpreters' threads in sys._current_frames (GH-158369) 2026-09-29 22:24:24 -04:00
Pengyu LeeandVictor Stinner aa287d7f44 gh-158241: Prevent double release of assembler byte writers (#158242)
Co-authored-by: Victor Stinner <vstinner@python.org>
2026-09-29 10:48:11 +00:00
Daniele Parmeggiani baec76438e gh-157914: Revert "gh-135871: Reload lock internal state while spinning in PyMutex_LockTimed (gh-146064)" (gh-158082) 2026-09-27 17:29:07 +00:00
Serhiy Storchaka dc590064bd gh-155496: Use Argument Clinic for more functions and methods (GH-158134)
Convert to Argument Clinic:

* builtins dir() and vars()
* property.__set_name__()
* memoryview.__exit__()
* structseq __replace__()
* types.SimpleNamespace.__replace__()
* re.Match.group()
* sys.getsizeof() and sys.set_asyncgen_hooks()
* atexit.register()
* os.scandir() iterator __exit__()
* _dbm, _gdbm and _decimal context manager __exit__()
* _functools lru_cache __copy__() and __deepcopy__()
* _elementtree.SubElement()
* _interpreters.new_config()
* _tkinter call() and wantobjects()
* zoneinfo.ZoneInfo.__init_subclass__()
* internal hamt and stdprinter methods
2026-09-27 19:00:22 +03:00
Brittany ReynosoandPablo Galindo Salgado 1e8ff18a12 gh-157757: Fix to make lazy import a.b as c import the module a.b (#158092)
* Import the module a lazy `import a.b as c` names

`import a.b as c` compiles to `IMPORT_NAME a.b` followed by `IMPORT_FROM b`.
Lazily, IMPORT_NAME leaves a placeholder holding "a.b", and IMPORT_FROM
rewrote it into the placeholder `lazy from a import b` produces.  Reification
then imported `a` alone and read `b` off it, so the module `a.b` was never
imported under its own name: an attribute of the package shadowing it answered
instead, and `math.pi`, which no module backs, bound the float where the eager
statement raises ModuleNotFoundError.

Mark the dotted import on the placeholder and keep the whole name on it.
Reification imports that name and then walks its components with IMPORT_FROM,
which is what the eager statement does.

The test pinning `lazy import math.pi as pi` as working is inverted, since the
eager statement raises.

* Stop excluding test_trace from the lazy-imports-all run

It passes now that a lazy `import a.b as c` imports the module: the
KeyError on 'test.tracedmodules.testmod' came from the submodule never
being imported under its own name.

* Rename lz_submodule to lz_dotted_as and trim the comments

The flag means "bind the whole dotted name, not the root", which the old
name did not say, and import.c already has unrelated lazy_pending_submodules
machinery to be confused with.

* Chain lazy IMPORT_FROM placeholders instead of flagging dotted imports

Each deferred IMPORT_FROM off a placeholder without a fromlist now keeps
the previous placeholder in lz_from and the attribute name in lz_attr.
Reification walks back to the placeholder IMPORT_NAME left, runs that
import, and replays the lookups in order with _PyEval_ImportFrom, which
is what the eager bytecode does.  This drops the lz_dotted_as flag and
also follows a custom __lazy_import__ that returns a placeholder for a
different module name.

* Chain every deferred IMPORT_FROM onto the previous placeholder

`lazy from a import b` now records its lookup the same way as `import
a.b as c`, so a placeholder holds either the module name and fromlist or
the previous placeholder and an attribute name, and reification has a
single path.  The import passes only the name being resolved as the
fromlist, so accessing b still does not import the other names'
submodules.

* Treat an empty fromlist on a lazy import placeholder as no fromlist

__import__("a.b", fromlist=()) returns the top-level package `a`, the same
as fromlist=None, but the placeholder kept the empty tuple.  Every consumer
of lz_attr then read it as a real fromlist: reification narrowed it to the
chained attribute and replayed the lookups on `a.b`, _PyEval_LazyImportFrom
took the attribute off sys.modules["a.b"], and the repr named `a.b.attr`.

_PyLazyImport_New already collapses None to NULL for exactly this reason,
so collapse an empty tuple there too and every site follows.

* gh-157757: Preserve empty fromlists for custom import hooks

---------

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2026-09-26 20:19:25 +00:00
Marc MuellerandPieter Eendebak 972cfaae3f gh-138912: Add fast path for match class patterns without sub-patterns (#144820)
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
2026-09-26 13:00:10 -07:00
Marc Mueller 109a192eb5 gh-151907: Reduce duplication in codegen comprehension functions (GH-154846) 2026-09-26 12:49:38 -04:00
Trent Nelson f156510960 gh-151518: Avoid STW starvation of attaching threads (#152826)
* gh-151518: Avoid STW starvation of attaching threads

Free-threaded stop-the-world pauses can otherwise starve a thread trying to reattach after it was suspended while detached.  A tight manual gc.collect() loop can release and immediately request the next stop-the-world pause, repeatedly parking the detached thread before it can attach and make progress.

Add a distinct _Py_THREAD_SUSPENDED_DETACHED state for tstates parked from DETACHED.  tstate_wait_attach() marks an attach waiter only after observing that detached-origin suspended state, and park_detached_threads() skips only those active waiters on later stop-the-world passes.  The ordinary successful tstate_try_attach() path remains the baseline CAS-only path.

Teach the related stop-the-world paths about both suspended states, including start_the_world() and tstate_delete_common().  Keep the new wait flag after the existing hot free-threaded _PyThreadStateImpl fields so their offsets do not move.

Add a free-threaded GC regression test that runs a subprocess with a tight gc.collect() worker and verifies the main thread can reattach after sleeping and stop the worker.

* gh-151518: Track attach waiters in the thread state

Represent active attach waiters with suspended-waiting and
detached-waiting states. Preserve waiter registration when the
world resumes, and keep passive detached threads immediately parkable.

Restore the thread-state padding and retain the single-CAS
uncontended attach path.

* gh-151518: Simplify the GC fairness regression

Use explicit warmup imports and a joined non-daemon collector.
Run the child through script_helper with a faulthandler watchdog
so a stalled attachment still fails with a traceback.

Describe the bug as a fairness issue in the NEWS entry.

* gh-151518: Exercise STW fairness directly

* gh-151518: Preserve attach waiters when resuming BRC suspensions

Share the waiter-aware resume transition between stop-the-world pauses
and biased reference count merging so a concurrently registering waiter
keeps its opportunity to attach.

Restore the support import needed by the new upstream GC regression and
align the thread-state constants.

* gh-151518: Strengthen the STW attach fairness regression

Hold each test pause for 10 ms and repeat pauses in C to reduce the
opportunities for a waiting thread to run between pause requests.

Clarify that parking rechecks the thread state before sleeping.

* gh-151518: Restrict STW test pauses to free-threaded builds

STW is a no-op in GIL builds. Avoid waiting in the helper there,
since WASI cannot perform the blocking futex operation.

* gh-151518: Wake only registered attach waiters

Avoid a parking-lot lookup when resuming a suspended thread that
has not tried to reattach. Use the old state from the successful CAS
so concurrent waiter registration still receives a wakeup.
2026-09-25 11:24:14 -07:00
Victor Stinner fe7717c611 gh-158080: Py_InitializeFromConfig() no longer exits Python (#158085)
If a command line option wants to exit Python, move this option
processing from PyConfig_Read() to Py_Main(). So
Py_InitializeFromInitConfig() and Py_InitializeFromConfig() can no
longer return an exit code.

Deprecate PyInitConfig_GetExitCode(), PyStatus_Exit(), and PyStatus_IsExit()
functions, and PyStatus.exitcode member.

Renumber getopt.c long options to start at 1, instead of 0.
2026-09-25 11:34:05 +00:00
sobolevnandPablo Galindo Salgado dbac44740f gh-145868: Suggest names on typos in __future__ imports (#154347)
* gh-145868: Suggest names on typos in `__future__` imports

* Address review

* Address review

* gh-145868: Suggest only valid future features

---------

Co-authored-by: Pablo Galindo Salgado <pablogsal@gmail.com>
2026-09-24 16:29:48 +00:00
Victor Stinner 7242fea93c gh-158001: Remove global configuration variables from C API (#158020)
Keep 4 variables in the stable ABI:

* Py_FileSystemDefaultEncodeErrors
* Py_FileSystemDefaultEncoding
* Py_HasFileSystemDefaultEncoding
* Py_UTF8Mode

Mark the 4 variables as ABI only in Misc/stable_abi.toml.
2026-09-24 16:42:02 +02:00
Victor Stinner a5a4659548 gh-158001: Remove Py_SetProgramName() function (#158024)
Remove Py_SetProgramName(), Py_SetPythonHome(), PySys_SetArgv() and
PySys_SetArgvEx() functions, deprecated since Python 3.11.

Mark the 4 functions as abi_only in stable_abi.toml.
2026-09-24 12:52:54 +02:00