Skip to content

gh-151722: Do not track the dict in the GC in _PyDict_FromKeys()#152067

Open
vstinner wants to merge 1 commit into
python:mainfrom
vstinner:dict_fromkeys
Open

gh-151722: Do not track the dict in the GC in _PyDict_FromKeys()#152067
vstinner wants to merge 1 commit into
python:mainfrom
vstinner:dict_fromkeys

Conversation

@vstinner

@vstinner vstinner commented Jun 24, 2026

Copy link
Copy Markdown
Member

dict_merge() no longer requires the dictionary to be tracked by the GC.

dict_merge() no longer requires the dictionary to be tracked by the
GC.

Co-authored-by: Donghee Na <donghee.na@python.org>
@vstinner

Copy link
Copy Markdown
Member Author

This fix is similar to PR gh-152021 but it doesn't call _PyObject_GC_UNTRACK(d). It only cares about the dictionary being tracked by the GC is it's a frozendict. If cls is a frozendict, call frozendict_new_untracked() to get directly a frozendict not tracked by the GC. Otherwise, if cls constructor creates a frozendict tracked by the GC, create a copy which is not tracked by the GC.

We don't have to track again the dictionary by the GC on error. For a dict, it's already tracked. For a frozendict, it's ok that it's not tracked by the GC on error.

@vstinner

Copy link
Copy Markdown
Member Author

cc @corona10 @methane

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review needs backport to 3.15 pre-release feature fixes, bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant