Commit graph

6317 commits

Author SHA1 Message Date
Victor Stinner
9e5e1f9988
gh-121617: Include <string.h> for Py_CLEAR() macro (#144666)
Python.h now also includes <string.h> in the limited C API version 3.11
and newer to fix the Py_CLEAR() macro which uses memcpy().

Add a Py_CLEAR() test in test_cext.

Modify also _Py_TYPEOF to use C23 typeof() if available.
2026-02-12 17:03:55 +01:00
Pablo Galindo Salgado
7854597d88
gh-142349: Fix build errors from PEP 810 (#144726) 2026-02-12 08:18:36 +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
Hugo van Kemenade
cf23fcd5f7 Merge branch 'main' of https://github.com/python/cpython 2026-02-11 17:34:44 +02:00
Hugo van Kemenade
7cfeb8c756 Post 3.15.0a6 2026-02-11 17:33:36 +02:00
Kumar Aditya
347d3594d3
gh-143300: implement PyUnstable_SetImmortal for marking objects as immortal (#144543) 2026-02-11 20:59:31 +05:30
Hugo van Kemenade
15b216f30d Python 3.15.0a6 2026-02-11 14:23:15 +02:00
Victor Stinner
3dadc22a27
gh-141563: Add missing cast to _PyDateTime_IMPORT() (#144667)
Fix compilation on C++.

Add test on PyDateTime_IMPORT in test_cext and test_cppext.
2026-02-10 14:47:12 +00:00
Sacul
6c8ca1c378
gh-134584: Optimize _BINARY_OP_SUBSCR_LIST_SLICE (GH-144659) 2026-02-10 22:33:32 +08:00
Alper
73fa6be2fe
gh-144490: Fix mimalloc debug build for C++ (#144620) 2026-02-10 11:56:52 +01:00
Kumar Aditya
dd30f16ac0
gh-141563: make PyDateTime_IMPORT thread-safe (#144210) 2026-02-09 13:20:35 +00:00
Alper
a2495ff1e7
gh-144490: Fix C++ compatibility in pycore_cell.h (GH-144482) 2026-02-06 22:11:58 -05:00
Ken Jin
895e83727d
gh-144549: Fix tail calling interpreter on Windows for FT (GH-144550) 2026-02-06 19:20:28 +00:00
kangtastic
45d4a34720
gh-101178: Add Ascii85, Base85, and Z85 support to binascii (GH-102753)
Add Ascii85, Base85, and Z85 encoders and decoders to binascii,
replacing the existing pure Python implementations in base64.

This makes the codecs two orders of magnitude faster and consume
two orders of magnitude less memory.

Note that attempting to decode Ascii85 or Base85 data of length 1 mod 5
(after accounting for Ascii85 quirks) now produces an error, as no
encoder would emit such data. This should be the only significant
externally visible difference compared to the old implementation.

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2026-02-06 16:43:16 +02: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
Sam Gross
7e2c9bdc98
gh-120321: Add gi_state, cr_state, and ag_state attributes (gh-144409)
Add `gi_state`, `cr_state`, and `ag_state` attributes to generators,
coroutines, and async generators respectively. These attributes return the
current state as a string (e.g., `GEN_RUNNING`, `CORO_SUSPENDED`).

The `inspect.getgeneratorstate()`, `inspect.getcoroutinestate()`, and
`inspect.getasyncgenstate()` functions now return these attributes directly.

This is in preparation for making `gi_frame` thread-safe, which may involve
stop-the-world synchronization. The new state attributes avoid potential
performance cliffs in `inspect.getgeneratorstate()` and similar functions by
not requiring frame access.

Also removes unused `FRAME_COMPLETED` state and renumbers the frame state enum
to start at 0 instead of -1.
2026-02-03 13:06:32 -05:00
Mark Shannon
141fd8b894
GH-144179: Add value recording to JIT tracing front-end (GH-144303) 2026-02-02 16:57:04 +00:00
Hai Zhu
ebbb2ca81f
gh-144145: Revert PR#144122 for performance and potential bugs. (GH-144391)
Revert "gh-144145: Track nullness of properties in the Tier 2 JIT optimizer (GH-144122)"

This reverts commit 1dc12b2883.
2026-02-02 14:09:54 +00:00
Pablo Galindo Salgado
96e4cd698a
gh-144319: Fix huge page safety in pymalloc arenas (#144331)
The pymalloc huge page support had two problems. First, on
architectures where the default huge page size exceeds the arena
size (e.g. 32 MiB on PPC, 512 MiB on ARM64 with 64 KB base
pages), mmap with MAP_HUGETLB silently allocates a full huge page
even when the requested size is smaller. The subsequent munmap
with the original arena size then fails with EINVAL, permanently
leaking the entire huge page. Second, huge pages were always
attempted when compiled in, with no way to disable them at
runtime. On Linux, if the huge page pool is exhausted, page
faults including copy-on-write faults after fork deliver SIGBUS
and kill the process.

The arena allocator now queries the system huge page size from
/proc/meminfo and skips MAP_HUGETLB when the arena size is not a
multiple of it. Huge pages also now require explicit opt-in at
runtime via the PYTHON_PYMALLOC_HUGEPAGES environment variable,
which is read through PyConfig and respects -E and -I flags.
The config field pymalloc_hugepages is propagated to the runtime
allocators struct so the low-level arena allocator can check it
without calling getenv directly.
2026-01-30 18:18:56 +00:00
Sam Gross
a01694dacd
gh-120321: Make gi_yieldfrom thread-safe in free-threading build (#144292)
Add a FRAME_SUSPENDED_YIELD_FROM_LOCKED state that acts as a brief
lock, preventing other threads from transitioning the frame state
while gen_getyieldfrom reads the yield-from object off the stack.
2026-01-30 12:20:27 -05:00
Hai Zhu
1dc12b2883
gh-144145: Track nullness of properties in the Tier 2 JIT optimizer (GH-144122) 2026-01-30 15:25:19 +00:00
Pablo Galindo Salgado
b1bc868fba
gh-144319: Add huge pages support for pymalloc (#144320) 2026-01-29 12:26:11 +00:00
Sam Gross
6ea3f8cd7f
gh-144289: Remove ENABLE_SPECIALIZATION_FT (gh-144290)
Now that the specializing interpreter works with free threading,
replace ENABLE_SPECIALIZATION_FT with ENABLE_SPECIALIZATION and
replace requires_specialization_ft with requires_specialization.

Also limit the uniquely referenced check to FOR_ITER_RANGE. It's not
necessary for FOR_ITER_GEN and would cause test_for_iter_gen to fail.
2026-01-27 17:52:50 -05:00
Diego Russo
66055d0650
GH-126910: add test for manual frame unwinding (#144137) 2026-01-27 13:17:40 +00:00
Nathan Goldbaum
f2b5c206c7
gh-143883: Use named parameters in PyModExport-related declarations & docs (GH-143884) 2026-01-27 10:28:28 +00:00
Serhiy Storchaka
7febbe6b60
gh-144001: Support ignorechars in binascii.a2b_base64() and base64.b64decode() (GH-144024) 2026-01-26 20:11:40 +02:00
AN Long
6e55337f8a
gh-143995: Eliminate redundant refcounting in the JIT from LOAD_ATTR_MODULE (GH-143996) 2026-01-25 18:24:44 +00:00
reiden
6d972e0104
gh-130415: Narrow types to constants in branches involving specialized comparisons with a constant (GH-144150) 2026-01-24 10:02:08 +00:00
AN Long
4e10fa993a
gh-144007: Eliminate redundant refcounting in the JIT for BINARY_OP (GH-144011) 2026-01-24 09:35:32 +00:00
AN Long
2f42f83344
gh-144005: Eliminate redundant refcounting in the JIT for BINARY_OP_EXTEND (#144006) 2026-01-23 17:19:01 +00:00
Mark Shannon
d77aaa7311
GH-139109: Partial reworking of JIT data structures (GH-144105)
* Halve size of buffers by reusing combined trace + optimizer buffers for TOS caching
* Add simple buffer struct for more maintainable handling of buffers
* Decouple JIT structs from thread state struct
* Ensure terminator is added to trace, when optimizer gives up
2026-01-22 10:55:49 +00:00
reiden
0b08438ea6
gh-130415: Narrowing to constants in branches involving is comparisons with a constant (GH-143895) 2026-01-22 09:37:45 +00:00
Mark Shannon
9eab67d507
GH-138245: Perform boolean guards by testing a single bit, rather than a full pointer comparison. (GH-143810) 2026-01-21 15:58:27 +00:00
Sergey B Kirpichev
4c7ec78092
gh-143869: Add PEP 757 functions to the limited API (#143906)
Co-authored-by: Petr Viktorin <encukou@gmail.com>
2026-01-21 14:47:14 +01:00
Donghee Na
27a7160b8b
gh-141504: Move PYTHON_UOPS_OPTIMIZE to policy object (GH-144082) 2026-01-20 18:47:38 +00:00
AN Long
54bedcf714
gh-144012: Check null binary op extend (#144014) 2026-01-19 02:38:37 +08:00
Hai Zhu
b4b73245d8
gh-143421: Use new buffer to save optimized uops (GH-143682) 2026-01-17 15:52:16 +00:00
Hai Zhu
61ec66acd5
gh-143946: Show JitOptSymbol on abstract stack when set PYTHON_OPT_DEBUG > 4 (GH-143957) 2026-01-17 15:20:35 +00:00
Ken Jin
7e28ae550f
gh-142913: Export JIT functions for _testinternalcapi (#143958)
* Export JIT functions for _testinternalcapi

* Add testinternalcapi to paths to run JIT CI on
2026-01-17 13:31:38 +00:00
Hai Zhu
7d151e552c
gh-143943: add missing header file for pycore_optimizer_types.h (GH-143947) 2026-01-17 12:26:19 +00:00
Neil Schemenauer
bb25f7280a
gh-132657: Add maybe_enable_deferred_ref_count() (gh-142843)
If we are specializing to `LOAD_GLOBAL_MODULE` or `LOAD_ATTR_MODULE`, try
to enable deferred reference counting for the value, if the object is owned by
a different thread.  This applies to the free-threaded build only and should
improve scaling of multi-threaded programs.
2026-01-17 01:54:43 +00:00
Dino Viehland
4d5a676aa0
gh-142913: Add test case for interpreter generator w/ overridden opcodes (#142911)
Add test case for interpreter generator w/ overridden opcodes
2026-01-16 10:33:29 -08:00
Peter Bierma
19e64afddf
gh-141070: Rename PyUnstable_Object_Dump to PyObject_Dump (GH-142848) 2026-01-16 09:19:43 -05:00
Mark Shannon
ae53da5758
GH-143493: Conform to spec for generator expressions while supporting virtual iterators (GH-143569)
* Moves the `GET_ITER` instruction into the generator function preamble.
  This means the the iterable is converted into an iterator during generator
  creation, as documented, but keeps it in the same code object allowing
  optimization.
2026-01-16 09:11:58 +00:00
Donghee Na
794f758cd8
gh-141504: Refactor policy object into a single opt_config (gh-143644) 2026-01-15 09:53:00 +09:00
Hugo van Kemenade
2b33b52219 Post 3.15.0a5 2026-01-14 19:30:22 +02:00
Hugo van Kemenade
d51cc01c19 Python 3.15.0a5 2026-01-14 16:41:32 +02:00
Serhiy Storchaka
a471a32f4b
gh-143214: Add the wrapcol parameter in binascii.b2a_base64() and base64.b64encode() (GH-143216) 2026-01-14 14:44:53 +02:00