[issue2778] set_swap_bodies is unsafe

Adam Olsen report at bugs.python.org
Thu May 15 00:11:53 CEST 2008


Adam Olsen <rhamph at gmail.com> added the comment:

There is no temporary hashability.  The hash value is calculated, but
never stored in the set's hash field, so it will never become out of
sync.  Modification while __hash__ or __eq__ is running is possible, but
for __eq__ that applies to any mutable type.

set_contains_key only has two callers, one for each value of the
treat_set_key_as_frozen argument, so I could inline it if you'd prefer that?

set_swap_bodies has only one remaining caller, which uses a normal set,
not a frozenset.  Using set_swap_bodies on a frozenset would be visible
except in a few special circumstances (ie it only contains builtin
types), so a sanity check against that seems appropriate.  The old code
reset ->hash to -1 in case one of the arguments was a frozenset -
impossible now, so I sanity check that it's always -1.

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2778>
__________________________________


More information about the Python-bugs-list mailing list