[pypy-commit] pypy default: rpython fix: str_decode_utf8 has already been annotated when we are rtyping .decode('utf-8'), so we need to make sure that the annotations are compatible
antocuni
noreply at buildbot.pypy.org
Fri Aug 31 11:21:51 CEST 2012
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch:
Changeset: r57050:f8b1cbbd9971
Date: 2012-08-31 11:20 +0200
http://bitbucket.org/pypy/pypy/changeset/f8b1cbbd9971/
Log: rpython fix: str_decode_utf8 has already been annotated when we are
rtyping .decode('utf-8'), so we need to make sure that the
annotations are compatible
diff --git a/pypy/rpython/lltypesystem/rstr.py b/pypy/rpython/lltypesystem/rstr.py
--- a/pypy/rpython/lltypesystem/rstr.py
+++ b/pypy/rpython/lltypesystem/rstr.py
@@ -147,6 +147,7 @@
from pypy.rpython.annlowlevel import hlstr, llunicode
from pypy.rlib.runicode import str_decode_utf_8
value = hlstr(llvalue)
+ assert value is not None
univalue, _ = str_decode_utf_8(value, len(value), 'strict')
return llunicode(univalue)
diff --git a/pypy/rpython/ootypesystem/rstr.py b/pypy/rpython/ootypesystem/rstr.py
--- a/pypy/rpython/ootypesystem/rstr.py
+++ b/pypy/rpython/ootypesystem/rstr.py
@@ -64,6 +64,7 @@
from pypy.rpython.annlowlevel import hlstr, oounicode
from pypy.rlib.runicode import str_decode_utf_8
value = hlstr(llvalue)
+ assert value is not None
univalue, _ = str_decode_utf_8(value, len(value), 'strict')
return oounicode(univalue)
diff --git a/pypy/rpython/test/test_runicode.py b/pypy/rpython/test/test_runicode.py
--- a/pypy/rpython/test/test_runicode.py
+++ b/pypy/rpython/test/test_runicode.py
@@ -153,6 +153,17 @@
assert self.ll_to_string(self.interpret(f, [0])) == f(0)
+ def test_utf_8_decoding_annotation(self):
+ from pypy.rlib.runicode import str_decode_utf_8
+ strings = [u'àèì'.encode('utf-8'), u'ìòéà'.encode('utf-8')]
+ def f(n):
+ x = strings[n]
+ # the annotation of y is SomeUnicodeString(can_be_None=False)
+ y, _ = str_decode_utf_8(x, len(x), 'strict')
+ return x.decode('utf-8') + y
+
+ assert self.ll_to_string(self.interpret(f, [1])) == f(1)
+
def test_unicode_decode_error(self):
def f(x):
y = 'xxx'
More information about the pypy-commit
mailing list