[pypy-commit] pypy default: Fix 'str(buffer(array.array('i')))' if running untranslated.
Manuel Jacob
noreply at buildbot.pypy.org
Wed May 21 22:03:37 CEST 2014
Author: Manuel Jacob
Branch:
Changeset: r71633:212ca275373d
Date: 2014-05-21 21:44 +0200
http://bitbucket.org/pypy/pypy/changeset/212ca275373d/
Log: Fix 'str(buffer(array.array('i')))' if running untranslated.
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
@@ -2,7 +2,7 @@
from rpython.rlib import jit
from rpython.rlib.buffer import Buffer
-from rpython.rlib.objectmodel import keepalive_until_here
+from rpython.rlib.objectmodel import keepalive_until_here, we_are_translated
from rpython.rlib.rarithmetic import ovfcheck, widen
from rpython.rlib.unroll import unrolling_iterable
from rpython.rtyper.annlowlevel import llstr
@@ -616,6 +616,14 @@
if step == 1:
data = self.array._charbuf_start()
try:
+ if not we_are_translated():
+ # rffi.ptradd(NULL, ...) doesn't work untranslated.
+ # It returns nonsense translated, but its return value is
+ # unused if size == 0, which is the case if data == NULL
+ if self.array._buffer_as_unsigned() == 0:
+ assert size == 0
+ return ''
+
return rffi.charpsize2str(rffi.ptradd(data, start), size)
finally:
self.array._charbuf_stop()
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
@@ -1029,6 +1029,9 @@
raises(TypeError, "a[MyInt(0)]")
raises(TypeError, "a[MyInt(0):MyInt(5)]")
+ def test_fresh_array_buffer_str(self):
+ assert str(buffer(self.array('i'))) == ''
+
class AppTestArrayBuiltinShortcut(AppTestArray):
spaceconfig = AppTestArray.spaceconfig.copy()
More information about the pypy-commit
mailing list