Commit graph

8355 commits

Author SHA1 Message Date
Miss Islington (bot)
66d0636025
[3.13] gh-128078: Clear exception in anext before calling _PyGen_SetStopIterationValue (GH-128780) (#128785)
gh-128078: Clear exception in `anext` before calling `_PyGen_SetStopIterationValue` (GH-128780)
(cherry picked from commit 76ffaef729)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2025-01-13 13:20:49 +00:00
Miss Islington (bot)
632745ade1
[3.13] gh-128759: fix data race in type_modified_unlocked (GH-128764) (#128769)
* gh-128759: fix data race in `type_modified_unlocked` (GH-128764)
(cherry picked from commit 6e1e780540)

Co-authored-by: sobolevn <mail@sobolevn.me>
2025-01-13 18:09:39 +05:30
Miss Islington (bot)
5370ad100d
[3.13] gh-126862: Use Py_ssize_t instead of int when processing the number of super-classes (GH-127523) (#128699)
gh-126862: Use `Py_ssize_t` instead of `int` when processing the number of super-classes  (GH-127523)
(cherry picked from commit 2fcdc8488c)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-01-10 03:56:35 +00:00
Miss Islington (bot)
b875917e21
[3.13] gh-127903: Fix a crash on debug builds when calling Objects/unicodeobject::_copy_characters (GH-127876) (#128458)
gh-127903: Fix a crash on debug builds when calling `Objects/unicodeobject::_copy_characters`` (GH-127876)
(cherry picked from commit 46cb6340d7)

Co-authored-by: Alexander Shadchin <shadchin@yandex-team.com>
2025-01-03 21:20:30 +02:00
Kumar Aditya
fa6c48e4b3
[3.13] gh-128013: fix data race in PyUnicode_AsUTF8AndSize on free-threading (#128021) (#128417) 2025-01-02 22:10:17 +05:30
Miss Islington (bot)
4f59f1d0d3
[3.13] Clean up redundant ifdef in list getitem (GH-128257) (#128276)
Clean up redundant ifdef in list getitem (GH-128257)

It's already inside a `Py_GIL_DISABLED` block so the `#else` clause is always unused.
(cherry picked from commit 42f7a00ae8)

Co-authored-by: da-woods <dw-git@d-woods.co.uk>
2024-12-26 15:04:32 +00:00
Serhiy Storchaka
c30cad0638
[3.13] gh-128198: Add missing error checks for usages of PyIter_Next() (GH-128199) (GH-128272)
(cherry picked from commit 5c814c83cd)

Co-authored-by: Yan Yanchii <yyanchiy@gmail.com>
2024-12-26 10:39:47 +00:00
Pablo Galindo Salgado
eb692d945e
[3.13] gh-126076: Account for relocated objects in tracemalloc (GH-126077) (#127823)
(cherry picked from commit 30aeb00d36)
2024-12-11 14:15:37 +01:00
Miss Islington (bot)
acf05aa5d8
[3.13] gh-127563: use dk_log2_index_bytes=3 in empty dicts (GH-127568) (GH-127798)
This fixes a UBSan failure (unaligned zero-size memcpy) in `dictobject.c`.
(cherry picked from commit 9af96f4406)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-12-11 09:24:14 +01:00
Sam Gross
69bb1c6c41
[3.13] gh-127582: Make object resurrection thread-safe for free threading. (GH-127612) (GH-127659)
Objects may be temporarily "resurrected" in destructors when calling
finalizers or watcher callbacks. We previously undid the resurrection
by decrementing the reference count using `Py_SET_REFCNT`. This was not
thread-safe because other threads might be accessing the object
(modifying its reference count) if it was exposed by the finalizer,
watcher callback, or temporarily accessed by a racy dictionary or list
access.

This adds internal-only thread-safe functions for temporary object
resurrection during destructors.
(cherry picked from commit f4f530804b)
2024-12-05 18:49:33 -05:00
Sam Gross
4060ef36e1
[3.13] gh-127536: Add missing locks in listobject.c (GH-127580) (GH-127613)
We were missing locks around some list operations in the free threading
build.
(cherry picked from commit e51da64ac3)
2024-12-04 15:17:19 -05:00
Miss Islington (bot)
e546876d83
[3.13] gh-127521: Mark list as "shared" before resizing if necessary (GH-127524) (GH-127533)
In the free threading build, if a non-owning thread resizes a list,
it must use QSBR to free the old list array because there may be a
concurrent access (without a lock) from the owning thread.

To match the pattern in dictobject.c, we just mark the list as "shared"
before resizing if it's from a non-owning thread and not already marked
as shared.
(cherry picked from commit c7dec02de2)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-12-02 19:22:05 -05:00
Miss Islington (bot)
f41d8d89e7
[3.13] gh-113841: fix possible undefined division by 0 in _Py_c_pow() (GH-127211) (#127216)
Note, that transformed expression is not an equivalent for original one (1/exp(-x) != exp(x) in general for floating-point numbers). Though, the difference seems to be ~1ULP for good libm implementations.

It's more interesting why division was used from beginning. Closest algorithm I've found (no error checks, of course;)) - it's Algorithm 190 from ACM: https://dl.acm.org/doi/10.1145/366663.366679. It uses subtraction in the exponent.

(cherry picked from commit f7bb658124)

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
2024-12-02 15:42:02 +01:00
Bénédikt Tran
943e57e1ce
[3.13] Fix Unicode encode_wstr_utf8() (#127420) (#127505)
Fix Unicode encode_wstr_utf8() (#127420)

Raise RuntimeError instead of RuntimeWarning.

Co-authored-by: Victor Stinner <vstinner@python.org>
2024-12-02 13:24:03 +01:00
Miss Islington (bot)
2f56c68dec
[3.13] gh-127316: fix incorrect assertion in setting __class__ in free-threading (GH-127399) (#127422)
gh-127316: fix incorrect assertion in setting `__class__` in free-threading (GH-127399)
(cherry picked from commit 45c5cba318)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2024-11-29 16:36:44 +00:00
Miss Islington (bot)
c74331413e
[3.13] gh-127020: Make PyCode_GetCode thread-safe for free threading (GH-127043) (GH-127107)
Some fields in PyCodeObject are lazily initialized. Use atomics and
critical sections to make their initializations and accesses thread-safe.
(cherry picked from commit 3926842117)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-11-21 16:27:36 +00:00
sobolevn
3fae84fe58
[3.13] gh-126980: Fix bytearray.__buffer__ crash on PyBUF_{READ,WRITE} (GH-126981) (#127023)
(cherry picked from commit 3932e1db53)

Co-authored-by: Victor Stinner <vstinner@python.org>
2024-11-19 20:37:53 +03:00
Miss Islington (bot)
fd276ad328
[3.13] gh-126594: Fix typeobject.c wrap_buffer() cast (GH-126754) (#127004)
gh-126594: Fix typeobject.c wrap_buffer() cast (GH-126754)

Reject flags smaller than INT_MIN.

(cherry picked from commit 84f07c3a4c)

Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-11-19 08:38:06 +00:00
Miss Islington (bot)
3fe062c98d
[3.13] gh-126341: add release check to __iter__ method of memoryview (GH-126759) (#126778)
gh-126341: add release check to `__iter__` method of `memoryview` (GH-126759)
(cherry picked from commit a12690ef49)

Co-authored-by: Ritvik Pasham <ritvikpasham@gmail.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: sobolevn <mail@sobolevn.me>
2024-11-13 19:05:59 +00:00
Miss Islington (bot)
02cd3ce0f2
[3.13] gh-116510: Fix a Crash Due to Shared Immortal Interned Strings (gh-124865) (gh-125709) (GH-125204)
* gh-116510: Fix a Crash Due to Shared Immortal Interned Strings (gh-124865)

Fix a crash caused by immortal interned strings being shared between
sub-interpreters that use basic single-phase init. In that case, the string
can be used by an interpreter that outlives the interpreter that created and
interned it. For interpreters that share obmalloc state, also share the
interned dict with the main interpreter.

This is an un-revert of gh-124646 that then addresses the Py_TRACE_REFS
failures identified by gh-124785.
(cherry picked from commit f2cb399470)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>

* [3.13] gh-125286: Share the Main Refchain With Legacy Interpreters (gh-125709)

They used to be shared, before 3.12.  Returning to sharing them resolves a failure on Py_TRACE_REFS builds.

---------

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2024-11-12 13:45:12 +01:00
Miss Islington (bot)
ce1a1a6021
[3.13] gh-126303: Fix pickling and copying of os.sched_param objects (GH-126336) (GH-126423)
(cherry picked from commit d3840503b0)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-11-05 06:50:33 +00:00
Miss Islington (bot)
f37ac53cd3
[3.13] gh-116938: Fix dict.update docstring and remove erraneous full stop from dict documentation (GH-125421) (#126150)
gh-116938: Fix `dict.update` docstring and remove erraneous full stop from `dict` documentation (GH-125421)
(cherry picked from commit 5527c4051c)

Co-authored-by: Prometheus3375 <35541026+Prometheus3375@users.noreply.github.com>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
2024-10-29 23:27:33 +00:00
Miss Islington (bot)
7b46ae92ad
[3.13] gh-125608: Trigger dictionary watchers when inline values change (GH-125611) (GH-125982)
Dictionary watchers on an object's attributes dictionary
(`object.__dict__`) were not triggered when the managed dictionary used
the object's inline values.
(cherry picked from commit 5989eb7446)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-10-25 14:35:04 +00:00
Shantanu
3d8b6f0977
[3.13] gh-123930: Better error for "from imports" when script shadows module (GH-123929) (#125937)
gh-123930: Better error for "from imports" when script shadows module (#123929)

(cherry picked from commit 500f5338a8)
2024-10-24 19:37:31 +00:00
Miss Islington (bot)
829d650ccb
[3.13] gh-125590: Allow FrameLocalsProxy to delete and pop keys from extra locals (GH-125616) (#125797)
gh-125590: Allow FrameLocalsProxy to delete and pop keys from extra locals (GH-125616)
(cherry picked from commit 5b7a872b26)

Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
2024-10-21 17:06:27 +00:00
Miss Islington (bot)
b3badabcd9
[3.13] gh-125221: Fix free-threading data race in object.__reduce_ex__ (GH-125267) (#125305)
gh-125221: Fix free-threading data race in `object.__reduce_ex__` (GH-125267)
(cherry picked from commit b12e99261e)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-10-11 08:26:23 +00:00
Miss Islington (bot)
84991153da
[3.13] gh-123378: fix a crash in UnicodeError.__str__ (GH-124935) (#125099)
gh-123378: fix a crash in `UnicodeError.__str__` (GH-124935)
(cherry picked from commit ba14dfafd9)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-10-08 12:06:57 +00:00
Victor Stinner
d432fa43b9
[3.13] Fix typos (#123775) (#123866)
Fix typos (#123775)

(cherry picked from commit 9017b95ff2)

Co-authored-by: algonell <algonell@gmail.com>
2024-10-07 23:44:31 +02:00
Miss Islington (bot)
b843974ab4
[3.13] gh-124785: Revert "gh-116510: Fix crash due to shared immortal interned strings (gh-124646)" (gh-124807) (#124812)
gh-124785: Revert "gh-116510: Fix crash due to shared immortal interned strings (gh-124646)" (gh-124807)

Revert "gh-116510: Fix crash due to shared immortal interned strings. (gh-124646)"

This reverts commit 98b2ed7e23.
(cherry picked from commit 7bdfabe2d1)

Co-authored-by: T. Wouters <thomas@python.org>
2024-09-30 18:38:26 -07:00
Miss Islington (bot)
44ba11a204
[3.13] gh-124642: Dictionaries aren't marking objects as weakref'd (GH-124643) (#124798)
gh-124642: Dictionaries aren't marking objects as weakref'd (GH-124643)

Dictionaries aren't marking objects as weakref'd
(cherry picked from commit 077e7ef6a0)

Co-authored-by: Dino Viehland <dinoviehland@meta.com>
2024-09-30 13:51:24 -07:00
Serhiy Storchaka
5bf32d1300
[3.13] gh-123339: Fix cases of inconsistency of __module__ and __firstlineno__ in classes (GH-123613) (#124735)
* Setting the __module__ attribute for a class now removes the
  __firstlineno__ item from the type's dict.
* The _collections_abc and _pydecimal modules now completely replace the
  collections.abc and decimal modules after importing them. This
  allows to get the source of classes and functions defined in these
  modules.
* inspect.findsource() now checks whether the first line number for a
  class is out of bound.
(cherry picked from commit 69a4063ca5)
2024-09-29 21:21:40 -07:00
Miss Islington (bot)
a1a4cfcc8e
[3.13] gh-123826: Fix unused function warnings in mimalloc on NetBSD (GH-123827) (#123875)
gh-123826: Fix unused function warnings in mimalloc on NetBSD (GH-123827)
(cherry picked from commit 4a6b1f1796)

Co-authored-by: Furkan Onder <furkanonder@protonmail.com>
2024-09-30 01:58:09 +00:00
Miss Islington (bot)
4c3d537531
[3.13] gh-77894: Fix a crash when the GC breaks a loop containing a memoryview (GH-123898) (#123936)
gh-77894: Fix a crash when the GC breaks a loop containing a memoryview (GH-123898)

Now a memoryview object can only be cleared if there are no buffers
that refer it.
(cherry picked from commit a1dbf2ea69)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-09-29 18:23:42 -07:00
Miss Islington (bot)
62f691f3d1
[3.13] gh-124513: Check args in framelocalsproxy_new() (GH-124515) (#124539)
gh-124513: Check args in framelocalsproxy_new() (GH-124515)

Fix a crash in FrameLocalsProxy constructor: check the number of
arguments.
(cherry picked from commit d6954b6421)

Co-authored-by: Victor Stinner <vstinner@python.org>
2024-09-29 18:03:00 -07:00
Miss Islington (bot)
e20505cb41
[3.13] gh-124498: Fix TypeAliasType not to be generic, when type_params=() (GH-124499) (#124603)
gh-124498: Fix `TypeAliasType` not to be generic, when `type_params=()` (GH-124499)
(cherry picked from commit abe5f799e6)

Co-authored-by: sobolevn <mail@sobolevn.me>
2024-09-29 18:01:06 -07:00
Miss Islington (bot)
80de9766f7
[3.13] GH-124547: Clear instance dictionary if memory error occurs during object dealloc (GH-124627) (#124714)
GH-124547: Clear instance dictionary if memory error occurs during object dealloc (GH-124627)
(cherry picked from commit 0e21cc6cf8)

Co-authored-by: Mark Shannon <mark@hotpy.org>
2024-09-27 15:23:39 -07:00
Miss Islington (bot)
c6c3d970ba
[3.13] gh-119004: fix a crash in equality testing between OrderedDict (GH-121329) (#124507)
gh-119004: fix a crash in equality testing between `OrderedDict` (GH-121329)
(cherry picked from commit 38a887dc3e)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-09-27 11:34:48 -07:00
Miss Islington (bot)
dc09a0c67f
[3.13] gh-116510: Fix crash due to shared immortal interned strings. (gh-124646) (#124648)
gh-116510: Fix crash due to shared immortal interned strings. (gh-124646)
(cherry picked from commit 98b2ed7e23)

Co-authored-by: Neil Schemenauer <nas-github@arctrix.com>
2024-09-27 11:15:25 -07:00
Miss Islington (bot)
22dee7b695
[3.13] gh-124538: Fix crash when using gc.get_referents on an untracked capsule object (GH-124559) (#124588)
gh-124538: Fix crash when using `gc.get_referents` on an untracked capsule object (GH-124559)
(cherry picked from commit f923605658)

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2024-09-26 13:51:58 -07:00
Petr Viktorin
d655c65561
[3.13] gh-123091: Use more _Py_IsImmortalLoose() (GH-123602) (GH-123622)
Switch more _Py_IsImmortal(...) assertions to _Py_IsImmortalLoose(...)

The remaining calls to _Py_IsImmortal are in free-threaded-only code,
initialization of core objects, tests, and guards that fall back to
code that works with mortal objects.

(cherry picked from commit 57c471a688)
2024-09-03 12:36:42 +02:00
Victor Stinner
10735bff9e
[3.13] gh-123091: Use _Py_IsImmortalLoose() (#123511) (#123600)
gh-123091: Use _Py_IsImmortalLoose() (#123511)

Use _Py_IsImmortalLoose() in bytesobject.c, typeobject.c
and ceval.c.

(cherry picked from commit f1a0d96f41)
2024-09-02 15:23:29 +02:00
Serhiy Storchaka
8b6dd92db7
[3.13] gh-122688: Fix support of var-positional parameter in Argument Clinic (GH-122689) (#122852)
* Parameters after the var-positional parameter are now keyword-only
  instead of positional-or-keyword.
* Correctly calculate min_kw_only.
* Raise errors for invalid combinations of the var-positional parameter
  with "*", "/" and deprecation markers.
(cherry picked from commit 8393608dd9)
2024-09-02 13:03:04 +02:00
Miss Islington (bot)
57ba3b0c6e
[3.13] gh-122527: Fix a crash on deallocation of PyStructSequence (GH-122577) (#122625)
gh-122527: Fix a crash on deallocation of `PyStructSequence` (GH-122577)

The `PyStructSequence` destructor would crash if it was deallocated after
its type's dictionary was cleared by the GC, because it couldn't compute
the "real size" of the instance. This could occur with relatively
straightforward code in the free-threaded build or with a reference
cycle involving the type in the default build, due to differing orders
in which `tp_clear()` was called.

Account for the non-sequence fields in `tp_basicsize` and use that,
along with `Py_SIZE()`, to compute the "real" size of a
`PyStructSequence` in the dealloc function. This avoids the accesses to
the type's dictionary during dealloc, which were unsafe.
(cherry picked from commit 4b63cd170e)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-09-02 12:47:18 +02:00
Miss Islington (bot)
bd29ce8509
[3.13] gh-123448: Move _PyNoDefault_Type to the static types array (GH-123449) (#123450)
(cherry picked from commit c9930f5022)

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2024-08-28 18:57:28 -07:00
Miss Islington (bot)
abaaaff328
[3.13] gh-122982: Extend the deprecation period for bool inversion by two years (GH-123306) (#123316)
gh-122982: Extend the deprecation period for bool inversion by two years (GH-123306)
(cherry picked from commit 249b083ed8)

Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
2024-08-25 19:48:34 +00:00
Miss Islington (bot)
95b4f9c9ad
[3.13] GH-120097: Make FrameLocalsProxy a mapping (GH-120101) (GH-120749)
Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>
2024-08-23 10:26:03 +01:00
Donghee Na
6cd67e413b
[3.13] gh-123083: Fix a potential use-after-free in ``STORE_ATTR_WITH… (#123235)
[3.13] gh-123083: Fix a potential use-after-free in ``STORE_ATTR_WITH_HINT`` (gh-123092)
(cherry picked from commit 297f2e093e)
2024-08-23 01:37:26 +09:00
Miss Islington (bot)
ff58c3cb48
[3.13] gh-123022: Fix crash with Py_Initialize in background thread (GH-123052) (#123114)
Check that the current default heap is initialized in
`_mi_os_get_aligned_hint` and `mi_os_claim_huge_pages`.

The mimalloc function `_mi_os_get_aligned_hint` assumes that there is an
initialized default heap. This is true for our main thread, but not for
background threads. The problematic code path is usually called during
initialization (i.e., `Py_Initialize`), but it may also be called if the
program allocates large amounts of memory in total.

The crash only affected the free-threaded build.
(cherry picked from commit d061ffea7b)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-08-17 20:38:02 +00:00
Miss Islington (bot)
55aede7342
[3.13] gh-122888: Fix crash on certain calls to str() (GH-122889) (#122947)
Fixes GH-122888
(cherry picked from commit 53ebb6232a)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-08-12 16:53:05 +00:00
Miss Islington (bot)
c1efeb3234
[3.13] gh-120974: Make asyncio swap_current_task safe in free-threaded build (GH-122317) (#122612)
gh-120974: Make asyncio `swap_current_task` safe in free-threaded build (GH-122317)

* gh-120974: Make asyncio `swap_current_task` safe in free-threaded build
(cherry picked from commit b5e6fb39a2)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-08-02 13:58:24 +00:00