Commits

Philip Jenvey  committed c686b0a

fix tostring() on empty arrays

  • Participants
  • Parent commits 6b33956

Comments (0)

Files changed (2)

File pypy/module/array/interp_array.py

         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)
 

File pypy/module/array/test/test_array.py

         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)