Skip to content

[DIFF] Immutability for NoGIL for 3.15a - #112

Open
xFrednet wants to merge 3781 commits into
immutable-basefrom
immutable-nogil
Open

xFrednet wants to merge 3781 commits into
immutable-basefrom
immutable-nogil

Conversation

@xFrednet

@xFrednet xFrednet commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

This is the entire diff to implement shallow and deep immutability for Python. This also includes the write-barriers from #63. The relevant files for this PR are probably:

Include/cpython/immutability.h
Include/internal/pycore_gc.h
Include/internal/pycore_immutability.h
Include/internal/pycore_object.h
Include/internal/pycore_stackref.h
Include/internal/pycore_weakref.h
Include/object.h
Include/refcount.h
Lib/immutable.py
Modules/_immutablemodule.c
Modules/_weakref.c
Objects/object.c
Objects/weakrefobject.c
Python/ceval.c
Python/crossinterp.c
Python/gc.c
Python/immutability.c

📚 Documentation preview 📚: https://cpython-previews--112.org.readthedocs.build/

pablogsal and others added 30 commits August 26, 2026 12:37
…154099) (python#156385)

pythongh-154085: Avoid duplicating diff line values (pythonGH-154099)
(cherry picked from commit 53381bc)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
…ocess with pdb -p (pythonGH-154469) (pythonGH-156397)

pythongh-154467: Fix empty (Pdb) prompt when attaching to a process with pdb -p (pythonGH-154469)

_PdbServer inherits _cmdloop, which wraps cmdloop() in
_maybe_use_pyrepl_as_stdin(). That context manager blanks self.prompt to ''
so that a local pyrepl draws the prompt itself. The remote server, however,
never reads from a local pyrepl -- it transmits self.prompt to the client
over the socket -- so the blanking made it send an empty prompt whenever the
target process had a pyrepl-capable terminal (pyrepl_input is set).

Override _maybe_use_pyrepl_as_stdin() in _PdbServer to a no-op, keeping the
real prompt. Add an integration test that attaches to a target running under
a pty, so PyREPL is genuinely enabled inside it, and asserts the transmitted
prompt is "(Pdb) ".
(cherry picked from commit 1ec5607)

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…156373) (python#156429)

(cherry picked from commit 98bd716)

Co-authored-by: Stan Ulbrych <stan@python.org>
) (python#156315)

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
…tringToNewUTF8 (pythonGH-156335) (python#156383)

Co-authored-by: Hood Chatham <roberthoodchatham@gmail.com>
…rt lines (pythonGH-156406) (python#156431)

Co-authored-by: Arcadiy Ivanov <arcadiy@ivanov.biz>
Co-authored-by: Barry Warsaw <barry@python.org>
…arify references to it (pythonGH-156053) (python#156123)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
…rgument (pythonGH-156247) (python#156254)

Co-authored-by: Timofei Ivankov <128279579+deadlovelll@users.noreply.github.com>
… syntax in `Interpolation` (pythonGH-155661) (python#155711)

Co-authored-by: dr-carlos <77367421+dr-carlos@users.noreply.github.com>
…`functools.partial` (pythonGH-155663) (python#155709)

Co-authored-by: dr-carlos <77367421+dr-carlos@users.noreply.github.com>
…ages (pythonGH-31546) (python#155643)

Co-authored-by: Addison Snelling <addison@asnell.io>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
…) and realpath() (pythonGH-155388) (python#155673)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
…scapechar (pythonGH-155067) (python#155685)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
…onGH-154173) (python#155690)

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
… (python#155622)

Co-authored-by: Amuthan Mannar <amuthanmannar4@gmail.com>
Co-authored-by: Alex Shkop <a.v.shkop@gmail.com>
…pletion (pythonGH-155730) (python#155769)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
…thonGH-154182) (python#155792)

Co-authored-by: David <slavicek.david29@gmail.com>
Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
… (python#155846)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
… available (pythonGH-156417) (python#156470)

Co-authored-by: Stan Ulbrych <stan@python.org>
…nGH-156528) (python#156530)

pythongh-156369: Update Windows builds to OpenSSL 3.5.8 (pythonGH-156528)
(cherry picked from commit b7ce9c3)

Co-authored-by: Zachary Ware <zach@python.org>
…lts in several signatures (pythonGH-155954) (python#156165)

pythongh-155952: Fix `<unrepresentable>` Argument Clinic defaults in several signatures (pythonGH-155954)
(cherry picked from commit 033dc43)

Co-authored-by: Stan Ulbrych <stan@python.org>
maurycy and others added 23 commits October 5, 2026 10:21
…reads (pythonGH-155828) (python#158829)

* update_seq

* no need for XCHGL, MOVL is enough?

* pythongh-155811: Retry an inconsistent GC snapshot once

---------
(cherry picked from commit 5fecd44)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
…y file when hitting `OverflowError` (pythonGH-152892) (python#158830)

pythongh-151292: `_remote_debugging`: Do not corrupt the binary file when hitting `OverflowError` (pythonGH-152892)

* the kolektor

* test

* better test

* news

* =Q, move const to the base, not self.running

* pythongh-151292: Track binary writer finalization state

---------
(cherry picked from commit f839c06)

Co-authored-by: Maurycy Pawłowski-Wieroński <maurycy@maurycy.com>
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
…x() (pythonGH-158584) (python#158691)

pythongh-158583: Fix uninitialized memory read in bytes.fromhex() (pythonGH-158584)
(cherry picked from commit 9d22a53)

Co-authored-by: Victor Stinner <vstinner@python.org>
…the sample (pythonGH-154195) (python#158831)

* pythongh-154194: Degrade frames in Tachyon instead of failing the sample (python#154195)

* degrade gracefully

* news

* better NEWS wording

* do not raise on MAX_REMOTE_STR_READ

* bye MAX_REMOTE_STR_READ

* fix -m asyncio ps|pstree

* test truncation and linetable sentinel

* simpler

* simpler

* redundant now

* respect python#157790 in the news

---------

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
(cherry picked from commit 7d25916)

* Preserve the stable ABI when creating fallback frame names

---------

Co-authored-by: Maurycy Pawłowski-Wieroński <maurycy@maurycy.com>
Run a job that the test suite with MSan to the CI (python#158625)

* Run the test suite with MSan in CI

* Additional fixes

* Add `_Py_MSAN_UNPOISON_STRING`

* Apply Victor's suggestions



* Apply Victor's suggestions



---------


(cherry picked from commit b93fb19)

Co-authored-by: Stan Ulbrych <stan@python.org>
Co-authored-by: Victor Stinner <victor.stinner@gmail.com>
…s UTF-8 (pythonGH-156811) (python#156814)

pythongh-156810: Write the profiler's collapsed-stack export as UTF-8 (pythonGH-156811)
(cherry picked from commit c3706f4)

Co-authored-by: tonghuaroot (童话) <tonghuaroot@gmail.com>
…ing binary format docs and a missing flag (pythonGH-157871) (python#158855)

pythongh-154060: Fix the `Profile Stats` offsets in the profiling binary format docs and a missing flag (pythonGH-157871)

* correct profile stats size and paddings

* missing flag

* pythongh-154060: Clarify the main-thread status flag

---------
(cherry picked from commit 8df2580)

Co-authored-by: Maurycy Pawłowski-Wieroński <maurycy@maurycy.com>
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
…ocking sampling (pythonGH-158802) (python#158845)

pythongh-158552: Wait for Windows threads to suspend before blocking sampling (pythonGH-158802)

* pythongh-158552: Wait for Windows threads to suspend before blocking sampling

* Use a named Windows thread enumeration status constant
(cherry picked from commit 1643525)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
…g binary reader (pythonGH-152722) (python#158850)

Backport of pythonGH-152722.

Co-authored-by: tonghuaroot <tonghuaroot@gmail.com>
…y recursive programs (pythonGH-156546) (python#158851)

Backport of pythonGH-156546.

Co-authored-by: tonghuaroot (童话) <tonghuaroot@gmail.com>
…th (pythonGH-158548) (python#158844)

pythongh-158540: Add the profiled script's directory to sys.path (pythonGH-158548)

* pythongh-158540: Add the profiled script's directory to sys.path

When a script is profiled with ``python -m profiling.sampling run
script.py`` from another directory, the script cannot import modules
placed next to it, because ``_sync_coordinator._execute_script()``
executes it with the working directory (added by
``_setup_environment()`` for the module case) as ``sys.path[0]``
instead of the script's own directory.

Make the script's directory importable in ``_execute_script()``,
matching the behavior of ``python script.py``.

Add a regression test that runs the coordinator on a script importing
a sibling module.

* Update _sync_coordinator.py Comment simplified



* pythongh-158540: Resolve symlinks when adding the script directory to sys.path

``python script.py`` resolves symlinks when computing ``sys.path[0]``, so
a script reached through a symlink (``link.py -> sub/where.py``) imports
modules from the real script's directory.  Apply ``os.path.realpath()``
before taking the directory name, and make sure the result is placed at
the front of ``sys.path`` even if it was already listed.

Add a regression test for a symlinked script.

---------
(cherry picked from commit 3f02aab)

Co-authored-by: he_tao <53343436+hetaozdh@users.noreply.github.com>
Co-authored-by: Eduardo Villalpando Mello <eduardo.villalpando.mello@gmail.com>
…exporter (pythonGH-153839) (python#158853)

Backport of pythonGH-153839.

Co-authored-by: tonghuaroot <tonghuaroot@gmail.com>
…tors/coroutines (pythonGH-158581) (python#158852)

* [3.15] pythongh-158539: Fix exception mode missing handlers in generators/coroutines (pythonGH-158581)

Backport of pythonGH-158581.

Co-authored-by: LucasZhou <donghao.zhou@outlook.com>

* [3.15] pythongh-158539: Use portable static assertion messages

* [3.15] pythongh-158539: Keep layout assertions with debug-offset validation

* [3.15] pythongh-158539: Use the platform guard for in-process inspection tests

---------

Co-authored-by: LucasZhou <donghao.zhou@outlook.com>
…e recurses (pythonGH-158526) (python#158870)

Co-authored-by: Timofei Ivankov <128279579+deadlovelll@users.noreply.github.com>
…s with aggressive "chatty" filtering (pythonGH-158531) (python#158537)

Co-authored-by: Malcolm Smith <smith@chaquo.com>
…#158959)

Co-authored-by: Nathan Goldbaum <nathan.goldbaum@gmail.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
…nGH-158940) (python#158949)

Co-authored-by: Maurycy Pawłowski-Wieroński <maurycy@maurycy.com>
…thon#159052)

Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
…n 3.15 (pythonGH-158256) (python#159053)

Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
…hon#159060)

Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: Matthew A Johnson <matjoh@microsoft.com>
Co-authored-by: Matthew Parkinson <mattpark@microsoft.com>
Co-authored-by: David Klement <kulisak12lp@gmail.com>
Co-authored-by: Tobias Wrigstad <tobias.wrigstad@it.uu.se>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.