Title: gh-151722: Defer GC tracking of frozendict.fromkeys() result until fully built by tonghuaroot · Pull Request #151967 · python/cpython · GitHub
Open Graph Title: gh-151722: Defer GC tracking of frozendict.fromkeys() result until fully built by tonghuaroot · Pull Request #151967 · python/cpython
X Title: gh-151722: Defer GC tracking of frozendict.fromkeys() result until fully built by tonghuaroot · Pull Request #151967 · python/cpython
Description: frozendict.fromkeys() fills its result by iterating the keys and inserting them one at a time with PyIter_Next(), which runs user code (the iterable's __next__). In the free-threaded build the result is GC-tracked during this fill loop, so another thread calling gc.get_objects() can reach and take a reference to the still half-built frozendict. That breaks the unique-reference invariant the lock-free insert relies on, tripping assert(can_modify_dict(mp)) on a debug build (or an unsynchronized write concurrent with a reader on a release build). This mirrors gh-151740, which applied the same untrack-during-build / track-when-complete pattern to frozendict_new() and frozendict_vectorcall(). fromkeys() is the remaining construction path that change did not cover. This is the separate follow-up for the fromkeys() path; in gh-151740 @corona10 suggested submitting it as its own PR once that one was merged. Issue: #151722 Issue: gh-151722
Open Graph Description: frozendict.fromkeys() fills its result by iterating the keys and inserting them one at a time with PyIter_Next(), which runs user code (the iterable's __next__). In the free-threaded build the...
X Description: frozendict.fromkeys() fills its result by iterating the keys and inserting them one at a time with PyIter_Next(), which runs user code (the iterable's __next__). In the free-threaded build...
Opengraph URL: https://github.com/python/cpython/pull/151967
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:dddf633c-06a8-3e1a-1184-21eb09839096 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | E6CE:165D8F:1A56D40:2465CE8:6A501025 |
| html-safe-nonce | e99803493c18bb2decdac0cf55d8eed2c963c17539e050a07c51727560206304 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNkNFOjE2NUQ4RjoxQTU2RDQwOjI0NjVDRTg6NkE1MDEwMjUiLCJ2aXNpdG9yX2lkIjoiNDI1ODMyMTU4MDI1MjIwNTA5MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | c025ae3317eaba78bd85b707944ee26206c7c534874a29b2324506ac4e219a5e |
| hovercard-subject-tag | pull_request:3917817592 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/cpython/pull/151967/files |
| twitter:image | https://avatars.githubusercontent.com/u/23011166?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/23011166?s=400&v=4 |
| og:image:alt | frozendict.fromkeys() fills its result by iterating the keys and inserting them one at a time with PyIter_Next(), which runs user code (the iterable's __next__). In the free-threaded build the... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | fe4f38b24922a1ce81c1708c3793b47c185599b9144ab94f6ca846b00698058d |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 42b6390c91978a16f9196c38c7a00e9bf21f37e7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width