Skip to content

[3.15] gh-151722: Defer GC tracking in frozendict.copy() (GH-152230)#152271

Merged
vstinner merged 1 commit into
python:3.15from
miss-islington:backport-05679f3-3.15
Jun 26, 2026
Merged

[3.15] gh-151722: Defer GC tracking in frozendict.copy() (GH-152230)#152271
vstinner merged 1 commit into
python:3.15from
miss-islington:backport-05679f3-3.15

Conversation

@miss-islington

@miss-islington miss-islington commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

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.
    (cherry picked from commit 05679f3)

Co-authored-by: Victor Stinner vstinner@python.org

)

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.
(cherry picked from commit 05679f3)

Co-authored-by: Victor Stinner <vstinner@python.org>
@vstinner vstinner enabled auto-merge (squash) June 26, 2026 11:56
@vstinner vstinner merged commit c48673b into python:3.15 Jun 26, 2026
54 checks passed
@miss-islington miss-islington deleted the backport-05679f3-3.15 branch June 26, 2026 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants