[pypy-commit] pypy stdlib-2.7.11: Fixed a.fromstring(a)
alex_gaynor
pypy.commits at gmail.com
Sat Mar 19 23:38:07 EDT 2016
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: stdlib-2.7.11
Changeset: r83176:950a3333c302
Date: 2016-03-19 23:37 -0400
http://bitbucket.org/pypy/pypy/changeset/950a3333c302/
Log: Fixed a.fromstring(a)
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
@@ -238,6 +238,11 @@
Appends items from the string, interpreting it as an array of machine
values,as if it had been read from a file using the fromfile() method).
"""
+ if self is w_s:
+ raise OperationError(
+ self.space.w_ValueError,
+ self.space.wrap("array.fromstring(x): x cannot be self")
+ )
s = space.getarg_w('s#', w_s)
if len(s) % self.itemsize != 0:
msg = 'string length not a multiple of item size'
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
@@ -151,6 +151,8 @@
raises(OverflowError, a.append, 2 ** (8 * b))
def test_fromstring(self):
+ import sys
+
a = self.array('c')
a.fromstring('Hi!')
assert a[0] == 'H' and a[1] == 'i' and a[2] == '!' and len(a) == 3
@@ -174,6 +176,8 @@
raises(ValueError, a.fromstring, '\x00' * (2 * a.itemsize + 1))
b = self.array(t, '\x00' * a.itemsize * 2)
assert len(b) == 2 and b[0] == 0 and b[1] == 0
+ if sys.version_info >= (2, 7, 11):
+ raises(ValueError, a.fromstring, a)
def test_fromfile(self):
More information about the pypy-commit
mailing list