Commit graph

9126 commits

Author SHA1 Message Date
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
Sergey B Kirpichev
c68a19448a
gh-146151: memoryview supports 'F' and 'D' format types (complex) (#146241)
Co-authored-by: Victor Stinner <vstinner@python.org>
2026-03-26 15:26:34 +01:00
Kumar Aditya
495178ab05
gh-146453: fix _PyType_LookupByVersion for types with fixed pre-defined version tags (#146454) 2026-03-26 14:36:55 +05:30
Sam Gross
60093096ba
gh-146041: Avoid lock in sys.intern() for already interned strings (gh-146072)
Fix free-threading scaling bottleneck in sys.intern and `PyObject_SetAttr` by
avoiding the interpreter-wide lock when the string is already interned and
immortalized.
2026-03-24 14:29:37 -04:00
Karolina Surma
1887a95f51
gh-128341: Use _Py_ABI_SLOT in stdlib modules (#145770)
Rename from _Py_INTERNAL_ABI_SLOT to _Py_ABI_SLOT
and define the macro using _PyABIInfo_DEFAULT.

Use the ABI slot in stdlib extension modules to enable running
a check of ABI version compatibility.

_tkinter, _tracemalloc and readline don't use the slots, hence they need
explicit handling.

Co-authored-by: Victor Stinner <vstinner@python.org>
2026-03-24 17:47:55 +00:00
Sergey B Kirpichev
68c7fad757
gh-138580: Add sys.float_info.iec_60559 boolean flag (#138811)
This value indicating support the IEC 60559 floating-point standard (the
Annex F of C99).  If enabled, the float type characteristics matches the
IEC 60559 double format and exceptional cases for the math's functions
follow to the section F.10 of the C99 standard.

Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
2026-03-24 11:36:15 +00:00
Brij Kapadia
e017971eb9
gh-146199: Fix error handling in code_richcompare when PyObject_RichCompareBool fails (#146200)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2026-03-23 23:41:53 +01:00
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