Author: Philip Jenvey <pjen...@underboss.org> Branch: Changeset: r72429:c686b0a3a21a Date: 2014-07-12 16:03 -0700 http://bitbucket.org/pypy/pypy/changeset/c686b0a3a21a/
Log: fix tostring() on empty arrays diff --git a/pypy/module/array/interp_array.py b/pypy/module/array/interp_array.py --- a/pypy/module/array/interp_array.py +++ b/pypy/module/array/interp_array.py @@ -228,8 +228,11 @@ Convert the array to an array of machine values and return the string representation. """ + size = self.len + if size == 0: + return space.wrap('') cbuf = self._charbuf_start() - s = rffi.charpsize2str(cbuf, self.len * self.itemsize) + s = rffi.charpsize2str(cbuf, size * self.itemsize) self._charbuf_stop() return self.space.wrap(s) diff --git a/pypy/module/array/test/test_array.py b/pypy/module/array/test/test_array.py --- a/pypy/module/array/test/test_array.py +++ b/pypy/module/array/test/test_array.py @@ -418,6 +418,10 @@ assert self.array('u', unicode('hello')).tounicode() == \ unicode('hello') + def test_empty_tostring(self): + a = self.array('l') + assert a.tostring() == b'' + def test_buffer(self): a = self.array('h', 'Hi') buf = buffer(a) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit