Commit graph

9211 commits

Author SHA1 Message Date
Neil Schemenauer
9626ef87f4
gh-152238: Revert gh-150490 and gh-152200. (gh-152232)
Revert commits:
    gh-151593: Fix dead lock in PyDict insert_split_key() (#152200)
    gh-150490: Raise PyType_Modified for insertion into split dictionary (#150489)

For gh-150489, it violates locking discipline and results in deadlocks,
gh-151593 is an example of it being hit in CI.  The attempted fix 
gh-152200 avoids the deadlock but introduces a data-race.  The race
window is small but can be triggered with pure Python code.
2026-06-26 11:20:41 -07:00
Donghee Na
5a549e82b8
gh-152235: Defer GC tracking in set.union and set.difference (gh-152290) 2026-06-26 17:11:33 +00:00
Donghee Na
a87d24a69d
gh-152235: Defer GC tracking in more set operations (gh-152273) 2026-06-26 22:35:17 +09:00
Victor Stinner
05679f3576
gh-151722: Defer GC tracking in frozendict.copy() (#152230)
Fix _PyDict_Or() and frozendict.copy(): only track the frozendict by
the GC once the dictionary is fully initialized.

Functions modifying frozendict now ensures that the object is not
tracked by the GC (in debug mode).

* can_modify_dict() checks that _PyObject_GC_IS_TRACKED() is false
  for frozendicts.
* dict_merge_api() makes sure that the dictionary is tracked by the
  GC.
2026-06-26 13:55:54 +02:00
Donghee Na
908f438e19
gh-152235: Defer GC tracking of set and frozenset to end of construction (gh-152237) 2026-06-26 11:34:13 +09:00
Victor Stinner
55bc3126e0
gh-151722: Do not track the frozendict in the GC in _PyDict_FromKeys() (#152067)
_PyDict_FromKeys() now creates a frozendict copy which is
not tracked by the GC.

dict_merge() no longer requires the dictionary to be tracked by the
GC.

Co-authored-by: Donghee Na <donghee.na@python.org>
Co-authored-by: Inada Naoki <songofacandy@gmail.com>
2026-06-25 18:06:07 +00:00
Victor Stinner
bef5706222
gh-151593: Fix dead lock in PyDict insert_split_key() (#152200)
Do not hold LOCK_KEYS() lock when calling PyType_Modified() to avoid
a deadlock.

Co-authored-by: Neil Schemenauer <nas-github@arctrix.com>
2026-06-25 19:58:27 +02:00
Jelle Zijlstra
0fb82b46df
gh-151955: Allow more ParamSpec and TypeVarTuple bounds (#151956) 2026-06-24 09:10:10 -07:00
sobolevn
22dd5b5b37
gh-151763: Fix possible crash on CodeType deallocation (#152034) 2026-06-24 14:46:39 +03:00
Ivy Xu
7928a8b730
gh-151126: Add missing PyErr_NoMemory() in type_from_slots_or_spec (#151582)
Co-authored-by: Stan Ulbrych <stan@python.org>
2026-06-23 15:48:11 +01:00
Donghee Na
6920036f28
gh-151722: Defer GC tracking of frozendict to end of construction (gh-151740) 2026-06-22 23:45:55 +00:00
Prakash Sellathurai
1ab8862ea0
gh-151905: fix memory error handling in PyFrame_GetBack (#151906) 2026-06-22 16:41:31 +05:30
AN Long
c2661e6189
gh-151845: Fix formatfloat() return-value contract in unicode_format.c (#151846)
Fix formatfloat() return-value contract in unicode_format.c
2026-06-21 20:16:30 +03:00
da-woods
a5568d0eb7
gh-141510 Add frozendict fast paths to abstract.c (#150692)
Add frozendict to the fast paths of PyMapping_GetOptionalItem(),
PyMapping_Keys(), PyMapping_Values(), and PyMapping_Items().

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
2026-06-19 08:41:00 +00:00
Maurycy Pawłowski-Wieroński
a8d74c062f
gh-151436: Fix missing tstate->last_profiled_frame updates (#151437) 2026-06-17 16:49:23 -04:00
Petr Viktorin
16185e9fe2
gh-149044: Improve Py_tp_base[s] docs & error message for non-type bases (GH-151252)
The initial implementation of PEP 820 worsened the error message
when non-types are given as base types in Py_tp_bases & Py_tp_base.
Bring back the 'bases must be types' wording and add a 'got' note for
easier debugging.

Improve slot ID documentation, and soft-deprecate Py_tp_base
(as per the PEP).
2026-06-17 15:27:02 +02:00
Victor Stinner
b16d23fc9f
gh-151218: Replace sys.flags in PyConfig_Set() (#151402)
PyConfig_Set() and sys.set_int_max_str_digits() now replace
sys.flags (create a new object), instead of modifying sys.flags in-place.

Modifying sys.flags in-place can lead to data races when multiple
threads are reading or writing sys.flags in parallel.

Use _Py_atomic functions to get and set max_str_digits members.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2026-06-16 16:17:33 +00:00
Victor Stinner
0ec7c9d17e
gh-146102: Fix type slot_bf_getbuffer() error handling (#151346)
Call PyBuffer_Release() if PyObject_GC_New() fails.

Fix also bytes_join(): only call Py_DECREF(item) after formatting the
error message which uses item.
2026-06-15 11:47:58 +02:00
Victor Stinner
b3b7c0025b
gh-146102: Don't clear exception on success in odictobject.c (#151347)
Calling PyErr_Clear() on success can mask a pending exception.
Replace it with an assertion checking that no exception is set.
2026-06-15 11:46:52 +02:00
JasonMendoza2008
ecbd31ee39
gh-137759: Replace _PyObject_HashFast() with PyObject_Hash() in setobject.c (#137828)
Replace also _PyObject_HashFast() with PyObject_Hash()
in _collections._count_elements().

Rename _PyObject_HashFast() to _PyObject_HashDictKey(),
and mark it as Py_ALWAYS_INLINE.

Only use _PyObject_HashDictKey() on dictionaries.
2026-06-15 11:31:04 +02:00
Matt Wozniski
c37599200f
gh-151297: Fix undefined behavior in _PyObject_MiRealloc (GH-151358)
The standard says that a call to `memcpy` must pass a valid source and
destination pointer even if the size is 0, so we must avoid calling
`memcpy` when our source pointer is NULL. If we don't, an optimizing
compiler can decide that the pointer must be non-NULL based on the
presence of UB, and optimize out checks for null pointers.

Specifically, note that the standard says:

    Where an argument declared as size_t n specifies the length of the
    array for a function, n can have the value zero on a call to that
    function. Unless explicitly stated otherwise in the description of
    a particular function in this subclause, pointer arguments on such
    a call shall still have valid values, as described in 7.1.4.

And section 7.1.4 says:

    If an argument to a function has an invalid value (such as a value
    outside the domain of the function, or a pointer outside the address
    space of the program, or a null pointer, or a pointer to
    non-modifiable storage when the corresponding parameter is not
    const-qualified) or a type (after default argument promotion) not
    expected by a function with a variable number of arguments, the
    behavior is undefined.

The specification for `memcpy` doesn't state that it's allowed to be
called with null pointers, and Linux's `/usr/include/string.h` declares
`memcpy` as `__nonnull ((1, 2))`.
2026-06-11 21:21:04 -04:00
Peter Bierma
80f9467434
gh-151065: Copy fix for memory leak from mimalloc upstream (GH-151066)
Applies d7a72c4912 to our copy of mimalloc.
2026-06-11 18:11:52 -04:00
Serhiy Storchaka
65047f2e2f
gh-150285: Fix too long docstrings in GenericAlias and __class_getitem__ (GH-151354) 2026-06-11 19:52:58 +03:00
Dino Viehland
efb2fffae1
gh-150490: Raise PyType_Modified for insertion into split dictionary (#150489)
Raise PyType_Modified for insertion into split dictionary
2026-06-11 09:38:31 -07:00
Kumar Aditya
6112d70abe
gh-151228: fix data race on clearing embedded dict values (#151330) 2026-06-11 21:37:00 +05:30
Thomas Kowalski
1ec6596828
gh-150858: fix data race while changing __qualname__ of a type object(#150859) 2026-06-11 15:07:36 +00:00
Victor Stinner
72e7eddce6
gh-123619: Fix PyUnstable_Object_EnableDeferredRefcount() (#151260)
Return 0 if the object is not tracked by the GC.
2026-06-11 12:55:13 +02:00
tonghuaroot (童话)
84a322aa15
gh-151295: Fix use-after-free in bytes.join()/bytearray.join() via re-entrant __buffer__ (GH-151296) 2026-06-11 07:51:43 +00:00
Lukas Geiger
f2a0f82282
gh-150988: Fix refleak in OSError when attrs are set before super().__init__() (#150990)
Co-authored-by: Victor Stinner <vstinner@python.org>
2026-06-10 12:27:11 +00:00
Serhiy Storchaka
ca32ebf793
gh-80384: Check that callback is callable at weak reference creation (GH-151145)
* Python functions weakref.ref() and weakref.proxy() now raise TypeError
  if the callback argument is not callable or None.
* C functions PyWeakref_NewRef() and PyWeakref_NewProxy() now raise TypeError
  if the callback argument is not callable, None, or NULL.

Co-authored-by: Maxwell Bernstein <emacs@fb.com>
2026-06-10 13:34:55 +03:00
Omkar Kabde
253904f752
gh-150942: Speed up frame local item collection (gh-151002) 2026-06-07 21:05:53 +09:00
Stephen Rosen
50fe49c879
gh-150319: Replace all documentation which says "See PEP 585" (#150325)
* Replace all documentation which says "See PEP 585"

The following classes in the stdlib get simple updates:

- array.array
- asyncio.Future
- asyncio.Task
- collections.defaultdict
- collections.deque
- contextvars.ContextVar
- contextvars.Token
- ctypes.Array
- os.DirEntry
- re.Match
- re.Pattern
- string.templatelib.Interpolation
- string.templatelib.Template
- types.MappingProxyType
- queue.SimpleQueue
- weakref.ref

The following classes are documented publicly as functions, and are
therefore updated internally (`__class_getitem__.__doc__`) but not in the
public docs:

- functools.partial
- itertools.chain

The following builtin types have updates to `__class_getitem__.__doc__`
but not to any documentation pages:

- BaseExceptionGroup
- coroutines (from generators)
- dict
- enumerate
- frozendict
- frozenset
- generators (and async generators)
- list
- memoryview
- set
- slice
- tuple

Special cases:

- union objects are now documented as "supporting class-level []",
  rather than anything to do with generics.

- Templates might be generic over a single type (union, in theory) or
  over a TypeVarTuple. As this is not currently fully settled, it is
  marked with a comment and a mild hint that it is a single type is used
  (namely, "type" is singular rather than "types", plural)

* Apply suggestions from code review

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>

* Correct several class getitem docs

And expand the text for tuples.

Co-authored-by: Jelle Zijlstra <906600+JelleZijlstra@users.noreply.github.com>

* Add notes on generic typing of builtins

* Fix typo in tuple.__class_getitem__ docstring

* Typo fix: malformed refs

Fix `generic` links which weren't marked as `:ref:`.

* Strike unnecessary docs on generic-ness

Co-authored-by: Jelle Zijlstra <906600+JelleZijlstra@users.noreply.github.com>

* Apply suggestions from code review

These are applied at both the originally indicated locations and in the
corresponding docstring definitions.

Co-authored-by: Alex Waygood <66076021+AlexWaygood@users.noreply.github.com>

* Update Doc/library/re.rst

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>

* Update Objects/enumobject.c

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>

* Remove tuple generic doc in 'stdtypes' page

This is covered in more detail in the cross-linked typing documentation.
The other copy of this documentation -- in the docstring for
`tuple.__class_getitem__` -- is left in place.

* Fix whitespace around new doc of generics

Per review, do not introduce or remove whitespace such that section
breaks are altered by the introduction of doc on various generic types.

In most cases, this is a removal of an extra line.

In one case (Arrays), it is the reintroduction of a line.

Additionally, two other minor fixes are included:
- incorrect indent on 'defaultdicts'
- make `mappingproxy.__class_getitem__.__doc__` consistent with other
  mapping type generic docs

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>

* Move placement of memoryview generic note

Previous placement was at the end of the main docstring, which is
consistent with other types but places it after a section on various
methods (which makes it read somewhat inconsistently). Moving it up
helps resolve.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>

* Ensure sphinxdoc does not start sentences lowercase

Lowercase class names at the start of sentences are marked out with the
`class` role. In the case of `deque`, documentation already refers to
these as `Deques`, so this form is preferred.

* Apply suggestions from code review

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>

* Fix line endings and wrap more tightly

Line endings fixed by pre-commit ; also re-wrapped the MappingProxyType
text which was too long.

* Use 'ContextVars' style in sphinx doc

---------

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Jelle Zijlstra <906600+JelleZijlstra@users.noreply.github.com>
Co-authored-by: Alex Waygood <66076021+AlexWaygood@users.noreply.github.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2026-06-02 21:13:34 +01:00
Bartosz Sławecki
5a2d2736a6
gh-150052: Resolve un-loaded lazily loaded submodules via module.__getattr__ instead of publishing lazy values (#150055) (#150744) 2026-06-02 09:58:51 +01:00
Brij Kapadia
f586fd9e30
gh-144774: Add critical section in BaseException.__setstate__ (#150578) 2026-05-30 21:07:27 +05:30
Serhiy Storchaka
e1e06be119
gh-150285: Fix too long docstrings in builtins (GH-150293)
* gh-150285: Fix too long docstrings in builtins

* Revert bytes and bytearray class multiline docstrings to make IDLE happy.
2026-05-24 15:03:32 +03:00
Pieter Eendebak
dfeeee990b
gh-145192: improve performance of PySequence_GetSlice (#145193) 2026-05-23 15:45:50 +05:30
Hai Zhu
e7eaed5614
gh-148450: abc.register needs to update type_version when tp_flags is changed (#148623) 2026-05-23 13:55:44 +05:30
sobolevn
f621ba16b7
gh-150146: Fix NULL dereference in _Py_subs_parameters (#150147) 2026-05-20 16:27:55 +03:00
Victor Stinner
244300162d
gh-149807: Fix hash(frozendict): compute (key, value) pair hash (#149841) 2026-05-20 13:22:57 +02:00
Tim Stumbaugh
de9c32fc34
PEP 810 - Update some error strings (#150126) 2026-05-20 00:47:44 +00:00
Peter Bierma
409fa8e1f3
gh-150027: Avoid copying during construction of frozenset objects (GH-150028) 2026-05-19 13:57:37 -04:00
Jelle Zijlstra
08218030a5
gh-148829: Make sentinels' repr and module customizable (#149654)
Implementation of python/peps#4968; still needs SC approval.
2026-05-19 09:18:56 -07:00
Kumar Aditya
00ea77613b
gh-149816: fix thread safety of deletion of list slice (#149936) 2026-05-18 22:08:37 +05:30
Kumar Aditya
1692854706
gh-149816: fix dict.clear() race on split-table dict with non-embedded values (#149914) 2026-05-18 21:39:45 +05:30
sobolevn
46afba7b93
gh-149816: Fix a race condition in _PyBytes_FromList with free-threading (#149909) 2026-05-16 08:37:34 +00:00
sobolevn
1fdf033774
gh-149816: Fix race condition in memoryview with free-threading (#149858) 2026-05-15 15:38:51 +03:00
Carlo Bramini
fdf064ca81
gh-148461: Use arc4random_buf() in mimalloc on Cygwin (#148462)
See also issue #113141.
2026-05-13 21:09:24 +02:00
Kumar Aditya
94bca40ff0
gh-148906: fix performance scaling of descriptors on free-threading (#148915) 2026-05-13 23:03:59 +05:30
Stan Ulbrych
6a0be131c3
gh-149595: Remove the sys._enablelegacywindowsfsencoding() function (#149596)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2026-05-12 17:11:34 +01:00
Thomas Kowalski
f5fb491341
gh-149676: Fix hash(frozendict | frozendict) (#149675)
Fix new_dict_impl() to properly initialize ma_hash on frozendict.

Co-authored-by: Victor Stinner <vstinner@python.org>
2026-05-12 10:47:39 +00:00