Author: Tyler Wade <way...@gmail.com> Branch: Changeset: r72431:2eef95188f80 Date: 2014-07-13 05:50 -0500 http://bitbucket.org/pypy/pypy/changeset/2eef95188f80/
Log: Fix underlying list of bytearrays being reused inappropriately diff --git a/pypy/objspace/std/bytearrayobject.py b/pypy/objspace/std/bytearrayobject.py --- a/pypy/objspace/std/bytearrayobject.py +++ b/pypy/objspace/std/bytearrayobject.py @@ -41,6 +41,8 @@ return ''.join(self.data) def _new(self, value): + if value is self.data: + value = value[:] return W_BytearrayObject(value) def _new_from_buffer(self, buffer): diff --git a/pypy/objspace/std/stringmethods.py b/pypy/objspace/std/stringmethods.py --- a/pypy/objspace/std/stringmethods.py +++ b/pypy/objspace/std/stringmethods.py @@ -455,7 +455,7 @@ d = width - len(value) if d > 0: fillchar = self._multi_chr(fillchar[0]) - value += d * fillchar + value = value + fillchar * d return self._new(value) diff --git a/pypy/objspace/std/test/test_bytearrayobject.py b/pypy/objspace/std/test/test_bytearrayobject.py --- a/pypy/objspace/std/test/test_bytearrayobject.py +++ b/pypy/objspace/std/test/test_bytearrayobject.py @@ -223,6 +223,20 @@ check(bytearray('abc').rstrip(memoryview('c')), 'ab') check(bytearray('aba').strip('a'), 'b') + def test_xjust_no_mutate(self): + # a previous regression + b = bytearray(b'') + assert b.ljust(1) == bytearray(b' ') + assert not len(b) + + b2 = b.ljust(0) + b2 += b' ' + assert not len(b) + + b2 = b.rjust(0) + b2 += b' ' + assert not len(b) + def test_split(self): # methods that should return a sequence of bytearrays def check(result, expected): _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit