9156 Commits

Author SHA1 Message Date
Mark Shannon 70bd1c2dd2 GH-143732: SEND specialization (GH-148963)
* SEND specialization. Adds 2 new specialized instructions:

* SEND_VIRTUAL: for sends to virtual iterators e.g lists and tuples
* SEND_ASYNC_GEN: for sends to async generators

Tweak FOR_ITER_VIRTUAL so that SEND_VIRTUAL and FOR_ITER_VIRTUAL use equivalent guards
2026-05-05 15:19:16 +01:00
Anuj Nitin Bharambe f6d16a0d70 gh-149216: Notify type watchers on heap type deallocation (GH-149236)
Authored-by: Anuj Bharambe <anujnitinb@gmail.com>
2026-05-05 11:24:07 +01:00
Petr Viktorin 508b49845d gh-149044: Implement PEP 820 – PySlot: Unified slot system for the C API (GH-149055)
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2026-05-05 09:18:04 +02:00
Victor Stinner 5dd5c8b5a6 gh-148675: Remove F and D formats from array and memoryview (GH-149368) 2026-05-04 17:26:30 +02:00
Victor Stinner 6e6f9053e3 gh-148675: Add Zd/Zf formats to array, ctypes, memoryview, struct (#148676)
* Add Zd/Zf format support to array, memoryview and struct.
* ctypes: Replace F/D/G complex format with Zf/Zd/Zg.
* Modify array, ctypes and struct modules to support format strings
  longer than 1 character (such as "Zd").
* Change array.typecodes type from str to tuple.
2026-05-04 16:14:23 +02:00
Kumar Aditya 5847931d11 gh-143732: allow dict subclasses to be specialized (GH-148128) 2026-05-04 09:39:03 +01:00
Mazin Sharaf 1fc2b38d63 GH-148189: Fix miscalculation of type-specific free list memory use (#148190)
* Fix calculation of PyListObject size in allocator

* Fix size calculation in _PyDict_DebugMallocStats

* Fix memory size calculation in tupleobject.c

Adjusted memory calculation for PyTupleObject freelist entries.

* Revert in tupleobject.c

Removed unnecessary comment regarding memory calculation and the memory calculation itself.

* 📜🤖 Added by blurb_it.

* Update tupleobject.c

---------

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
2026-05-02 22:03:13 -05:00
Neko Asakura 7c9ad27dd1 gh-148871: extend and improve LOAD_COMMON_CONSTANT (GH-148971) 2026-05-02 19:59:51 +01:00
Eric Mark Martin a65611e7f5 gh-149171: Make TypeAliasType __module__ writable (#149172)
closes #149171.
2026-05-02 17:28:08 +00:00
Petr Viktorin fcd53b6872 gh-145497: Use same size of static_types array in all builds (GH-149139)
When someone adds a new type but doesn't increment
`_Py_MAX_MANAGED_STATIC_BUILTIN_TYPES` or
`_Py_MAX_MANAGED_STATIC_EXT_TYPES`, JIT tests fail,
because JIT builds define an extra type.
But the JIT tests don't necessarily run for the commit
that causes the failure.

As a workaround, use the same size for the array for all
builds, potentially with an empty spot.
2026-05-01 09:41:28 +02:00
Maurycy Pawłowski-Wieroński 5110738779 gh-144319: Use transparent huge pages via madvise(MADV_HUGEPAGE) in pymalloc (#144353) 2026-04-30 22:18:07 +01:00
Jelle Zijlstra 29a92abb60 gh-148829: Implement PEP 661 (#148831)
Co-authored-by: Victorien <65306057+Viicos@users.noreply.github.com>
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2026-04-27 19:28:30 -07:00
sobolevn 85d3bcd4f3 gh-134690: Removed deprecated codetype.co_lnotab (#134691) 2026-04-25 19:13:48 +03:00
Sam Gross 4629c2215a gh-113956: Make intern_common thread-safe in free-threaded build (gh-148886)
Avoid racing with the owning thread's refcount operations when
immortalizing an interned string: if we don't own it and its refcount
isn't merged, intern a copy we own instead. Use atomic stores in
_Py_SetImmortalUntracked so concurrent atomic reads are race-free.
2026-04-23 14:42:57 -04:00
Kumar Aditya 29917d51ab gh-148907: fix performance regression in PyType_GetModuleByDef on free-threading (#148908) 2026-04-23 16:42:57 +05:30
KotlinIsland 04fd103713 gh-148207: add additional keywords to typing.TypeVarTuple (#148212) 2026-04-22 06:28:12 -07:00
Gabriele N. Tornetta 858e69eab0 gh-142186: Allow all PEP-669 events to be per-code object and disableable (GH-146182)
* Make the `PY_UNWIND` monitoring event available as a code-local
event to allow trapping on function exit events when an exception
bubbles up. This complements the PY_RETURN event by allowing to
catch any function exit event.

* Allow `PY_UNWIND`  to be `DISABLE`d; disabling it disables the event for the whole code object.

* Do the above for `PY_THROW`, `RAISE`, `EXCEPTION_HANDLED`, and `RERAISE` events.
2026-04-22 09:08:23 +01:00
Dino Viehland d81599eeb7 gh-148659: Export a few more functions required for external JITs (#148704)
Export a few more functions required for external JITs
2026-04-18 11:32:22 -07:00
Prakash Sellathurai 634568d030 gh-148222: Fix NULL dereference bugs in genericaliasobject.c (#148226) 2026-04-17 17:21:13 -07:00
Dino Viehland 2a07ff980b gh-148659: Export some internal functions for the JIT (PEP-523) (#148634)
Export (as internal functions, not public ones) C API functions necessary to implement a JIT as a separate extension module.
2026-04-17 01:55:03 +02:00
Mark Shannon 600f4dbd54 GH-145668: Add FOR_ITER specialization for virtual iterators. Specialize GET_ITER. (GH-147967)
* Add FOR_ITER_VIRTUAL to specialize FOR_ITER for virtual iterators
* Add GET_ITER_SELF to specialize GET_ITER for iterators (including generators)
* Add GET_ITER_VIRTUAL to specialize GET_ITER for iterables as virtual iterators
* Add new (internal) _tp_iteritem function slot to PyTypeObject
* Put limited RESUME at start of genexpr for free-threading. Fix up exception handling in genexpr
2026-04-16 15:22:22 +01:00
Pieter Eendebak 1f6a09fb36 gh-100239: Specialize more binary operations using BINARY_OP_EXTEND (GH-128956) 2026-04-16 09:22:41 +01:00
Bénédikt Tran 69e0a78e6e gh-148390: fix undefined behavior of memoryview(...).cast("?") (#148454) 2026-04-15 11:42:20 +00:00
Ken Jin 6f7bb297db gh-146261: JIT: protect against function version changes (#146300)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2026-04-13 02:23:47 +08:00
Sam Gross 3ab94d6842 gh-148393: Use atomic ops on _ma_watcher_tag in free threading build (gh-148397)
Fixes data races between dict mutation and watch/unwatch on the same dict.
2026-04-12 10:40:41 -04:00
Wulian233 e2fa10e04d gh-148208: Fix recursion depth leak in PyObject_Print (GH-148209) 2026-04-11 17:26:18 -07:00
Kumar Aditya d3b7b93cbb gh-148037: remove critical section from PyCode_Addr2Line (#148103) 2026-04-10 17:58:17 +05:30
Max Bachmann ee2775cfae gh-148274: properly handle result from PyObject_VisitManagedDict (#148275) 2026-04-09 18:50:50 +05:30
Kumar Aditya 458aca9237 gh-131798: fold super method lookups in JIT (#148231) 2026-04-09 13:25:01 +05:30
Petr Viktorin 8923ca418c gh-145921: Add "_DuringGC" functions for tp_traverse (GH-145925)
There are newly documented restrictions on tp_traverse:

    The traversal function must not have any side effects.
    It must not modify the reference counts of any Python
    objects nor create or destroy any Python objects.

* Add several functions that are guaranteed side-effect-free,
  with a _DuringGC suffix.
* Use these in ctypes
* Consolidate tp_traverse docs in gcsupport.rst, moving unique
  content from typeobj.rst there

Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2026-04-08 09:15:11 +02:00
Wulian233 69f51625e6 gh-148119: Refactor get_type_attr_as_size to improve error handling in structseq.c (#148120) 2026-04-06 17:41:30 +05:30
Pablo Galindo Salgado 77fc2f5a5e gh-144319: Fix huge page leak in datastack chunk allocator (#147963)
Fix huge page leak in datastack chunk allocator

The original fix rounded datastack chunk allocations in pystate.c so that
_PyObject_VirtualFree() would receive the full huge page mapping size.

Change direction and move that logic into _PyObject_VirtualAlloc() and
_PyObject_VirtualFree() instead. The key invariant is that munmap() must see
the full mapped size, so alloc and free now apply the same platform-specific
rounding in the allocator layer.

This keeps _PyStackChunk bookkeeping in requested-size units, avoids a
hardcoded 2 MB assumption, and also covers other small virtual-memory users
such as the JIT tracer state allocation in optimizer.c.
2026-04-05 16:29:38 +01:00
Wulian233 c398490fbf gh-148074: Fix typeobject.c missing error return (#148075) 2026-04-04 21:04:55 +05:30
Neil Schemenauer 9d087d6d41 GH-147985: Use lock-free lookup in PySet_Contains (#147986)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2026-04-03 12:04:06 +05:30
Victor Stinner c1a4112c22 gh-147988: Initialize digits in long_alloc() in debug mode (#147989)
When Python is built in debug mode:

* long_alloc() now initializes digits with a pattern to detect usage of
  uninitialized digits.
* _PyLong_CompactValue() now makes sure that the digit is zero when the
  sign is zero.
* PyLongWriter_Finish() now raises SystemError if it detects uninitialized
  digits

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2026-04-02 11:55:34 +00:00
Petr Viktorin a86963b3e2 gh-146636: Py_mod_abi mandatory for modules created from slots array (GH-146855) 2026-04-02 13:54:21 +02:00
Sergey B Kirpichev b456cb25a9 gh-143050: Add helper _PyLong_InitTag() (#147956)
With this we can assume, that _PyLong_SetSignAndDigitCount() and
_PyLong_SetDigitCount() operate on non-immortal integers.

Co-authored-by: Victor Stinner <vstinner@python.org>
2026-04-01 21:42:10 +00:00
Serhiy Storchaka 473d2a35ce gh-147944: Increase range of bytes_per_sep (GH-147946)
Accepted range for the bytes_per_sep argument of bytes.hex(),
bytearray.hex(), memoryview.hex(), and binascii.b2a_hex()
is now increased, so passing sys.maxsize and -sys.maxsize is now
valid.
2026-04-01 08:33:30 +00:00
Stan Ulbrych 62a6e898e0 gh-147856: Allow the 'count' argument of bytes.replace() to be a keyword (#147943) 2026-03-31 19:27:52 +02:00
Sergey B Kirpichev db5936c5b8 gh-143050: Correct PyLong_FromString() to use _PyLong_Negate() (#145901)
The long_from_string_base() might return a small integer, when the
_pylong.py is used to do conversion.  Hence, we must be careful here to
not smash it "small int" bit by using the _PyLong_FlipSign().

Co-authored-by: Victor Stinner <vstinner@python.org>
2026-03-31 13:17:49 +00:00
sunmy2019 bbf7fb2c15 gh-146615: Fix format specifiers in Objects/ directory (GH-146620) 2026-03-31 10:59:48 +03:00
sunmy2019 72d29ea363 gh-146615: Fix crash in __get__() for METH_METHOD descriptors with invalid type argument (GH-146634) 2026-03-31 10:48:02 +03:00
Serhiy Storchaka 727890410b gh-145056: Fix merging of collections.OrderedDict and frozendict (GH-146466) 2026-03-30 22:06:44 +03:00
Kumar Aditya 8e9d21c64b gh-146558: JIT optimize dict access for objects with known hash (#146559) 2026-03-30 14:23:29 +00:00
Victor Stinner adf2c47911 gh-126835: Fix _PY_IS_SMALL_INT() macro (#146631) 2026-03-30 12:48:18 +00:00
Kumar Aditya 8e10bd77ea gh-146587: fix type slot assignment incase of multiple slots for same name (#146593) 2026-03-30 18:07:38 +05:30
Serhiy Storchaka 6932c3ee6a gh-145876: Do not mask KeyErrors raised during dictionary unpacking in call (GH-146472)
KeyErrors raised in keys() or __getitem__() during dictionary unpacking
in call (func(**mymapping)) are no longer masked by TypeError.
2026-03-29 11:58:52 +03:00
Sergey Miryanov a933e9ccee GH-145247: Use _PyTuple_FromPair[Steal] in Objects (#145884)
Co-authored-by: Victor Stinner <vstinner@python.org>
2026-03-28 00:01:01 +00:00
Brij Kapadia 0de4e08a59 gh-146250: Fix memory leak in re-initialization of SyntaxError (#146251) 2026-03-27 19:29:21 +05:30
Sergey B Kirpichev 256907d3aa gh-138580: Revert sys.float_info.iec_60559 boolean flag (#146501)
This reverts commit 68c7fad757.

It looks like on practice the __STDC_IEC_559__ doesn't indicate
conformance to the standard. It can't be used to filter out tests
or to give some promises in documentation. See discussion in
the reverted PR thread:
https://github.com/python/cpython/pull/138811#issuecomment-4117692418
2026-03-27 11:29:15 +01:00