Commit graph

9080 commits

Author SHA1 Message Date
Pablo Galindo Salgado
cba2974a54
[3.13] gh-136541: Fix several problems of perf trampolines in x86_64 and aarch64 (GH-136500) (#136545)
This commit fixes the following problems:

* The x86_64 trampolines are not preserving frame pointers
* The hardcoded offsets to the code segment from the FDE only worked properly for x64_64
* The CIE data was not following conventions of aarch64
* The eh_frame for aarch64 was not fully correct
(cherry picked from commit 236f733d8f)
2025-07-11 14:02:19 +00:00
Miss Islington (bot)
2362cb6c6e
[3.13] gh-109700: fix interpreter finalization while handling memory error (GH-136342) (#136353)
gh-109700: fix interpreter finalization while handling memory error (GH-136342)
(cherry picked from commit 0c3e3da195)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2025-07-07 07:37:35 +00:00
Sam Gross
c64df2a3ec
[3.13] gh-135871: Fix needless spinning in _PyMutex_LockTimed with zero timeout (gh-135872) (gh-135947)
The free threading build could spin unnecessarily on `_Py_yield()` if the initial
compare and swap failed.
(cherry picked from commit cbfaf41caf)

Co-authored-by: Joseph Tibbertsma <josephtibbertsma@gmail.com>
2025-06-25 17:09:17 +00:00
Brian Schubert
3e4362812e
[3.13] gh-135855: Raise TypeError When Passing Non-dict Object to _interpreters.set___main___attrs (gh-135903)
Some checks are pending
Tests / (push) Blocked by required conditions
Tests / Windows MSI (push) Blocked by required conditions
Tests / Change detection (push) Waiting to run
Tests / Docs (push) Blocked by required conditions
Tests / Check if the ABI has changed (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run
(cherry picked from commit 4e6f0d116e, AKA gh-135856)
2025-06-24 16:23:26 -06:00
T. Wouters
6ae51582a1
[3.13] GH-135171: Roll back all fixes for GH-127682 as they are not suitable for 3.13 (#135390) 2025-06-11 16:57:35 +02:00
stratakis
65192572d2
[3.13] gh-128605: Add branch protections for x86_64 in asm_trampoline.S (#128606) (#135353)
Apply Intel Control-flow Technology for x86-64 on asm_trampoline.S.

Required for mitigation against return-oriented programming (ROP)
and Call or Jump Oriented Programming (COP/JOP) attacks.

Manual application is required for the assembly files.

See also: https://sourceware.org/annobin/annobin.html/Test-cf-protection.html
2025-06-11 12:09:20 +02:00
Miss Islington (bot)
857647fa67
[3.13] Heavily comment Python/perf_jit_trampoline.c to improve maintainability (GH-134527) (#135300)
Some checks are pending
Tests / Windows MSI (push) Blocked by required conditions
Tests / (push) Blocked by required conditions
Tests / Change detection (push) Waiting to run
Tests / Docs (push) Blocked by required conditions
Tests / Check if the ABI has changed (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run
2025-06-09 22:09:37 +01:00
Miss Islington (bot)
f9c18bab7f
[3.13] gh-128605: Revert "Add branch protections for x86_64 in asm_tr…ampoline.S (GH-128606) (GH-135077)" (GH-135175) (GH-135203)
[3.14] gh-128605: Revert "Add branch protections for x86_64 in asm_tr…ampoline.S (GH-128606) (GH-135077)" (GH-135175)

This reverts commit 899cca6dbf,
which broke buildbots.
(cherry picked from commit b477e21d5c)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
2025-06-06 16:09:09 +02:00
Miss Islington (bot)
9f3d99967c
[3.13] gh-128605: Add branch protections for x86_64 in asm_trampoline.S (GH-128606) (GH-135077) (#135083)
[3.14] gh-128605: Add branch protections for x86_64 in asm_trampoline.S (GH-128606) (GH-135077)

Apply Intel Control-flow Technology for x86-64 on asm_trampoline.S.

Required for mitigation against return-oriented programming (ROP)
and Call or Jump Oriented Programming (COP/JOP) attacks.

Manual application is required for the assembly files.

See also: https://sourceware.org/annobin/annobin.html/Test-cf-protection.html
(cherry picked from commit 899cca6dbf)

Co-authored-by: stratakis <cstratak@redhat.com>
2025-06-03 13:54:53 +00:00
Mark Shannon
c6af7f4bf7
[3.13] GH-128161: Fix refleak introduced in GH-134788 (GH-134799) 2025-05-27 18:14:56 +01:00
Mark Shannon
814ac0d587
[3.13] gh-128161: Remove redundant GET_ITER from list comprehension code (backport of GH-134778) (GH-134788) 2025-05-27 14:12:04 +01:00
Miss Islington (bot)
523024499e
[3.13] gh-134100: Fix use-after-free in PyImport_ImportModuleLevelObject (GH-134117) (#134172)
gh-134100: Fix use-after-free in `PyImport_ImportModuleLevelObject` (GH-134117)
(cherry picked from commit 4e9005d32f)

Co-authored-by: Nico-Posada <102486290+Nico-Posada@users.noreply.github.com>
2025-05-18 20:38:28 +05:30
Victor Stinner
5cd56b249f
[3.13] gh-133441: Fix STORE_ATTR_WITH_HINT bytecode (#133446)
Deoptimize if the dict is a dict subclass.

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2025-05-11 23:10:04 +02:00
Miss Islington (bot)
e0aefbd263
gh-133597: Fix memory leak if error occurred in _sys_getwindowsversion_from_kernel32 (GH-133598)
(cherry picked from commit 0ec8fc83a8)

Co-authored-by: Sergey Miryanov <sergey.miryanov@gmail.com>
2025-05-08 11:32:59 +00:00
Mark Shannon
132bdf6990
[3.13] GH-127682: Backport GH-132351 (GH-132384)
Only call `__iter__` once in generator expressions
2025-04-29 09:35:29 +01:00
Bénédikt Tran
7ebfc6ec5e
[3.13] gh-132909: handle overflow for 'K' format in do_mkvalue (GH-132911) (#132932)
(cherry picked from commit 3fa024dec3)
2025-04-25 12:44:53 +00:00
Bartosz Sławecki
582d1ef463
[3.13] gh-130070: Fix exec(<string>, closure=<non-None>) unexpected path (GH-130071) (#132627)
gh-130070: Fix `exec(<string>, closure=<non-None>)` unexpected path (#130071)

Fixed an assertion error (so, it could be reproduced only in builds with assertions enabled)
for `exec` when the `source` argument is a string and the `closure` argument is not `None`.

Co-authored-by: sobolevn <mail@sobolevn.me>
(cherry picked from commit 954b2cf031)
2025-04-17 09:21:56 +00:00
Serhiy Storchaka
f218549afc
[3.13] gh-124476: Fix decoding from the locale encoding in the C.UTF-8 locale (GH-132477) (ПР-132528)
(cherry picked from commit 102f825c51)
2025-04-14 18:59:07 +00:00
Tomas R.
4ff5d88fb1
[3.13] gh-131927: Prevent emitting compiler warnings twice (GH-131993) (GH-132463)
(cherry picked from commit 3d08c8ad20)
2025-04-13 08:42:04 +00:00
Peter Bierma
5911768600
[3.13] gh-131998: Fix NULL dereference when using an unbound method descriptor in a specialized code path (GH-132000) (#132262)
(cherry picked from commit ac3c439cdf)

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: sobolevn <mail@sobolevn.me>
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Mark Shannon <mark@hotpy.org>
2025-04-08 11:02:29 +00:00
sobolevn
7a8364460d
[3.13] gh-130775: Allow negative locations in ast (GH-130795) (#132243)
(cherry picked from commit bc5233b6a5)

Co-authored-by: Victor Stinner <vstinner@python.org>
2025-04-08 10:47:24 +02:00
Mark Shannon
3f3863281b
[3.13] GH-127953: Make line number lookup O(1) regardless of the size of the code object (#129127)
GH-127953: Make line number lookup O(1) regardless of the size of the code object (GH-128350)
2025-04-07 20:15:02 +02:00
Sam Gross
1fcf409ace
[3.13] gh-131988: Fix a multithreaded scaling regression (#131989)
gh-131988: Fix a multithreaded scaling regression

The 3.13 free threaded build immortalizes certain objects to avoid
reference count contention. In gh-127114 the condition was
unintentionally changed to happen when the first thread was created
instead of the first non-main thread. The `interp->gc.immortalize` field
is then cleared again during `_PyGC_Init()`.

Change the condition so that we check if we should immortalize objects
using deferred reference counting whenever a non-main thread is created.
2025-04-07 20:13:02 +02:00
sobolevn
5fb9fe0e3e
[3.13] gh-132011: Fix crash on invalid CALL_LIST_APPEND deoptimization (GH-132018) (#132161)
* [3.13] gh-132011: Fix crash on invalid `CALL_LIST_APPEND` deoptimization (GH-132018)
(cherry picked from commit c0661df42a)

Co-authored-by: sobolevn <mail@sobolevn.me>
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2025-04-06 17:08:48 +00:00
Miss Islington (bot)
240c200cce
[3.13] gh-130115: fix thread identifiers for 32-bit musl (GH-130391) (GH-132089)
CPython's pthread-based thread identifier relies on pthread_t being able
to be represented as an unsigned integer type.

This is true in most Linux libc implementations where it's defined as an
unsigned long, however musl typedefs it as a struct *.

If the pointer has the high bit set and is cast to PyThread_ident_t, the
resultant value can be sign-extended [0]. This can cause issues when
comparing against threading._MainThread's identifier. The main thread's
identifier value is retrieved via _get_main_thread_ident which is backed
by an unsigned long which truncates sign extended bits.

  >>> hex(threading.main_thread().ident)
  '0xb6f33f3c'
  >>> hex(threading.current_thread().ident)
  '0xffffffffb6f33f3c'

Work around this by conditionally compiling in some code for non-glibc
based Linux platforms that are at risk of sign-extension to return a
PyLong based on the main thread's unsigned long thread identifier if the
current thread is the main thread.

[0]: https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Arrays-and-pointers-implementation.html

---------
(cherry picked from commit 72123063dd)

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Co-authored-by: Vincent Fazio <vfazio@gmail.com>
2025-04-04 22:57:35 +02:00
Tomasz Pytel
900dc2b034
[3.13] gh-128632: fix segfault on nested __classdict__ type param (GH-128744) (#132085)
(cherry picked from commit 891c61c1fa)

Co-authored-by: Tomasz Pytel <tompytel@gmail.com>
2025-04-04 08:23:40 -07:00
Miss Islington (bot)
57e4f0886d
[3.13] gh-132002: Fix crash of ContextVar on unhashable str subtype (GH-132003) (#132007)
gh-132002: Fix crash of `ContextVar` on unhashable `str` subtype (GH-132003)
(cherry picked from commit ab2a3dda1d)

Co-authored-by: sobolevn <mail@sobolevn.me>
2025-04-02 12:15:44 +00:00
Miss Islington (bot)
5547c895e2
[3.13] gh-131818: Add imply -P in -I's help message (GH-131819) (#131822)
gh-131818: Add imply `-P` in `-I`'s help message (GH-131819)
(cherry picked from commit 8bd88e2827)

Co-authored-by: Hang <bebound@gmail.com>
2025-03-28 08:13:00 +00:00
Donghee Na
9d3f538471
[3.13] gh-131740: Update PyUnstable_GC_VisitObjects to traverse perm … (gh-131754)
* [3.13] gh-131740: Update PyUnstable_GC_VisitObjects to traverse perm gen (gh-131744)

(cherry picked from commit 7bb41aef4b)

* fix
2025-03-27 02:43:16 +09:00
Miss Islington (bot)
3492098418
[3.13] gh-131670: Fix crash in anext() when __anext__ is sync and raises (GH-131682) (#131686)
gh-131670: Fix crash in `anext()` when `__anext__` is sync and raises (GH-131682)
(cherry picked from commit 929afd1d6e)

Co-authored-by: sobolevn <mail@sobolevn.me>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-03-24 19:27:01 +00:00
Miss Islington (bot)
94fbe97bbe
[3.13] gh-117657: Fix TSAN data race in _PyEval_SetTrace assertion (gh-131561) (#131564)
The `sys_tracing_threads` variable should be read inside `LOCK_SETUP()`.
(cherry picked from commit 0de5e0c544)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2025-03-21 18:48:40 +00:00
Sam Gross
5646f6f739
[3.13] gh-130382: add missing _PyReftracerTrack to ceval Py_DECREF (GH-130689) (#131195)
(cherry picked from commit c5abded099)

Co-authored-by: Tomasz Pytel <tompytel@gmail.com>
2025-03-14 09:52:05 -04:00
Kumar Aditya
589382bd04
[3.13] gh-131141: fix data race in instrumentation while registering callback (#131166) 2025-03-13 09:41:26 +00:00
Russell Keith-Magee
589f422d1b
[3.13] gh-130940: Remove PyConfig.use_system_logger (#131129)
Removes ``PyConfig.use_system_logger``, resolving an ABI incompatibility introduced in
3.13.2.

Changes the default behavior of iOS to *always* direct stdout/stderr to the system log.
2025-03-13 11:53:11 +08:00
Miss Islington (bot)
f9d19a3ada
[3.13] gh-131082: Add missing guards for WIN32_LEAN_AND_MEAN (GH-131044) (#131084)
(cherry picked from commit de8818ae23)

Co-authored-by: Max Bachmann <kontakt@maxbachmann.de>
2025-03-11 11:56:54 +00:00
Miss Islington (bot)
c7022230d2
[3.13] gh-117174: Add a new route in linecache to fetch interactive source code (GH-117500) (#131060)
gh-117174: Add a new route in linecache to fetch interactive source code (GH-117500)
(cherry picked from commit a931a8b324)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2025-03-10 23:11:24 +00:00
Sam Gross
07522755ae
[3.13] gh-130794: Process interpreter QSBR queue in _PyMem_AbandonDelayed. (gh-130808) (#130857)
This avoids a case where the interpreter's queue of memory to be freed
could grow rapidly if there are many short lived threads.
(cherry picked from commit 2f6e0e9f70)
2025-03-04 23:35:22 +00:00
Bénédikt Tran
00cf2a621a
[3.13] gh-130740: Move some stdbool.h includes after Python.h (#130738) (#130756)
gh-130740: Move some `stdbool.h` includes after `Python.h` (#130738)

Move some `#include <stdbool.h>` after `#include "Python.h"` when `pyconfig.h` is not
included first and when we are in a platform-agnostic context. This is to avoid having
features defined by `stdbool.h` before those decided by `Python.h` (this caused some
build failures when compiling CPython with `zig cc`).

(cherry-picked from commit 214562ed4d)

---------

Co-authored-by: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
2025-03-03 13:09:59 +01:00
Victor Stinner
9184b1b031
[3.13] Postpone <stdbool.h> inclusion after Python.h (#130641) (#130675)
Postpone <stdbool.h> inclusion after Python.h (#130641)

Remove inclusions prior to Python.h.

<stdbool.h> will cause <features.h> to be included before Python.h can
define some macros to enable some additional features, causing multiple
types not to be defined down the line.

(cherry picked from commit 830f04b505)

Co-authored-by: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
2025-02-28 09:40:06 +00:00
Serhiy Storchaka
7c1b76fce8
[3.13] gh-130163: Fix crashes related to PySys_GetObject() (GH-130503) (GH-130556)
The use of PySys_GetObject() and _PySys_GetAttr(), which return a borrowed
reference, has been replaced by using one of the following functions, which
return a strong reference and distinguish a missing attribute from an error:
_PySys_GetOptionalAttr(), _PySys_GetOptionalAttrString(),
_PySys_GetRequiredAttr(), and _PySys_GetRequiredAttrString().
(cherry picked from commit 0ef4ffeefd)
2025-02-25 22:50:26 +00:00
Miss Islington (bot)
9e23e0ad2c
[3.13] Update manpage environment variables and command line arguments (GH-129623) (#130078)
Co-authored-by: Stefano Rivera <stefano@rivera.za.net>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2025-02-13 16:42:21 +02:00
Donghee Na
f7af8bc58a
[3.13] gh-129533: Update PyGC_Enable/Disable/IsEnabled to use atomic operat… (gh-129756)
gh-129533: Update PyGC_Enable/Disable/IsEnabled to use atomic operation  (gh-129563)

(cherry picked from commit b184abf074)
2025-02-06 23:11:17 +00:00
Sam Gross
f7cc862345
[3.13] gh-129732: Fix race on shared->array in qsbr code under free-threading (gh-129738) (gh-129747)
The read of `shared->array` should happen under the lock to avoid a race.
(cherry picked from commit b4ff8b22b3)

Co-authored-by: Peter Hawkins <phawkins@google.com>
2025-02-06 14:30:16 -05:00
Miss Islington (bot)
0468ea1230
[3.13] gh-126108: Fix potential null pointer dereference in PySys_AddWarnOptionUnicode (GH-126118) (#129520)
gh-126108: Fix potential null pointer dereference in `PySys_AddWarnOptionUnicode` (GH-126118)
(cherry picked from commit fad36bf382)

Co-authored-by: Valery Fedorenko <federicovalenso@gmail.com>
2025-01-31 20:32:44 +05:30
Irit Katriel
a853e2f076
[3.13] gh-128799: Add frame of except* to traceback when wrapping a naked exception (#128971) (#129299) 2025-01-30 12:20:13 +00:00
Victor Stinner
1ee321b4c0
[3.13] gh-128679: Clear the ref tracer in _PyTraceMalloc_Stop() (#129258)
_PyTraceMalloc_Stop() now calls PyRefTracer_SetTracer(NULL, NULL).
2025-01-24 14:54:02 +01:00
Victor Stinner
e3b3e01d6a
[3.13] gh-129185: Fix PyTraceMalloc_Untrack() at Python exit (#129191) (#129217)
gh-129185: Fix PyTraceMalloc_Untrack() at Python exit (#129191)

Support calling PyTraceMalloc_Track() and PyTraceMalloc_Untrack()
during late Python finalization.

* Call _PyTraceMalloc_Fini() later in Python finalization.
* Test also PyTraceMalloc_Untrack() without the GIL
* PyTraceMalloc_Untrack() now gets the GIL.
* Test also PyTraceMalloc_Untrack() in test_tracemalloc_track_race().

(cherry picked from commit 46c7e13c05)
2025-01-23 13:59:19 +01:00
Victor Stinner
6b47499510
[3.13] gh-128679: Fix tracemalloc.stop() race conditions (#128897)
tracemalloc_alloc(), tracemalloc_realloc(), PyTraceMalloc_Track(),
PyTraceMalloc_Untrack() and _PyTraceMalloc_TraceRef() now check
tracemalloc_config.tracing after calling TABLES_LOCK().

_PyTraceMalloc_Stop() now protects more code with TABLES_LOCK(),
especially setting tracemalloc_config.tracing to 1.

Add a test using PyTraceMalloc_Track() to test tracemalloc.stop()
race condition.

Call _PyTraceMalloc_Init() at Python startup.
2025-01-18 23:39:07 +00:00
Peter Bierma
1ec36a62eb
[3.13] gh-128717: Stop-the-world when setting the recursion limit (GH-128741) (#128757)
[3.13] gh-128717: Stop-the-world when setting the recursion limit (GH-128741)
(cherry picked from commit f6c61bf2d7)

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2025-01-14 13:33:52 +05:30
Miss Islington (bot)
bbe0b33d2a
[3.13] gh-128146: Exclude os/log.h import on older macOS versions. (GH-128165) (#128575)
gh-128146: Exclude os/log.h import on older macOS versions. (GH-128165)

Reworks the handling of Apple system log handling to account for older macOS
versions that don't provide os-log.
(cherry picked from commit e837a1f71e)

Co-authored-by: Russell Keith-Magee <russell@keith-magee.com>
2025-01-07 05:36:00 +00:00