Author: Lukas Diekmann <lukas.diekm...@uni-duesseldorf.de> Branch: Changeset: r55714:776e724afb92 Date: 2012-06-19 11:44 +0200 http://bitbucket.org/pypy/pypy/changeset/776e724afb92/
Log: issue 1183: difference should never reuse the storage of a set as the storage of the resulting set, even if they are equal diff --git a/pypy/objspace/std/setobject.py b/pypy/objspace/std/setobject.py --- a/pypy/objspace/std/setobject.py +++ b/pypy/objspace/std/setobject.py @@ -491,7 +491,8 @@ storage = self._difference_unwrapped(w_set, w_other) elif not w_set.strategy.may_contain_equal_elements(w_other.strategy): strategy = w_set.strategy - storage = w_set.sstorage + d = self.unerase(w_set.sstorage) + storage = self.erase(d.copy()) else: strategy = self.space.fromcache(ObjectSetStrategy) storage = self._difference_wrapped(w_set, w_other) diff --git a/pypy/objspace/std/test/test_setobject.py b/pypy/objspace/std/test/test_setobject.py --- a/pypy/objspace/std/test/test_setobject.py +++ b/pypy/objspace/std/test/test_setobject.py @@ -642,6 +642,14 @@ assert set([1,2,3,'5']).difference(set([2,3,4])) == set([1,'5']) assert set().difference(set([1,2,3])) == set() + def test_difference_bug(self): + a = set([1,2,3]) + b = set([]) + c = a - b + c.remove(2) + assert c == set([1, 3]) + assert a == set([1,2, 3]) + def test_intersection_update(self): s = set([1,2,3,4,7]) s.intersection_update([0,1,2,3,4,5,6]) _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit