Author: Manuel Jacob
Branch: py3k-memoryview
Changeset: r71634:61cb7d5b5ce5
Date: 2014-05-21 21:44 +0200
http://bitbucket.org/pypy/pypy/changeset/61cb7d5b5ce5/
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
@@ -656,6 +656,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
@@ -1044,6 +1044,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()
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit