[pypy-svn] r76142 - in pypy/trunk/pypy/rpython: . test
arigo at codespeak.net
arigo at codespeak.net
Mon Jul 12 15:32:26 CEST 2010
Author: arigo
Date: Mon Jul 12 15:32:24 2010
New Revision: 76142
Modified:
pypy/trunk/pypy/rpython/rstr.py
pypy/trunk/pypy/rpython/test/test_rstr.py
Log:
Fix for str(u) where u is a UniChar.
Modified: pypy/trunk/pypy/rpython/rstr.py
==============================================================================
--- pypy/trunk/pypy/rpython/rstr.py (original)
+++ pypy/trunk/pypy/rpython/rstr.py Mon Jul 12 15:32:24 2010
@@ -415,7 +415,17 @@
sourcevars.append((v_item, r_arg))
return r_str.ll.do_stringformat(hop, sourcevars)
-
+
+
+class __extend__(AbstractCharRepr):
+ def ll_str(self, ch):
+ return self.ll.ll_chr2str(ch)
+
+class __extend__(AbstractUniCharRepr):
+ def ll_str(self, ch):
+ # xxx suboptimal, maybe
+ return str(unicode(ch))
+
class __extend__(AbstractCharRepr,
AbstractUniCharRepr):
@@ -433,9 +443,6 @@
get_ll_fasthash_function = get_ll_hash_function
- def ll_str(self, ch):
- return self.ll.ll_chr2str(ch)
-
def rtype_len(_, hop):
return hop.inputconst(Signed, 1)
Modified: pypy/trunk/pypy/rpython/test/test_rstr.py
==============================================================================
--- pypy/trunk/pypy/rpython/test/test_rstr.py (original)
+++ pypy/trunk/pypy/rpython/test/test_rstr.py Mon Jul 12 15:32:24 2010
@@ -863,6 +863,12 @@
res = self.interpret(f, [1])
assert self.ll_to_string(res) == "hello"
+ def test_str_unichar(self):
+ def f(i):
+ c = u"abc"
+ return str(c[i])[0]
+ assert self.interpret(f, [1]) == "b"
+
def FIXME_test_str_to_pystringobj():
def f(n):
if n >= 0:
More information about the Pypy-commit
mailing list