Commit Graph

10488 Commits

Author SHA1 Message Date
Mark Shannon c6982439ee GH-148874: Make sure that mngr.__exit__() is always called in a with statement (GH-150911)
* Even if there is an interrupt during the call to mngr.__enter__()
2026-07-01 15:15:33 +01:00
Brij Kapadia a3dc7849a3 gh-145857: Replace DELETE_GLOBAL with PUSH_NULL; STORE_GLOBAL (GH-146314) 2026-06-30 19:04:56 +01:00
Brij Kapadia c393ab61d9 gh-145854: Replace DELETE_NAME with PUSH_NULL; STORE_NAME (GH-146006) 2026-06-30 17:21:31 +01:00
Petr Vaganov 10ed03edf1 gh-152682: Fix NULL dereference on OOM in symtable_visit_type_param_bound_or_default (#152684)
In `symtable_visit_type_param_bound_or_default()`, when a reserved name
(e.g. `__classdict__`) is used as a type parameter, `PyUnicode_FromFormat()`
is called to build the SyntaxError message. If the allocation fails and
returns NULL, the subsequent `PyErr_SetObject()` and `Py_DECREF()` calls
would dereference NULL, causing a segfault.

Fix by returning 0 immediately when `PyUnicode_FromFormat()` returns NULL.
This propagates the MemoryError set by `PyUnicode_FromFormat()`.

The bug was introduced in gh-128632 (commit 891c61c).
2026-06-30 14:45:25 +00:00
sobolevn ecdef17730 gh-151126: Fix a possible crash during the startup with no memory under Py_STACKREF_DEBUG (#152478) 2026-06-30 14:28:17 +03:00
Timofei 9e10f14b92 gh-152192: Fix JUMP_BACKWARD passing a truncated oparg to the jit tracer (GH-152382) 2026-06-30 10:46:59 +01:00
Serhiy Storchaka bc3fa17c30 gh-82312: Further improvement of error messages for generating AST nodes (GH-150912)
This is a follow up of GH-17715.

* Use %T instead of _PyType_Name().
* Add the wrong type name we got for identifier and string.
2026-06-30 01:03:33 +03:00
Stan Ulbrych cdec9acd63 gh-152375: Fix undefined behaviour in the INSTRUMENTED_JUMP macro (#152376) 2026-06-29 11:06:04 +02:00
Brandt Bucher 2d0003c0b2 GH-151672: __lazy_import__ always resolves to the module being imported (#151827) 2026-06-29 00:13:12 +01:00
Brandt Bucher 7ed9062dd0 GH-151619: Ensure non-module global/builtin namespaces are watched for lazy imports (#151762) 2026-06-28 23:24:32 +01:00
Pablo Galindo Salgado 8cda6ae2f1 gh-151613: Fix remote debugging frame cache ABA (#151614)
The remote debugging frame cache previously used only the last_profiled_frame address as its cache anchor. If a frame returned and a later frame reused the same _PyInterpreterFrame address, the profiler could accept a stale cache entry and splice parent frames from a different call chain into the current stack.

This adds a last_profiled_frame_seq counter next to last_profiled_frame, increments it when the anchor advances, stores it in frame cache entries, and validates cache hits against both the frame address and the sequence. Cache miss walks now copy stack chunks before storing new cache entries so stored continuations come from a stable snapshot. The new regression test exercises alternating call chains and checks that cached stacks never contain frames from both branches.
2026-06-27 16:56:31 +00:00
Łukasz Langa a69d0fc41e gh-151029: Fix sys.remote_exec() unable to find writable memory when libpython replaced on disk (#151032)
Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
2026-06-27 16:21:15 +00:00
Neil Schemenauer 9626ef87f4 gh-152238: Revert gh-150490 and gh-152200. (gh-152232)
Revert commits:
    gh-151593: Fix dead lock in PyDict insert_split_key() (#152200)
    gh-150490: Raise PyType_Modified for insertion into split dictionary (#150489)

For gh-150489, it violates locking discipline and results in deadlocks,
gh-151593 is an example of it being hit in CI.  The attempted fix 
gh-152200 avoids the deadlock but introduces a data-race.  The race
window is small but can be triggered with pure Python code.
2026-06-26 11:20:41 -07:00
Marc Mueller 56ae0b8e4f gh-148825: Fix build error if specialization is disabled (#148826) 2026-06-25 14:06:22 +00:00
Amrutha 5e0747db2f gh-151842: Fix crash upon OOM in _interpreters.capture_exception (GH-151843) 2026-06-23 16:31:47 -04:00
dev d35b1719a5 gh-151773: Fix NULL dereference in PyContextVar_Set (#151836) 2026-06-23 17:15:15 +03:00
Timofei 7782794850 gh-151665: Fix inspect.signature() on type alias and type parameter evaluators (#151837) 2026-06-21 15:08:01 -07:00
Hood Chatham d701f8edbe gh-145177: Bump Emscripten to 6.0.0 (#151611)
Bumps Emscripten to 6.0.0, and fixes related issues in getentropy() and umask().
2026-06-19 07:29:33 +08:00
Mark Shannon ad1513a263 GH-150516: Reduce the work done to spill and reload the stack around calls (GH-151587) 2026-06-18 15:14:30 +01:00
Maurycy Pawłowski-Wieroński a8d74c062f gh-151436: Fix missing tstate->last_profiled_frame updates (#151437) 2026-06-17 16:49:23 -04:00
AN Long eff805b7a7 gh-151510: Fix __lazy_import__ without frame (#151511) 2026-06-17 14:09:51 -04:00
Victor Stinner 9a61d1c0c8 gh-151546: Fix stack limits on musl (#151548)
If the thread stack size is set by linker flags, pass the stack size
to Python/ceval.c via the new _Py_LINKER_THREAD_STACK_SIZE variable
to set Py_C_STACK_SIZE macro.
2026-06-17 10:23:57 +02:00
Daniele Parmeggiani c2ca7724af gh-150902: Optimize PyCriticalSection2 to skip locking the same locks held by the current CS2
This mimics an optimization already present for the single-mutex critical section.
2026-06-16 16:56:37 +00:00
Victor Stinner b16d23fc9f gh-151218: Replace sys.flags in PyConfig_Set() (#151402)
PyConfig_Set() and sys.set_int_max_str_digits() now replace
sys.flags (create a new object), instead of modifying sys.flags in-place.

Modifying sys.flags in-place can lead to data races when multiple
threads are reading or writing sys.flags in parallel.

Use _Py_atomic functions to get and set max_str_digits members.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2026-06-16 16:17:33 +00:00
Kumar Aditya e9d5280f6c gh-151223: fix tsan data races in load global specializations (#151393) 2026-06-15 22:09:49 +05:30
Victor Stinner 552ce57e33 gh-139227: Remove unused _PyRuntime.imports.pkgcontext (#151490)
The global variable has been replaced by a new thread local variable
"pkgcontext" in Python/import.c.
2026-06-15 10:23:04 +00:00
Dino Viehland efb2fffae1 gh-150490: Raise PyType_Modified for insertion into split dictionary (#150489)
Raise PyType_Modified for insertion into split dictionary
2026-06-11 09:38:31 -07:00
Stan Ulbrych 937d89c4d9 gh-151112: Fix crash in compiler_mod() when entering the current compilation unit fails (#151234) 2026-06-11 15:52:11 +01:00
Stan Ulbrych 2d3381035d gh-151112: Move an assert that may fail in cfg_builder_check (#151153) 2026-06-11 10:16:27 +01:00
Victor Stinner e60c42dc3f gh-151278: Fix test_faulthandler on UBSan (#151279)
* Py_FatalError() no longer calls _PyFaulthandler_Fini() if it
  doesn't hold the GIL.
* Skip test_faulthandler tests raising signals if run with UBSan.
* Enable test_faulthandler in GitHub Action "Reusable Sanitizer".
2026-06-10 21:39:03 +02:00
Victor Stinner 7b6e98911e gh-151253: Dump the Python path configuration on _PyCodec_InitRegistry() failure (#151250)
If "import encodings" fails at Python startup, dump the Python path
configuration to help users debugging their configuration. The
encodings module is the first module imported during Python startup.
2026-06-10 18:43:38 +02:00
Bartosz Sławecki ce916dc506 gh-150700: Fix class-scope inline comprehensions when nested scopes reference __class__ and friends (#150735)
* Fix class-scope inline comprehensions when nested scopes reference `__class__` and friends

In `inline_comprehension()`, when `__class__` / `__classdict__` /
`__conditional_annotations__` appears as `FREE` in a comprehension's
symbol table because a nested scope captured it (e.g. nested lambdas),
this name is still discarded from `comp_free` unconditionally.

This prevents `drop_class_free()` from seeing it, so the appropriate
`ste_needs_(...)` flag is never set on the enclosing class.
That leads to `codegen_make_closure()` throwing `SystemError` when it
couldn't find `__class__` / `__classdict__` /
`__conditional_annotations__` in the class's cellvars.

From now on we just discard from `comp_free` when no child scope
(e.g. a lambda) still needs the name as `FREE`. When a child scope does
need it, keep it in `comp_free` so `drop_class_free()` can set the
appropriate flag and the class creates the implicit cell.

* Fix tests

* Fix typo

* Fix formatting

* Add test checking validity of `__class__` returned

* Prefer 'used' to 'deferred'
2026-06-09 15:22:13 -07:00
Stan Ulbrych 580499177c gh-151112: Fix double free in assemble_init when out of memory (#151142) 2026-06-09 20:45:54 +01:00
sobolevn 3186547c1e gh-151126: Fix missing PyErr_NoMemory() in remove_unused_consts (#151127) 2026-06-09 10:03:33 +00:00
Thomas Kowalski 54de5475cd gh-150633: Properly handle null characters in the name when importing frozen modules (GH-150634) 2026-06-08 21:31:54 +03:00
Victor Stinner 0036565e81 gh-146527: Fix memory leak in _PyGC_Fini() (#150969)
Free generation_stats allocated by _PyGC_Init().

Fix Python/gc.c: Python/gc_free_threading.c was already fixed.
2026-06-05 13:43:05 +00:00
Batuhan Taskaya 3ff2117ea3 bpo-38131: Improve messages when generating AST nodes from objects with wrong field values (GH-17715) 2026-06-04 10:58:51 +00:00
Nazım Can Altınova 494f2e3c92 gh-150723: Fix perf jitdump files on macOS (#150728)
The perf jitdump format defines the thread id field of the JR_CODE_LOAD
record as a 32-bit value, but on macOS it was declared as a uint64_t
(since pthread_threadid_np() returns a uint64_t). Those extra 8 bytes
plus alignment padding shifted every following field, so parsers reading
the file by the spec misread code_size as the code address and failed to
resolve any Python frames.

Declare thread_id as uint32_t on all platforms and truncate the macOS
thread id when writing the record. The value is only informational.
Symbols are resolved by address, and not thread ids so truncation is
safe here.

* Use mach_absolute_time for macOS jitdump timestamps

On macOS the jitdump file is consumed by profilers such as samply, which
timestamp their samples using mach_absolute_time(). The jitdump events were
stamped with clock_gettime(CLOCK_MONOTONIC), a different clock domain that
keeps advancing while the system is asleep, so the JIT code mappings could be
off by days relative to the samples and no Python frame would resolve. Stamp
jitdump events with mach_absolute_time() on macOS so they share the sampler's
clock domain. Linux continues to use CLOCK_MONOTONIC to stay aligned with perf.

Exercise the -Xperf_jit (jitdump) backend through samply and assert that
Python frames resolve, exercising the binary jitdump path end to end.
Skipped when samply is not installed.
2026-06-03 01:15:34 +01:00
Stephen Rosen 50fe49c879 gh-150319: Replace all documentation which says "See PEP 585" (#150325)
* Replace all documentation which says "See PEP 585"

The following classes in the stdlib get simple updates:

- array.array
- asyncio.Future
- asyncio.Task
- collections.defaultdict
- collections.deque
- contextvars.ContextVar
- contextvars.Token
- ctypes.Array
- os.DirEntry
- re.Match
- re.Pattern
- string.templatelib.Interpolation
- string.templatelib.Template
- types.MappingProxyType
- queue.SimpleQueue
- weakref.ref

The following classes are documented publicly as functions, and are
therefore updated internally (`__class_getitem__.__doc__`) but not in the
public docs:

- functools.partial
- itertools.chain

The following builtin types have updates to `__class_getitem__.__doc__`
but not to any documentation pages:

- BaseExceptionGroup
- coroutines (from generators)
- dict
- enumerate
- frozendict
- frozenset
- generators (and async generators)
- list
- memoryview
- set
- slice
- tuple

Special cases:

- union objects are now documented as "supporting class-level []",
  rather than anything to do with generics.

- Templates might be generic over a single type (union, in theory) or
  over a TypeVarTuple. As this is not currently fully settled, it is
  marked with a comment and a mild hint that it is a single type is used
  (namely, "type" is singular rather than "types", plural)

* Apply suggestions from code review

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>

* Correct several class getitem docs

And expand the text for tuples.

Co-authored-by: Jelle Zijlstra <906600+JelleZijlstra@users.noreply.github.com>

* Add notes on generic typing of builtins

* Fix typo in tuple.__class_getitem__ docstring

* Typo fix: malformed refs

Fix `generic` links which weren't marked as `:ref:`.

* Strike unnecessary docs on generic-ness

Co-authored-by: Jelle Zijlstra <906600+JelleZijlstra@users.noreply.github.com>

* Apply suggestions from code review

These are applied at both the originally indicated locations and in the
corresponding docstring definitions.

Co-authored-by: Alex Waygood <66076021+AlexWaygood@users.noreply.github.com>

* Update Doc/library/re.rst

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>

* Update Objects/enumobject.c

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>

* Remove tuple generic doc in 'stdtypes' page

This is covered in more detail in the cross-linked typing documentation.
The other copy of this documentation -- in the docstring for
`tuple.__class_getitem__` -- is left in place.

* Fix whitespace around new doc of generics

Per review, do not introduce or remove whitespace such that section
breaks are altered by the introduction of doc on various generic types.

In most cases, this is a removal of an extra line.

In one case (Arrays), it is the reintroduction of a line.

Additionally, two other minor fixes are included:
- incorrect indent on 'defaultdicts'
- make `mappingproxy.__class_getitem__.__doc__` consistent with other
  mapping type generic docs

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>

* Move placement of memoryview generic note

Previous placement was at the end of the main docstring, which is
consistent with other types but places it after a section on various
methods (which makes it read somewhat inconsistently). Moving it up
helps resolve.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>

* Ensure sphinxdoc does not start sentences lowercase

Lowercase class names at the start of sentences are marked out with the
`class` role. In the case of `deque`, documentation already refers to
these as `Deques`, so this form is preferred.

* Apply suggestions from code review

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>

* Fix line endings and wrap more tightly

Line endings fixed by pre-commit ; also re-wrapped the MappingProxyType
text which was too long.

* Use 'ContextVars' style in sphinx doc

---------

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Jelle Zijlstra <906600+JelleZijlstra@users.noreply.github.com>
Co-authored-by: Alex Waygood <66076021+AlexWaygood@users.noreply.github.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2026-06-02 21:13:34 +01:00
Stan Ulbrych c52d2b16dd gh-149805: Fix SystemError when compiling __classdict__ class annotation (#149806) 2026-06-02 10:17:03 +01:00
Bartosz Sławecki 5a2d2736a6 gh-150052: Resolve un-loaded lazily loaded submodules via module.__getattr__ instead of publishing lazy values (#150055) (#150744) 2026-06-02 09:58:51 +01:00
Russell Keith-Magee 71fc4c66d3 gh-150644: Tag Apple system log messages as public. (#150645)
macOS 26 changed the default visibility of "dynamic" system messages. This
changes the logging strategy to tag all messages as "public" so they are
visible in the system log without special configuration.
2026-06-02 06:25:46 +08:00
Mark Shannon 633b6be8f5 GH-148960: Reduce the size of the debug stencils to less than half. (GH-150551)
For AArch64 linux, reduces the total bytes in the code bodies from 489kb to 218kb.
Reduces the size of the stencils files from 394k lines to 167k lines.
2026-06-01 17:56:16 +01:00
Langyan 13fee461c2 Fix typos in InternalDocs/compiler.md (#149915) 2026-05-29 15:44:20 +05:30
pengyu lee 686996e4d8 gh-150454: Fix wrong-interpreter return in import_run_extension error path (#150455) 2026-05-29 15:33:37 +05:30
Bartosz Sławecki 1d4e965829 gh-148587: Make sys.lazy_modules match PEP and keep internal lazy submodules tracking internal (#150086)
Make sys.lazy_modules match PEP and keep internal lazy submodules tracking internal

Co-authored-by: Dino Viehland <dinoviehland@meta.com>
2026-05-28 17:55:47 -07:00
Neko Asakura 39bd44fc70 gh-148871: make LOAD_COMMON_CONSTANT use immortal stackref borrows (GH-149625) 2026-05-28 12:27:37 +01:00
Serhiy Storchaka 8ab7b43a14 gh-62259: Add support of multi-byte encodings in the XML parser (GH-149860)
Supported encodings: "cp932", "cp949", "cp950", "Big5","EUC-JP",
"GB2312", "GBK", "johab", and "Shift_JIS".

Partially supported encodings (only BMP characters): "Big5-HKSCS",
"EUC_JIS-2004", "EUC_JISX0213", "Shift_JIS-2004", "Shift_JISX0213",
"utf-8-sig" and non-standard aliases like "UTF8" (without hyphen).

The parser now raises ValueError for known unsupported
multi-byte encodings such us "ISO-2022-JP" or "raw-unicode-escape"
instead of failing later, when encounter non-ASCII data.
2026-05-26 19:40:25 +00:00
Mark Shannon a6793662e7 GH-126910: Make _Py_get_machine_stack_pointer return the actual stack pointer (GH-149103)
* Make _Py_ReachedRecursionLimit inline again
* Remove _Py_MakeRecCheck replacing its use with _Py_ReachedRecursionLimit
* Move the check for C stack swtiching into _Py_CheckRecursiveCall
2026-05-26 15:14:17 +01:00
Pablo Galindo Salgado a5be25d3bd gh-149619: Harden _remote_debugging error paths (#150349) 2026-05-25 23:22:46 +01:00