Skip to content

Conversation

@kemingy
Copy link
Contributor

@kemingy kemingy commented Nov 27, 2025

gh-141805: goes directly to the found_unused_or_dummy when finding a dummy slot in set.add

This avoids triggering the __eq__ in the next iteration by the PyObject_RichCompareBool, which might introduce another set.add in the user code. Like:

tasks = set()

class Corrupt:
    def __eq__(self, value):
        tasks.add(self)
        return False

As described in #141805 (comment)

…er add

Signed-off-by: Keming <kemingy94@gmail.com>
@kemingy kemingy requested a review from rhettinger as a code owner November 27, 2025 09:52
@kemingy kemingy changed the title fix: avoid increase the set->used twice when the __eq__ trigger another add gh-141805: avoid increase the set->used twice when the __eq__ trigger another add Nov 27, 2025
Signed-off-by: Keming <kemingy94@gmail.com>
Copy link
Member

@efimov-mikhail efimov-mikhail left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR looks correct for me, just little nitpicks.

@efimov-mikhail efimov-mikhail added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Dec 20, 2025
Copy link
Member

@efimov-mikhail efimov-mikhail left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants