9940 Commits
Author SHA1 Message Date
Pablo Galindo Salgado 04735deeb2 [3.14] gh-149619: Harden _remote_debugging error paths (GH-150349) (#154844)
(cherry picked from commit a5be25d3bd)
2026-07-28 23:46:43 +01:00
Pablo Galindo Salgadoandivonastojanovic c533f180e0 [3.14] gh-149619: Fix _remote_debugging permissions error on Linux (GH-150012) (#154825)
When running profiling on Linux without sudo, attempts to read
process memory would fail with the misleading error 'Failed to find
the PyRuntime section in process <pid> on Linux platform'.

The actual issue is a permissions error because profiling was not
run with sudo. We were clearing the exception on Linux when trying
to read memory, instead, we should bubble up the permissions error
and show it properly.

(cherry picked from commit 0563890872)

Co-authored-by: ivonastojanovic <80911834+ivonastojanovic@users.noreply.github.com>
2026-07-28 22:53:39 +01:00
Miss Islington (bot)andCarlo Bramini 6065d74ca7 [3.14] gh-152903: Change PCWSTR to PWSTR in GetThreadDescription() typedef (GH-152904) (#152944)
gh-152903: Change PCWSTR to PWSTR in GetThreadDescription() typedef (GH-152904)

Fixes issue GH-152903
(cherry picked from commit ac1acb6d7d)

Co-authored-by: Carlo Bramini <carlo_bramini@users.sourceforge.net>
2026-07-26 18:27:03 +00:00
Serhiy StorchakaandClaude Opus 4.8 903265fd16 [3.14] gh-154283: Make threading.get_native_id() unique across processes on DragonFly (GH-154287) (GH-154297)
On DragonFly BSD lwp_gettid() is only unique within a process (the main
thread is always LWP 1), so combine it with the process id, like Solaris.
(cherry picked from commit 53597df11e)

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-20 20:21:13 +00:00
1ba35ca180 [3.14] gh-151644: Fix data race in sys.setdlopenflags/getdlopenflags under free-threading (gh-151768) (gh-153789)
In free-threading builds, concurrent calls to sys.getdlopenflags() and
sys.setdlopenflags() race on interp->imports.dlopenflags.  Fix by
using FT_ATOMIC_LOAD_INT_RELAXED / FT_ATOMIC_STORE_INT_RELAXED in
_PyImport_GetDLOpenFlags and _PyImport_SetDLOpenFlags, consistent with
how analogous interpreter-state integer fields (lazy_imports_mode,
pystats_enabled) are protected.

Relaxed ordering is correct here: dlopenflags is a standalone config
integer with no ordering relationship to other memory.

(cherry picked from commit cde31ec135)

Co-authored-by: Jiucheng(Oliver) <git.jiucheng@gmail.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-17 13:13:30 -07:00
Victor Stinner 6374772d8c [3.14] gh-152132: Test Py_CompileString() in test_capi.test_run (#153470) (#153473)
gh-152132: Test Py_CompileString() in test_capi.test_run (#153470)

PyRun functions now raises ValueError if the start argument is
invalid.

Add Modules/_testlimitedcapi/run.c.

(cherry picked from commit d83d26724b)
2026-07-10 02:08:14 +00:00
Victor Stinner 62c34a62c2 [3.14] gh-152132: Fix Py_RunMain() to return an exit code (#153446) (#153455)
gh-152132: Fix Py_RunMain() to return an exit code (#153446)

* Fix Py_RunMain() to return an exit code, rather than calling
  Py_Exit(), when running a script, a command, or the REPL.
* _PyRun_SimpleFile() now logs errors to stderr, for example if setting
  __main__.__file__ fails.
* Add tests on Py_RunMain() exitcode.
* Rename functions:

  * _PyRun_SimpleStringFlagsWithName() => _PyRun_SimpleString()
  * _PyRun_SimpleFileObject() => _PyRun_SimpleFile()
  * _PyRun_AnyFileObject() => _PyRun_AnyFile()
  * _PyRun_InteractiveLoopObject() => _PyRun_InteractiveLoop()

* Change _PyRun_SimpleString(), _PyRun_SimpleFile(), _PyRun_AnyFile() and
  _PyRun_InteractiveLoop() return type to PyObject*.
* pymain_repl() now displays the error if PySys_Audit() or
  import _pyrepl failed.
* PyRun_SimpleFileExFlags() and PyRun_AnyFileExFlags() now log
  PyUnicode_DecodeFSDefault() error. So these functions can no longer
  return -1 with an exception set.

(cherry picked from commit fac72f1ee9)
2026-07-09 21:37:45 +02:00
Miss Islington (bot)andVictor Stinner 246d9ad255 [3.14] gh-152132: Test all PyRun functions in test_capi.test_run (GH-153352) (#153412)
gh-152132: Test all PyRun functions in test_capi.test_run (GH-153352)

PyRun_InteractiveOneObjectEx() now raises TypeError if the second
parameter type is not str.
(cherry picked from commit cd9994e283)

Co-authored-by: Victor Stinner <vstinner@python.org>
2026-07-09 11:18:23 +00:00
Victor Stinner 6241d0d46b [3.14] gh-153300: Set global configuration variables in PyConfig_Set() (#153301) (#153359)
gh-153300: Set global configuration variables in PyConfig_Set() (#153301)

PyConfig_Set() now also set global configuration variables. For
example, PyConfig_Set("inspect", value) now also sets Py_InspectFlag.

Use PyConfig_Set() in main.c to set the inspect flag. Python code can
now see the updated sys.flags.inspect value.

(cherry picked from commit 9fb713f1b8)
2026-07-08 20:20:45 +02:00
Miss Islington (bot)andsobolevn 3d802b5be9 [3.14] gh-153252: Fix error handling in _PyCompile_CodeGen (GH-153253) (#153282)
gh-153252: Fix error handling in `_PyCompile_CodeGen` (GH-153253)
(cherry picked from commit a74280e669)

Co-authored-by: sobolevn <mail@sobolevn.me>
2026-07-07 18:02:59 +00:00
97a45b0d00 [3.14] gh-153205: Set MemoryError in stackref array conversion (GH-153206) (#153273)
gh-153205: Set `MemoryError` in stackref array conversion (GH-153206)
(cherry picked from commit 08759ff101)

Co-authored-by: An Long <aisk@users.noreply.github.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: sobolevn <mail@sobolevn.me>
2026-07-07 16:32:27 +00:00
0903be826a [3.14] gh-152682: Fix NULL dereference on OOM in symtable_visit_type_param_bound_or_default (GH-152684) (#152696)
In `symtable_visit_type_param_bound_or_default()`, when a reserved name
(e.g. `__classdict__`) is used as a type parameter, `PyUnicode_FromFormat()`
is called to build the SyntaxError message. If the allocation fails and
returns NULL, the subsequent `PyErr_SetObject()` and `Py_DECREF()` calls
would dereference NULL, causing a segfault.

Fix by returning 0 immediately when `PyUnicode_FromFormat()` returns NULL.
This propagates the MemoryError set by `PyUnicode_FromFormat()`.

The bug was introduced in gh-128632 (commit 891c61c).
(cherry picked from commit 10ed03edf1)

Co-authored-by: Petr Vaganov <petrvaganoff@gmail.com>

* Remove test

---------

Co-authored-by: Petr Vaganov <petrvaganoff@gmail.com>
Co-authored-by: Stan Ulbrych <stan@python.org>
2026-07-06 17:35:58 +01:00
d80f581faa [3.14] gh-152849: Fix OverflowError message for out-of-range timestamps in the time module (GH-152850) (#153208)
(cherry picked from commit 2d7a74ece7)

Co-authored-by: tonghuaroot (童话) <tonghuaroot@gmail.com>
Co-authored-by: Stan Ulbrych <stan@python.org>
2026-07-06 15:16:34 +00:00
Miss Islington (bot) 74c8d5ce0f [3.14] gh-151763: Fix OOM-0013 crash when the parser or compiler fails to allocate (GH-151968) (#152837) 2026-07-02 09:23:07 +01:00
Miss Islington (bot)andsobolevn fd4965de33 [3.14] gh-151126: Fix a possible crash during the startup with no memory under Py_STACKREF_DEBUG (GH-152478) (#152678)
gh-151126: Fix a possible crash during the startup with no memory under `Py_STACKREF_DEBUG` (GH-152478)
(cherry picked from commit ecdef17730)

Co-authored-by: sobolevn <mail@sobolevn.me>
2026-06-30 11:55:16 +00:00
Miss Islington (bot)andStan Ulbrych be68d9abca [3.14] gh-152375: Fix undefined behaviour in the INSTRUMENTED_JUMP macro (GH-152376) (#152567)
(cherry picked from commit cdec9acd63)

Co-authored-by: Stan Ulbrych <stan@python.org>
2026-06-29 09:40:05 +00:00
Łukasz Langa 9a9bceb953 [3.14] gh-151029: Fix sys.remote_exec() unable to find writable memory when libpython replaced on disk (GH-151032) (#152464) 2026-06-28 16:43:14 +02:00
Miss Islington (bot)andAmrutha 33b5aebfd4 [3.14] gh-151842: Fix crash upon OOM in _interpreters.capture_exception (GH-151843) (GH-152032)
(cherry picked from commit 5e0747db2f)

Co-authored-by: Amrutha <amruthamodela06@gmail.com>
2026-06-23 20:57:34 +00:00
Miss Islington (bot)anddev b471b4a6ba [3.14] gh-151773: Fix NULL dereference in PyContextVar_Set (GH-151836) (#152010)
gh-151773: Fix NULL dereference in `PyContextVar_Set` (GH-151836)
(cherry picked from commit d35b1719a5)

Co-authored-by: dev <b.chouksey27@gmail.com>
2026-06-23 14:41:31 +00:00
Miss Islington (bot)andDaniele Parmeggiani c1104577bf [3.14] gh-150902: Optimize PyCriticalSection2 to skip locking the same locks held by the current CS2 (gh-151555)
This mimics an optimization already present for the single-mutex critical section.
(cherry picked from commit c2ca7724af)

Co-authored-by: Daniele Parmeggiani <8658291+dpdani@users.noreply.github.com>
2026-06-19 09:51:55 -04:00
Victor Stinner c005251a2d [3.14] gh-151546: Fix stack limits on musl (#151548) (#151583) (#151591)
[3.15] gh-151546: Fix stack limits on musl (#151548) (#151583)

gh-151546: Fix stack limits on musl (#151548)

If the thread stack size is set by linker flags, pass the stack size
to Python/ceval.c via the new _Py_LINKER_THREAD_STACK_SIZE variable
to set Py_C_STACK_SIZE macro.

(cherry picked from commit 9a61d1c0c8)
(cherry picked from commit a5c5edddbc)
2026-06-17 09:41:24 +00:00
Victor StinnerandBénédikt Tran 60132db980 [3.14] gh-151218: Replace sys.flags in PyConfig_Set() (#151402) (#151553)
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.


(cherry picked from commit b16d23fc9f)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2026-06-16 18:55:35 +02:00
Miss Islington (bot)andStan Ulbrych 5f8546e22f [3.14] gh-151112: Fix crash in compiler_mod() when entering the current compilation unit fails (GH-151234) (#151351)
(cherry picked from commit 937d89c4d9)

Co-authored-by: Stan Ulbrych <stan@python.org>
2026-06-11 15:16:58 +00:00
Miss Islington (bot)andStan Ulbrych 435af7f42b [3.14] gh-151112: Move an assert that may fail in cfg_builder_check (GH-151153)
(cherry picked from commit 2d3381035d)

Co-authored-by: Stan Ulbrych <stan@python.org>
2026-06-11 09:42:53 +00:00
Victor Stinner b3a7758d8a [3.14][3.15] gh-151253: Dump the Python path configuration on _PyCodec_InitRegistry() failure (#151250) (#151269) (#151283)
[3.15] gh-151253: Dump the Python path configuration on _PyCodec_InitRegistry() failure (#151250) (#151269)

gh-151253: Dump the Python path configuration on _PyCodec_InitRegistry() failure (#151250)

If "import encodings" fails at Python startup, dump the Python path
configuration to help users debugging their configuration. The
encodings module is the first module imported during Python startup.

(cherry picked from commit 7b6e98911e)
(cherry picked from commit 10f616cf39)
2026-06-10 20:31:29 +00:00
Victor Stinner 7befb46bb2 [3.14] gh-151278: Fix test_faulthandler on UBSan (#151279) (#151282)
gh-151278: Fix test_faulthandler on UBSan (#151279)

* Py_FatalError() no longer calls _PyFaulthandler_Fini() if it
  doesn't hold the GIL.
* Skip test_faulthandler tests raising signals if run with UBSan.
* Enable test_faulthandler in GitHub Action "Reusable Sanitizer".

(cherry picked from commit e60c42dc3f)
2026-06-10 20:30:10 +00:00
Miss Islington (bot)andBartosz Sławecki 51e83ca706 [3.14] gh-150700: Fix class-scope inline comprehensions when nested scopes reference __class__ and friends (GH-150735) (#151212)
gh-150700: Fix class-scope inline comprehensions when nested scopes reference `__class__` and friends (GH-150735)

* Fix class-scope inline comprehensions when nested scopes reference `__class__` and friends

In `inline_comprehension()`, when `__class__` / `__classdict__` /
`__conditional_annotations__` appears as `FREE` in a comprehension's
symbol table because a nested scope captured it (e.g. nested lambdas),
this name is still discarded from `comp_free` unconditionally.

This prevents `drop_class_free()` from seeing it, so the appropriate
`ste_needs_(...)` flag is never set on the enclosing class.
That leads to `codegen_make_closure()` throwing `SystemError` when it
couldn't find `__class__` / `__classdict__` /
`__conditional_annotations__` in the class's cellvars.

From now on we just discard from `comp_free` when no child scope
(e.g. a lambda) still needs the name as `FREE`. When a child scope does
need it, keep it in `comp_free` so `drop_class_free()` can set the
appropriate flag and the class creates the implicit cell.

* Fix tests

* Fix typo

* Fix formatting

* Add test checking validity of `__class__` returned

* Prefer 'used' to 'deferred'
(cherry picked from commit ce916dc506)

Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com>
2026-06-09 22:48:25 +00:00
Miss Islington (bot)andStan Ulbrych 24cb16ee80 [3.14] gh-151112: Fix double free in assemble_init when out of memory (GH-151142) (#151206)
gh-151112: Fix double free in `assemble_init` when out of memory (GH-151142)
(cherry picked from commit 580499177c)

Co-authored-by: Stan Ulbrych <stan@python.org>
2026-06-09 21:13:45 +01:00
Miss Islington (bot)andsobolevn 5c6402e6a5 [3.14] gh-151126: Fix missing PyErr_NoMemory() in remove_unused_consts (GH-151127) (#151135)
gh-151126: Fix missing `PyErr_NoMemory()` in `remove_unused_consts` (GH-151127)
(cherry picked from commit 3186547c1e)

Co-authored-by: sobolevn <mail@sobolevn.me>
2026-06-09 10:33:08 +00:00
Miss Islington (bot)andThomas Kowalski 0977fc23fd [3.14] gh-150633: Properly handle null characters in the name when importing frozen modules (GH-150634) (GH-151101)
(cherry picked from commit 54de5475cd)

Co-authored-by: Thomas Kowalski <thom.kowa@gmail.com>
2026-06-08 18:56:49 +00:00
Miss Islington (bot)andStan Ulbrych 522fe015ab [3.14] gh-149805: Fix SystemError when compiling __classdict__ class annotation (GH-149806)
(cherry picked from commit c52d2b16dd)

Co-authored-by: Stan Ulbrych <stan@python.org>
2026-06-03 09:39:33 +01:00
7756f59892 [3.14] gh-150319: Replace all documentation which says "See PEP 585" (#150325) (#150813)
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



* Correct several class getitem docs

And expand the text for tuples.



* 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



* Apply suggestions from code review

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



* Update Doc/library/re.rst



* Update Objects/enumobject.c



* 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



* 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.



* 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



* 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: Stephen Rosen <sirosen@globus.org>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Jelle Zijlstra <906600+JelleZijlstra@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2026-06-02 22:22:46 +00:00
Miss Islington (bot)andRussell Keith-Magee 13bb7f7cd7 [3.14] gh-150644: Tag Apple system log messages as public. (GH-150645) (#150739)
macOS 26 changed the default visibility of "dynamic" system messages. This
changes the logging strategy to tag all messages as "public" so they are
visible in the system log without special configuration.
(cherry picked from commit 71fc4c66d3)

Co-authored-by: Russell Keith-Magee <russell@keith-magee.com>
2026-06-01 22:51:07 +00:00
Serhiy Storchaka 49975a511f [3.14] gh-150285: Fix too long docstrings in Argument Clinic code (GH-150338) (GH-150350) (GH-150473)
(cherry picked from commit cf73b17adf)
(cherry picked from commit 287c98f4cb)
2026-05-27 16:24:18 +00:00
Serhiy Storchaka 730fc6a858 [3.14] gh-150285: Fix too long docstrings in builtins (GH-150293) (GH-150466)
(cherry picked from commit e1e06be119)
2026-05-26 10:05:49 +00:00
Miss Islington (bot) 152a9a6db4 [3.14] gh-149156: Fix perf trampoline crash after fork (GH-150347) (#150392) 2026-05-25 18:29:47 +00:00
Miss Islington (bot)andpengyu lee 5676bfcf85 [3.14] gh-150178: Fix refcount leaks in hamt allocation failure paths (GH-150179) (#150302)
gh-150178: Fix refcount leaks in hamt allocation failure paths (GH-150179)
(cherry picked from commit 32823af153)

Co-authored-by: pengyu lee <lipengyu@kylinos.cn>
2026-05-24 07:42:21 +00:00
Victor Stinnerandstratakis c863e96455 [3.14] gh-139808: Add branch protections for aarch64 in asm_trampoline.S (#130864) (#150189)
gh-139808: Add branch protections for aarch64 in asm_trampoline.S (#130864)

Apply protection against ROP/JOP attacks for aarch64 on asm_trampoline.S.

The BTI flag must be applied in assembler sources for this class
of attacks to be mitigated on newer aarch64 processors.

See also:
https://sourceware.org/annobin/annobin.html/Test-branch-protection.html
and
https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/enabling-pac-and-bti-on-aarch64

The 3.14 backport makes Python/jit_unwind.c changes in
Python/perf_jit_trampoline.c.


(cherry picked from commit da8477b25c)

Co-authored-by: stratakis <cstratak@redhat.com>
2026-05-21 18:41:26 +02:00
Sam GrossandAlper d6b6fd70c4 [3.14] gh-145235: Make dict watcher API thread-safe for free-threaded builds (gh-145233) (#149691)
In free-threaded builds, concurrent calls to PyDict_AddWatcher, PyDict_ClearWatcher, PyDict_Watch, and PyDict_Unwatch can race on the shared callback array and the per-dict watcher tags. This change adds a mutex to serialize watcher registration and removal, atomic operations for tag updates, and atomic acquire/release synchronization for callback dispatch in _PyDict_SendEvent.

(cherry picked from commit 8a4895985f)

Co-authored-by: Alper <alperyoney@fb.com>
2026-05-12 13:21:31 -04:00
Miss Islington (bot)andDaniele Parmeggiani 8a7f0570e6 [3.14] gh-146270: Fix PyMember_SetOne(..., NULL) not being atomic (gh-148800) (#149460)
Fixes a sequential consistency bug whereby two threads that are deleting a struct member may observe both their deletions to be successful.

(cherry picked from commit 1bdfc0f253)

Co-authored-by: Daniele Parmeggiani <8658291+dpdani@users.noreply.github.com>
2026-05-06 14:16:36 +00:00
Miss Islington (bot)andUxío García Andrade 3f8c485660 [3.14] gh-137293: Ignore Exceptions when searching ELF File in Remote Debug (GH-137309) (#149391)
gh-137293: Ignore Exceptions when searching ELF File in Remote Debug (GH-137309)
(cherry picked from commit 2995d45659)

Co-authored-by: Uxío García Andrade <uxiog21@gmail.com>
2026-05-05 01:15:33 +00:00
Victor StinnerandMark Shannon 690b2bb615 [3.14] gh-137030: Fix YIELD_VALUE bytecode assertion (#149184) (#149383)
gh-137030: Fix YIELD_VALUE bytecode assertion (#149184)


(cherry picked from commit 952784af47)

Co-authored-by: Mark Shannon <mark@hotpy.org>
2026-05-04 23:41:19 +02:00
Miss Islington (bot)andMaurycy Pawłowski-Wieroński fc390bdcee [3.14] gh-147998: Fix possible memory leak in _pop_preserved (crossinterp.c) (GH-147999) (GH-149365)
(cherry picked from commit 72f29dc704)

Co-authored-by: Maurycy Pawłowski-Wieroński <maurycy@maurycy.com>
2026-05-04 14:11:04 +00:00
Miss Islington (bot)andWulian233 95979d1813 [3.14] gh-148418: Fix a possible reference leak in a corrupted TYPE_CODE marshal stream (GH-148419) (GH-149363)
(cherry picked from commit c3972f2795)

Co-authored-by: Wulian233 <1055917385@qq.com>
2026-05-04 14:07:43 +00:00
Miss Islington (bot)andPetr Viktorin bfcaeead9f [3.14] gh-149122: Fix refleak in codegen (GH-149179) (#149181)
gh-149122: Fix refleak in codegen (GH-149179)
(cherry picked from commit 4599335a83)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
2026-04-30 18:42:52 +05:30
Miss Islington (bot)andIrit Katriel 098880de36 [3.14] gh-149122: Fix segfault in compiler when certain builtin functions are passed a coroutine as arg (GH-149138) (#149151)
gh-149122: Fix segfault in compiler when certain builtin functions are passed a coroutine as arg (GH-149138)
(cherry picked from commit 16f292ef4e)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2026-04-29 14:01:45 +00:00
Sergey Miryanov 4d0ae4cba9 [3.14] GH-148726: Add heap_size to _gc_runtime_state (#149025) 2026-04-29 13:04:11 +03:00
Gregory P. Smith bb8d6a0863 [3.14] Improve hash() builtin docstring with caveats. (GH-125229) (#149054)
Improve  `hash()` builtin docstring with caveats.

Mention its return type and that the value can be expected to change between
processes (hash randomization).

Why? The `hash` builtin gets reached for and used by a lot of people whether it
is the right tool or not. IDEs surface docstrings and people use pydoc and
`help(hash)`.
(cherry picked from commit 665b7dfcfa)
2026-04-27 16:17:30 +00:00
9a7e205e46 [3.14] GH-148726: Forward-port generational GC (#148720)
Co-authored-by: Neil Schemenauer <nas@arctrix.com>
Co-authored-by: Sergey Miryanov <sergey.miryanov@gmail.com>
Co-authored-by: Zanie Blue <contact@zanie.dev>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: Neil Schemenauer <nas-github@arctrix.com>
2026-04-26 21:12:52 +03:00
Miss Islington (bot)andzSirius 78c5e54b4f [3.14] gh-146455: Fix O(N²) in add_const() after constant folding moved to CFG (GH-146456) (#149011)
gh-146455: Fix O(N²) in add_const() after constant folding moved to CFG (GH-146456)

The add_const() function in flowgraph.c uses a linear search over the
consts list to find the index of a constant. After gh-126835 moved
constant folding from the AST optimizer to the CFG optimizer, this
function is now called N times for N inner tuple elements during
fold_tuple_of_constants(), resulting in O(N²) total time.

Fix by maintaining an auxiliary _Py_hashtable_t that maps object
pointers to their indices in the consts list, providing O(1) lookup.

For a file with 100,000 constant 2-tuples:
- Before: 10.38s (add_const occupies 83.76% of CPU time)
- After:  1.48s
(cherry picked from commit 5d416324c5)

Co-authored-by: zSirius <107359899+zSirius@users.noreply.github.com>
2026-04-26 18:45:38 +03:00