Skip to content

gh-158660: Allow calling frozenset methods without locking - #163017

Merged
vstinner merged 9 commits into
python:mainfrom
vstinner:can_modify_set
Dec 2, 2026
Merged

vstinner merged 9 commits into
python:mainfrom
vstinner:can_modify_set

Conversation

@vstinner

@vstinner vstinner commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Add ASSERT_CAN_MODIFY_SET(), ASSERT_SET_LOCKED() and ASSERT_OTHER_LOCKED() helper functions to setobject.c to check if it's safe to use an object. For set objects, check that the critical section is locked.

ASSERT_CAN_MODIFY_SET() and ASSERT_SET_LOCKED() do not require locking if the argument is a frozenset. ASSERT_OTHER_LOCKED() does not require locking if the argument is a frozenset or a frozendict.

Move lock check from set_add_entry() to set_add_entry_takeref().

Add ASSERT_CAN_MODIFY_SET(), ASSERT_SET_LOCKED() and
ASSERT_OTHER_LOCKED() helper functions to setobject.c to check if
it's safe to use an object. For set objects, check that the critical
section is locked.

ASSERT_CAN_MODIFY_SET() and ASSERT_SET_LOCKED() do not require
locking if the argument is a frozenset. ASSERT_OTHER_LOCKED() does
not require locking if the argument is a frozenset or a frozendict.

Move lock check from set_add_entry() to set_add_entry_takeref().
@vstinner
vstinner requested a review from rhettinger as a code owner December 2, 2026 15:29
@vstinner vstinner changed the title gh-158660: Allow calling set methods on frozenset without locking gh-158660: Allow calling frozenset methods without locking Dec 2, 2026
Call ASSERT_CAN_MODIFY_SET() in set_table_resize() and
set_discard_entry().
@vstinner

vstinner commented Dec 2, 2026

Copy link
Copy Markdown
Member Author

Ah, there is yet another GitHub outage: Incident with Webhooks and Actions. I will re-run the CI later, once it will be solved.

@rhettinger
rhettinger removed their request for review December 2, 2026 20:18
@vstinner
vstinner enabled auto-merge (squash) December 2, 2026 22:24
@vstinner
vstinner merged commit 4a7130d into python:main Dec 2, 2026
54 checks passed
@vstinner
vstinner deleted the can_modify_set branch December 2, 2026 23:02
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.

1 participant