Commit graph

10223 commits

Author SHA1 Message Date
Victor Stinner
9159287f58
gh-144175: Add PyArg_ParseArray() function (#144283)
Add PyArg_ParseArray() and PyArg_ParseArrayAndKeywords()
functions to parse arguments of functions using the METH_FASTCALL
calling convention.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2026-03-06 21:57:44 +00:00
Victor Stinner
4fce98a920
gh-141510: Change marshal version to 6 (#145551)
Fix SliceTestCase: test also that version 4 fails with ValueError.
2026-03-06 10:23:11 +01:00
Victor Stinner
c0ecf211b2
gh-145055: Accept frozendict for globals in exec() and eval() (#145072) 2026-03-05 12:35:43 +01:00
Victor Stinner
31343cf2bc
gh-142417: Restore private _Py_InitializeMain() function (#145472)
This reverts commit 07c3518ffb.

Co-authored-by: Petr Viktorin <encukou@gmail.com>
2026-03-04 11:00:08 +01:00
Jelle Zijlstra
bd13cc09fa
gh-145376: Fix various reference leaks (GH-145377) 2026-03-03 16:23:30 +01:00
Donghee Na
6908372fb8
gh-145214: Narrow _GUARD_TOS_ANY_{SET,DICT} by using probable type (gh-145215) 2026-03-03 09:58:38 +09:00
Filipe Laíns
eb611a8515
GH-145275: add -X pathconfig_warnings and PYTHON_PATHCONFIG_WARNINGS (#145277) 2026-03-02 19:19:05 +00:00
Hai Zhu
107863ee17
gh-144569: Avoid creating temporary objects in BINARY_SLICE for list, tuple, and unicode (GH-144590)
* Scalar replacement of BINARY_SLICE for list, tuple, and unicode
2026-03-02 17:02:38 +00:00
Bartosz Sławecki
8bcb3eaa67
gh-144851: Fix __lazy_import__ crash with user-defined filters (#144852) 2026-03-02 12:01:32 +01:00
Petr Viktorin
3b276f3f59
gh-144748: Make PyErr_CheckSignals raise the exception scheduled by PyThreadState_SetAsyncExc (GH-145178)
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2026-03-02 11:47:32 +01:00
Taegyun Kim
c2d3d6b0dd
gh-144316: Fix missing exception in _remote_debugging with debug=False (#144442) 2026-02-26 21:14:34 +00:00
Hood Chatham
43fdb7037e
gh-145037: Fix Emscripten trampoline with emcc >= 4.0.19 (#145038)
This undoes a change made as a part of PR 137470, for compatibility with EMSDK
4.0.19. It adds `emscripten_trampoline` field in `pycore_runtime_structs.h`
and initializes it from JS initialization code with the wasm-gc based trampoline
if possible. Otherwise we fall back to the JS trampoline.
2026-02-26 06:21:05 +08:00
Hai Zhu
277a03711b
gh-145197: Fix JIT trace crash when recording function from cleared generator frame (GH-145220) 2026-02-25 16:52:53 +00:00
Stan Ulbrych
5e61a16c10
gh-145187: Fix crash on invalid type parameter bound expression in conditional block (GH-145188)
Fix parsing crash found by oss-fuzz
2026-02-24 12:44:57 -08:00
Donghee Na
0f759f1171
gh-145122: Add _GUARD_NOS_ANY_DICT to prevent STORE_SUBSCR_DICT on frozendict (gh-145039) 2026-02-25 00:48:45 +09:00
Gregory P. Smith
ad4ee7cb0f
gh-144015: Add portable SIMD optimization for bytes.hex() et. al. (GH-143991)
Add SIMD optimization for `bytes.hex()`, `bytearray.hex()`, and `binascii.hexlify()` as well as `hashlib` `.hexdigest()` methods using platform-agnostic GCC/Clang vector extensions that compile to native SIMD instructions on our [PEP-11 Tier 1 Linux and macOS](https://peps.python.org/pep-0011/#tier-1) platforms.

- 1.1-3x faster for common small data (16-64 bytes, covering md5 through sha512 digest sizes)
- Up to 11x faster for large data (1KB+)
- Retains the existing scalar code for short inputs (<16 bytes) or platforms lacking SIMD instructions, no observable performance regressions there.

## Supported platforms:

- x86-64: the compiler generates SSE2 - always available, no flags or CPU feature checks needed
- ARM64: NEON is always available, always available, no flags or CPU feature checks needed
- ARM32: Requires NEON support and that appropriate compiler flags enable that (e.g., `-march=native` on a Raspberry Pi 3+) - while we _could_ use runtime detection to allow neon when compiled without a recent enough `-march=` flag (`cortex-a53` and later IIRC), there are diminishing returns in doing so. Anyone using 32-bit ARM in a situation where performance matters will already be compiling with such flags. (as opposed to 32-bit Raspbian compilation that defaults to aiming primarily for compatibility with rpi1&0 armv6 arch=armhf which lacks neon)
- Windows/MSVC: Not supported. MSVC lacks `__builtin_shufflevector`, so the existing scalar path is used. Leaving it as an opportunity for the future for someone to figure out how to express the intent to that compiler.

This is compile time detection of features that are always available on the target architectures. No need for runtime feature inspection.
2026-02-22 19:19:03 -08:00
Hai Zhu
fd01372d4e
gh-145064: Fix JIT assertion failure during CALL_ALLOC_AND_ENTER_INIT side exit (GH-145100) 2026-02-22 18:46:03 +00:00
Chris Eibl
5944a539b9
Fix warnings on main (GH-145104) 2026-02-22 19:02:15 +08:00
Rudi Heitbaum
faea32b729
gh-145092: Fix compiler warning for memchr() and wcschr() returning const pointer (GH-145093) 2026-02-22 10:01:27 +02:00
Victor Stinner
2be2dd5fc2
gh-145076: Check globals type in __lazy_import__() (#145086) 2026-02-21 22:06:59 +01:00
Stan Ulbrych
e1bd0cd37b
gh-145058: Add input validation to _PyImport_LazyImportModuleLevelObject (#145068) 2026-02-21 12:52:40 +00:00
Bénédikt Tran
34f4fa8425
gh-141226: Deprecate PEP-456 support for embedders (#141287)
Deprecate PEP-456 [1] support for providing an external definition
of the string hashing scheme. Removal is scheduled for Python 3.19.

Previously, embedders could define the ``Py_HASH_ALGORITHM`` macro to be
``Py_HASH_EXTERNAL`` [2] to indicate that the hashing scheme was provided
externally but this feature was undocumented, untested and most likely
unused.

[1]: https://peps.python.org/pep-0456/
[2]: https://peps.python.org/pep-0456/#hash-function-selection
2026-02-21 12:42:13 +01:00
Alper
a56532771a
gh-144981: Make PyUnstable_Code_SetExtra/GetExtra thread-safe (#144980)
* Make PyUnstable_Code_SetExtra/GetExtra thread-safe
2026-02-20 10:52:18 -08:00
Chris Eibl
b5c8e6e133
gh-100239: Use `PyFloat_AS_DOUBLE and _PyLong_IsZero`` in the float / compactlong specializations (#144826) 2026-02-19 21:45:59 +02:00
David Peter
1d099164bc
gh-144702: Use standard terminology in class pattern error message (#144703) 2026-02-19 13:31:13 +00:00
Mark Shannon
3f37b94c73
GH-144651: Optimize the new uops added when recording values during tracing. (GH-144948)
* Handle dependencies in the optimizer, not the tracer
* Strengthen some checks to avoid relying on optimizer for correctness
2026-02-19 11:52:57 +00:00
Donghee Na
3e2f5c133f
gh-141510: Update specializer to support frozendict (gh-144949) 2026-02-19 01:10:53 +09:00
Victor Stinner
83f4fffe3d
gh-144763: Don't detach the GIL in tracemalloc (#144779)
tracemalloc no longer detaches the GIL to acquire its internal lock.

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2026-02-18 15:57:48 +00:00
Sam Gross
6577d870b0
gh-144438: Fix false sharing between QSBR and tlbc_index (gh-144554)
Align the QSBR thread state array to a 64-byte cache line boundary
and add padding at the end of _PyThreadStateImpl. Depending on heap
layout, the QSBR array could end up sharing a cache line with a
thread's tlbc_index, causing QSBR quiescent state updates to contend
with reads of tlbc_index in RESUME_CHECK. This is sensitive to
earlier allocations during interpreter init and can appear or
disappear with seemingly unrelated changes.

Either change alone is sufficient to fix the specific issue, but both
are worthwhile to avoid similar problems in the future.
2026-02-17 11:12:25 -05:00
Victor Stinner
696cdfc0a2
gh-141510, PEP 814: Add built-in frozendict type (#144757)
Add TYPE_FROZENDICT to the marshal module.

Add C API functions:

* PyAnyDict_Check()
* PyAnyDict_CheckExact()
* PyFrozenDict_Check()
* PyFrozenDict_CheckExact()
* PyFrozenDict_New()

Add PyFrozenDict_Type C type.

Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: Adam Johnson <me@adamj.eu>
Co-authored-by: Benedikt Johannes <benedikt.johannes.hofer@gmail.com>
2026-02-17 10:54:41 +01:00
Benedikt Johannes
645f5c4a73
gh-144822: remove redundant decref in codegen.c (#144823) 2026-02-14 19:20:33 +00:00
Chris Eibl
caac966b00
fix warnings in jit builds (GH-144817) 2026-02-14 17:39:10 +00:00
Chris Eibl
14cbd0e6af
remove unused _PyFunction_LookupByVersion (GH-144814) 2026-02-14 14:09:01 +00:00
Yilei
5922149a50
gh-144766: Fix a crash in fork child process when perf support is enabled. (#144795) 2026-02-14 11:41:28 +00:00
Marc Mueller
75d4839fa9
gh-138912: Improve MATCH_CLASS opcode performance (GH-138915)
Only check for duplicates if there is at least one positional pattern.
With a test case for duplicate keyword attributes.
2026-02-13 21:06:15 -08:00
Pablo Galindo Salgado
072cd7c336
gh-142349: Fix refcount corruption in lazy import specialization (#144733)
Remove spurious Py_DECREF on borrowed ref in LOAD_GLOBAL specialization

_PyDict_LookupIndexAndValue() returns a borrowed reference via
_Py_dict_lookup(), but specialize_load_global_lock_held() called
Py_DECREF(value) on it when bailing out for lazy imports. Each time
the adaptive counter fired while a lazy import was still in globals,
this stole one reference from the dict's object. With 8+ threads
racing through LOAD_GLOBAL during concurrent lazy import resolution,
enough triggers accumulated to drive the refcount to zero while the
dict and other threads still referenced the object, causing
use-after-free.
2026-02-12 11:45:28 +00:00
Pablo Galindo Salgado
46d5106cfa
gh-142349: Implement PEP 810 - Explicit lazy imports (#142351)
Co-authored-by: T. Wouters <twouters@meta.com >
Co-authored-by: Brittany Reynoso <breynoso@meta.com>
Co-authored-by: Dino Viehland <dinoviehland@meta.com>
2026-02-12 00:15:33 +00:00
Sacul
6c8ca1c378
gh-134584: Optimize _BINARY_OP_SUBSCR_LIST_SLICE (GH-144659) 2026-02-10 22:33:32 +08:00
Gregory P. Smith
ac8b5b6890
gh-143650: Fix importlib race condition on import failure (GH-143651)
Fix a race condition where a thread could receive a partially-initialized
module when another thread's import fails. The race occurs when:

1. Thread 1 starts importing, adds module to sys.modules
2. Thread 2 sees the module in sys.modules via the fast path
3. Thread 1's import fails, removes module from sys.modules
4. Thread 2 returns a stale module reference not in sys.modules

The fix adds verification after the "skip lock" optimization in both Python
and C code paths to check if the module is still in sys.modules. If the
module was removed (due to import failure), we retry the import so the
caller receives the actual exception from the import failure rather than
a stale module reference.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-10 14:08:33 +01:00
Pablo Galindo Salgado
2c1ca6bb5b
gh-144563: Fix remote debugging with duplicate libpython mappings from ctypes (#144595)
When _ctypes is imported, it may call dlopen on the libpython shared
library, causing the dynamic linker to load a second mapping of the
library into the process address space. The remote debugging code
iterates memory regions from low addresses upward and returns the first
mapping whose filename matches libpython. After _ctypes is imported, it
finds the dlopen'd copy first, but that copy's PyRuntime section was
never initialized, so reading debug offsets from it fails.

Fix this by validating each candidate PyRuntime address before accepting
it. The validation reads the first 8 bytes and checks for the "xdebugpy"
cookie that is only present in an initialized PyRuntime. Uninitialized
duplicate mappings will fail this check and be skipped, allowing the
search to continue to the real, initialized PyRuntime.
2026-02-10 10:04:50 +00:00
Steve Dower
a9b6788ae6
gh-144278: Enable overriding sys.implementation's name and cache_tag when building sysmodule.c (GH-144293)
Changing the values requires forking and patching, which is intentional. Simply rebuilding from source does not change the implementation enough to justify changing these values - they would still be `cpython` and compatible with existing `.pyc` files. But people who maintain forks are better served by being able to easily override these values in a place that can be forward-ported reliably.
2026-02-10 00:01:17 +00:00
Peter Bierma
fd6b639a49
gh-144601: Avoid sharing exception objects raised in a PyInit function across multiple interpreters (GH-144602) 2026-02-09 16:57:03 +01:00
Hai Zhu
988286e510
gh-144623: Fix missing output uops in optimizer debug output (GH-144617) 2026-02-09 13:23:02 +00:00
Sacul
cfeede85a7
GH-131798: Optimize _GUARD_TOS_SLICE (GH-144470) 2026-02-08 18:08:26 +00:00
Ken Jin
895e83727d
gh-144549: Fix tail calling interpreter on Windows for FT (GH-144550) 2026-02-06 19:20:28 +00:00
Sam Gross
0fdf6a9a71
gh-144513: Skip critical section locking during stop-the-world (gh-144524)
When the interpreter is in a stop-the-world pause, critical sections
don't need to acquire locks since no other threads can be running.
This avoids a potential deadlock where lock fairness hands off ownership
to a thread that has already suspended for stop-the-world.
2026-02-06 15:14:08 +00:00
Sam Gross
5bb3bbb9c6
gh-144446: Fix some frame object thread-safety issues (gh-144479)
Fix thread-safety issues when accessing frame attributes while another
thread is executing the frame:

- Add critical section to frame_repr() to prevent races when accessing
  the frame's code object and line number

- Add _Py_NO_SANITIZE_THREAD to PyUnstable_InterpreterFrame_GetLasti()
  to allow intentional racy reads of instr_ptr.

- Fix take_ownership() to not write to the original frame's f_executable
2026-02-06 09:43:36 -05:00
Sam Gross
d891b2bbd1
gh-139103: Improve namedtuple scaling in free-threaded build (gh-144332)
Add `_Py_type_getattro_stackref`, a variant of type attribute lookup
that returns `_PyStackRef` instead of `PyObject*`. This allows returning
deferred references in the free-threaded build, reducing reference count
contention when accessing type attributes.

This significantly improves scaling of namedtuple instantiation across
multiple threads.

* Add blurb

* Rename PyObject_GetAttrStackRef to _PyObject_GetAttrStackRef

* Apply suggestion from @vstinner

Co-authored-by: Victor Stinner <vstinner@python.org>

* Apply suggestion from @vstinner

Co-authored-by: Victor Stinner <vstinner@python.org>

* format

* Update Include/internal/pycore_function.h

Co-authored-by: Victor Stinner <vstinner@python.org>

---------

Co-authored-by: Victor Stinner <vstinner@python.org>
2026-02-06 09:43:05 -05:00
Zackery Spytz
01a1dd283b
gh-77188: Add support for pickling private methods and nested classes (GH-21480)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2026-02-05 19:50:51 +00:00
Mark Shannon
b53fc7caa6
GH-144179: Use recorded values to make optimizer more robust (GH-144437)
* Add three new symbol kinds
* Do not smuggle code object in _PUSH_FRAME operand
* Fix small bug in predicate analysis
2026-02-05 08:58:41 +00:00