[issue2778] set_swap_bodies is unsafe
Raymond Hettinger
report at bugs.python.org
Thu May 8 06:06:42 CEST 2008
Raymond Hettinger <rhettinger at users.sourceforge.net> added the comment:
Rejecting this patch which simply disables a feature that some users
consider to be important.
I will look at it further. Right now, I'm inclined to simply document
that the three temporary autoconversions deny meaningful
contemporaneous access to a set used as a key.
The set_swap_bodies() function itself is fine -- it behaves just like
an atomic version of the pure python sequence: t=set(a); a.clear();
a.update(b); b.clear(); b.update(t); del t.
The issue is simply that the swap/search/swap dance allows the
possibility that a determined user could graft onto the search step and
access but not modify the temporary swapped-in frozenset. It doesn't
crash; it simply produces an undefined result. I'm not losing sleep
over this scenario.
I'm am entertaining an alternative where contains/discard/remove would
duplicate instead of swap the set bodies; however, that approach may do
more harm than good.
__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2778>
__________________________________
More information about the Python-bugs-list
mailing list