Skip to content

gh-148450: abc.register needs to update type_version when tp_flags is changed.#148623

Open
cocolato wants to merge 2 commits intopython:mainfrom
cocolato:gh-148450
Open

gh-148450: abc.register needs to update type_version when tp_flags is changed.#148623
cocolato wants to merge 2 commits intopython:mainfrom
cocolato:gh-148450

Conversation

@cocolato
Copy link
Copy Markdown
Member

@cocolato cocolato commented Apr 15, 2026

@cocolato cocolato added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Apr 15, 2026
@nascheme
Copy link
Copy Markdown
Member

This looks correct to me. Setting flags means that caches based on the type version should be invalidated. You can't call type_modified_unlocked() with the world stopped, since it is re-entrant. So you need the tricky process of acquiring type lock, ensuring it stays locked on stop-the-world.

Minor improvement suggestion: I would adjust the comment to explain that ideally the setting of flags and clearing (invalidation) of version would be done in one step. However, because the version invalidation must be done with the world not stopped, we need to do these two steps.

Regarding the 3.13 backport: the code is different in that version, there is no stop-the-world done. With 3.13, there are data races on on tp_flags (since they are read without a lock and without atomics). For the backport, you would just not worry about that and call type_modified_unlocked() while holding the type lock.

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

Labels

awaiting review needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants