Commit graph

9100 commits

Author SHA1 Message Date
Petr Viktorin
91cd2e5806
gh-146175: Soft-deprecate outdated macros; convert internal usage (GH-146178)
Co-authored-by: Victor Stinner <vstinner@python.org>
2026-03-23 12:42:09 +01:00
reiden
e36f8db7e5
gh-143414: Implement unique reference tracking for JIT, optimize unpacking of such tuples (GH-144300)
Co-authored-by: Ken Jin <kenjin4096@gmail.com>
2026-03-23 00:57:23 +08:00
Mark Shannon
879c85f6e4
GH-145667: Merge GET_ITER and GET_YIELD_FROM_ITER (GH-146120)
* Merge GET_ITER and GET_YIELD_FROM_ITER. Modify SEND to make it a bit more like FOR_ITER
2026-03-21 10:48:13 +00:00
Shamil
cd10a2e65c
gh-146196: Fix Undefined Behavior in _PyUnicodeWriter_WriteASCIIString() (#146201)
Avoid calling memcpy(data + writer->pos, NULL, 0)
which has an undefined behavior.

Co-authored-by: Victor Stinner <vstinner@python.org>
2026-03-20 15:58:41 +00:00
Sergey Miryanov
ced64605be
GH-146096: Fix segfault in BaseExceptionGroup repr (#146141) 2026-03-19 11:25:15 +00:00
Carlos Sousa
004ce8d97b
gh-137696: Rename 'fort' parameter to 'order' in PyBuffer_* functions (#137866) 2026-03-19 16:54:27 +05:30
Serhiy Storchaka
becd7a967f
gh-146143: Fix the PyUnicodeWriter_WriteUCS4() signature (GH-146144)
It now accepts a pointer to constant buffer of Py_UCS4.
2026-03-19 08:23:01 +00:00
Serhiy Storchaka
0f2246b155
gh-146056: Fix list.__repr__() for lists containing NULLs (GH-146129)
Co-authored-by: Victor Stinner <vstinner@python.org>
2026-03-19 09:59:48 +02:00
Victor Stinner
e1e4852133
gh-146092: Handle _PyFrame_GetFrameObject() failures properly (#146124)
* Fix _PyFrame_GetLocals() and _PyFrame_GetLocals() error handling.
* _PyEval_ExceptionGroupMatch() now fails on _PyFrame_GetLocals()
  error.
2026-03-18 18:27:52 +01:00
Sam Gross
e0f7c1097e
gh-145779: Improve classmethod/staticmethod scaling in free-threaded build (#145826)
Add special cases for classmethod and staticmethod descriptors in
_PyObject_GetMethodStackRef() to avoid calling tp_descr_get, which
avoids reference count contention on the bound method and underlying
callable. This improves scaling when calling classmethods and
staticmethods from multiple threads.

Also refactor method_vectorcall in classobject.c into a new _PyObject_VectorcallPrepend() helper so that it can be used by
PyObject_VectorcallMethod as well.
2026-03-17 14:24:44 -04:00
Serhiy Storchaka
99e2c5eccd
gh-144545: Improve handling of default values in Argument Clinic (GH-146016)
* Add the c_init_default attribute which is used to initialize the C variable
  if the default is not explicitly provided.
* Add the c_default_init() method which is used to derive c_default from
  default if c_default is not explicitly provided.
* Explicit c_default and py_default are now almost always have precedence
  over the generated value.
* Add support for bytes literals as default values.
* Improve support for str literals as default values (support non-ASCII
  and non-printable characters and special characters like backslash or quotes).
* Fix support for str and bytes literals containing trigraphs, "/*" and "*/".
* Improve support for default values in converters "char" and "int(accept={str})".
* Converter "int(accept={str})" now requires 1-character string instead of
  integer as default value.
* Add support for non-None default values in converter "Py_buffer": NULL,
  str and bytes literals.
* Improve error handling for invalid default values.
* Rename Null to NullType for consistency.
2026-03-17 12:16:35 +02:00
Ken Jin
3d0824aef2
gh-127958: Trace from RESUME in the JIT (GH-145905) 2026-03-17 00:18:59 +08:00
Hai Zhu
81ef1b7317
gh-144888: Replace bloom filter linked lists with continuous arrays to optimize executor invalidating performance (GH-145873) 2026-03-16 15:58:18 +00:00
Sergey Miryanov
fd50b41aa9
GH-145247: Use _PyTuple_FromPair in exceptions.c (GH-145910) 2026-03-16 13:50:26 +00:00
Victor Stinner
77632f085d
gh-141510: Avoid critical section on frozendict copy (#145920) 2026-03-16 14:19:00 +01:00
Bénédikt Tran
97968564b6
gh-143636: fix a crash when calling `__replace__ on invalid SimpleNamespace` instances (#143655) 2026-03-14 09:58:15 +00:00
Pieter Eendebak
00a25859a9
gh-145376: Fix GC tracking in structseq.__replace__ (#145820) 2026-03-13 15:42:19 +00:00
Stan Ulbrych
0adc7289c3
Revert "gh-143050: Remove redundant decref in _PyLong_Negate (gh-143051)" (#145891)
OSS Fuzzer caught an assertion failure.

This reverts commit 5197ecb5e4.
2026-03-12 21:53:29 -04:00
Sergey Miryanov
f105265538
GH-132042: Fix calculation of slotdef index in update_one_slot() (#145880) 2026-03-12 23:16:53 +01:00
Sam Gross
cd52172831
gh-145685: Improve scaling of type attribute lookups (gh-145774)
Avoid locking in the PyType_Lookup cache-miss path if the type's
tp_version_tag is already valid.
2026-03-12 13:30:36 -04:00
Thomas Kowalski
7836ecc5da
gh-145681: do not deallocate list buffer in _PyList_AsTupleAndClear (GH-145680)
Setting the size to 0 turns the list contents into overallocated memory that the deallocator will free.
Ownership is transferred to the new tuple so no refcount adjustment is needed.
2026-03-12 14:27:07 +01:00
Victor Stinner
713be70175
gh-141510: Raise TypeError in PyDict_SetItem() on frozendict (#145564)
If the following functions get an unexpected frozendict,
raise TypeError instead of SystemError:

* PyDict_DelItem()
* PyDict_DelItemString()
* PyDict_Merge()
* PyDict_MergeFromSeq2()
* PyDict_Pop()
* PyDict_PopString()
* PyDict_SetDefault()
* PyDict_SetDefaultRef()
* PyDict_SetItem()
* PyDict_SetItemString()
* _PyDict_SetItem_KnownHash()
* PyDict_Update()

Co-authored-by: mohsinm-dev <mohsin.mdev@gmail.com>
2026-03-11 17:05:09 +01:00
Sergey B Kirpichev
dae85c4d93
gh-145633: Remove support for ancient ARM platforms with mixed-endian doubles (#145634)
* Drop DOUBLE_IS_ARM_MIXED_ENDIAN_IEEE754 macro.
* Use DOUBLE_IS_BIG/LITTLE_ENDIAN_IEEE754 to detect endianness of
  float/doubles.
* Drop "unknown_format" code path in PyFloat_Pack/Unpack*().

Co-authored-by: Victor Stinner <vstinner@python.org>
2026-03-11 12:39:24 +01:00
Sam Gross
bdf6de8c3f
gh-145685: Avoid contention on TYPE_LOCK in super() lookups (gh-145775) 2026-03-11 07:19:32 -04:00
Thomas Kowalski
c3955e049f
gh-145713: make bytearray.resize thread-safe on free-threading (#145714)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2026-03-11 12:57:26 +05:30
Pieter Eendebak
5197ecb5e4
gh-143050: Remove redundant decref in _PyLong_Negate (gh-143051) 2026-03-10 15:51:17 -04:00
Sam Gross
f26eca7732
gh-145685: Update find_name_in_mro() to return a _PyStackRef (gh-145693) 2026-03-10 12:47:12 -04:00
Benedikt Johannes
50f82d062b
gh-145044: avoid calling Py_DECREF in unsafe_object_compare on immortal objects (#145045) 2026-03-10 22:03:56 +05:30
bkap123
9e0802330c
gh-145036: Fix data race for list capacity in free-threading (#145365)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2026-03-10 22:00:11 +05:30
Sergey Miryanov
478a315b7a
GH-145247: Implement _PyTuple_FromPair() (#145325)
Implement _PyTuple_FromPair() and _PyTuple_FromPairSteal().

Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2026-03-10 11:44:20 +01:00
Stan Ulbrych
bdf0105291
gh-103997: Remove incorrect statements about -c dedenting (gh-138624) 2026-03-10 09:56:00 +01:00
Sam Gross
0b65c88c2a
gh-145685: Stop the world when updating MRO of existing types (gh-145707)
We already have a stop-the-world pause elsewhere in this code path
(type_set_bases) and this makes will make it easier to avoid contention
on the TYPE_LOCK when looking up names in the MRO hierarchy.

Also use deferred reference counting for non-immortal MROs.
2026-03-09 18:41:07 -04:00
Sam Gross
d76df75f51
gh-145615: Fix mimalloc page leak in the free-threaded build (gh-145626)
Fix three issues that caused mimalloc pages to be leaked until the
owning thread exited:

1. In _PyMem_mi_page_maybe_free(), move pages out of the full queue
   when relying on QSBR to defer freeing the page. Pages in the full
   queue are never searched by mi_page_queue_find_free_ex(), so a page
   left there is unusable for allocations.

2. Move _PyMem_mi_page_clear_qsbr() from _mi_page_free_collect() to
   _mi_page_thread_free_collect() where it only fires when all blocks
   on the page are free (used == 0). The previous placement was too
   broad: it cleared QSBR state whenever local_free was non-NULL, but
   _mi_page_free_collect() is called from non-allocation paths (e.g.,
   page visiting in mi_heap_visit_blocks) where the page is not being
   reused.

3. In _PyMem_mi_page_maybe_free(), use the page's heap tld to find the
   correct thread state for QSBR list insertion instead of
   PyThreadState_GET(). During stop-the-world pauses, the function may
   process pages belonging to other threads, so the current thread
   state is not necessarily the owner of the page.
2026-03-09 13:24:34 -04:00
Victor Stinner
0dfe649400
gh-141510: Optimize frozendict(frozendict) (#145592)
Return the same object unmodified if it's exactly the frozendict
type.

Optimize also PyFrozenDict_New(frozendict).
2026-03-09 15:47:02 +01:00
Pieter Eendebak
886bc6e14b
gh-145376: Fix various reference leaks in Objects/ and Modules/ (#145385)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
2026-03-09 14:19:36 +01:00
Pieter Eendebak
8060aa5d7d
gh-145376: Fix various refleaks in Objects/ (#145609) 2026-03-09 14:17:27 +01:00
Sam Gross
1d091a336e
gh-145566: Skip stop-the-world when reassigning __class__ on newly created objects (gh-145567) 2026-03-06 12:01:06 -05:00
Victor Stinner
0c29f83caa
gh-141510: No longer accept frozendict in PyDict_Copy() (#145542)
Rename _PyDict_Copy() to anydict_copy().

Replace PyObject_IsInstance(op, &PyFrozenDict_Type) with
PyFrozenDict_Check().
2026-03-05 15:26:54 +01:00
Victor Stinner
2cd0ddfe04
gh-141510: Fix frozendict.items() ^ frozendict.items() (#145535)
Add non-regression tests.
2026-03-05 14:14:04 +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
0fe20fc170
gh-141510: Don't accept frozendict in PyDict_Watch() (#145529)
Don't accept frozendict in PyDict_Watch() and PyDict_Unwatch().
A frozendict cannot be modified, so it's not useful to watch for
modifications.
2026-03-05 12:31:29 +01:00
Victor Stinner
0a51113a49
gh-141510: Optimize PyDict_Copy() for frozendict (#145509)
Implement fast-path for frozendict in PyDict_Copy().
2026-03-04 20:49:20 +01:00
Victor Stinner
95f56b1206
gh-141510: Return frozendict unmodified in PyDict_Copy() (#145505)
Add also the internal _PyDict_CopyAsDict() function.
2026-03-04 19:11:00 +00:00
Sam Gross
8a7eb8b2ab
gh-145500: Delete _PyType_GetMRO (gh-145501) 2026-03-04 13:32:43 -05:00
Pieter Eendebak
18aec59fe5
gh-145376: Fix refleak in unusual error path in BaseExceptionGroup_new (GH-145474) 2026-03-04 14:34:24 +01:00
Bartosz Sławecki
e6c3c04fab
gh-145452: Initialize PyLazyImport_Type during interpreter startup (#145453)
Co-authored-by: Victor Stinner <vstinner@python.org>
2026-03-03 17:14:12 +01:00
Victor Stinner
c9d123482a
gh-144995: Optimize memoryview == memoryview (#144996)
Optimize memoryview comparison: a memoryview is equal to itself, there is no
need to compare values, except if it uses float format.

Benchmark comparing 1 MiB:

    from timeit import timeit
    with open("/dev/random", 'br') as fp:
        data = fp.read(2**20)
    view = memoryview(data)
    LOOPS = 1_000
    b = timeit('x == x', number=LOOPS, globals={'x': data})
    m = timeit('x == x', number=LOOPS, globals={'x': view})
    print("bytes %f seconds" % b)
    print("mview %f seconds" % m)
    print("=> %f time slower" % (m / b))

Result before the change:

    bytes 0.000026 seconds
    mview 1.445791 seconds
    => 55660.873940 time slower

Result after the change:

    bytes 0.000026 seconds
    mview 0.000028 seconds
    => 1.104382 time slower

This missed optimization was discovered by Pierre-Yves David
while working on Mercurial.

Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
2026-03-03 12:15:32 +01:00
Stan Ulbrych
f8d2f9fe67
gh-145118: Add frozendict support to type() (#145124) 2026-03-02 20:45:03 +01:00
Peter Bierma
592e8f0865
gh-130327: Always traverse managed dictionaries, even when inline values are available (#130469) 2026-03-02 14:32:06 -05:00
Sam Gross
02288bf022
gh-130555: Fix use-after-free in dict.clear() with embedded values (gh-145268) 2026-03-02 12:25:13 -05:00