[pypy-commit] pypy default: rpython fix: unicode_encode_utf8 has already been annotated when we are rtyping .encode('utf-8'), so we need to make sure that the annotations are compatible
antocuni
noreply at buildbot.pypy.org
Fri Aug 31 11:21:49 CEST 2012
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch:
Changeset: r57049:eae84b7cc330
Date: 2012-08-31 11:16 +0200
http://bitbucket.org/pypy/pypy/changeset/eae84b7cc330/
Log: rpython fix: unicode_encode_utf8 has already been annotated when we
are rtyping .encode('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
@@ -199,6 +199,7 @@
from pypy.rpython.annlowlevel import hlunicode, llstr
from pypy.rlib.runicode import unicode_encode_utf_8
s = hlunicode(ll_s)
+ assert s is not None
bytes = unicode_encode_utf_8(s, len(s), 'strict')
return llstr(bytes)
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
@@ -109,6 +109,7 @@
from pypy.rpython.annlowlevel import hlunicode, oostr
from pypy.rlib.runicode import unicode_encode_utf_8
s = hlunicode(ll_s)
+ assert s is not None
bytes = unicode_encode_utf_8(s, len(s), 'strict')
return oostr(bytes)
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
@@ -106,6 +106,20 @@
assert self.ll_to_string(self.interpret(f, [38])) == f(38)
+ def test_utf_8_encoding_annotation(self):
+ from pypy.rlib.runicode import unicode_encode_utf_8
+ def f(n):
+ x = u'àèì' + unichr(n)
+ if x:
+ y = u'ìòé'
+ else:
+ y = u'òìàà'
+ # the annotation of y is SomeUnicodeString(can_be_None=False)
+ y = unicode_encode_utf_8(y, len(y), 'strict')
+ return x.encode('utf-8') + y
+
+ assert self.ll_to_string(self.interpret(f, [38])) == f(38)
+
def test_unicode_encode_error(self):
def f(x, which):
if which:
More information about the pypy-commit
mailing list