[pypy-svn] r48416 - in pypy/branch/pypy-rpython-unicode/rpython: . lltypesystem test

fijal at codespeak.net fijal at codespeak.net
Thu Nov 8 15:52:47 CET 2007


Author: fijal
Date: Thu Nov  8 15:52:44 2007
New Revision: 48416

Modified:
   pypy/branch/pypy-rpython-unicode/rpython/lltypesystem/rstr.py
   pypy/branch/pypy-rpython-unicode/rpython/rstr.py
   pypy/branch/pypy-rpython-unicode/rpython/test/test_runicode.py
Log:
ll_str for unicode


Modified: pypy/branch/pypy-rpython-unicode/rpython/lltypesystem/rstr.py
==============================================================================
--- pypy/branch/pypy-rpython-unicode/rpython/lltypesystem/rstr.py	(original)
+++ pypy/branch/pypy-rpython-unicode/rpython/lltypesystem/rstr.py	Thu Nov  8 15:52:44 2007
@@ -119,6 +119,18 @@
         self.ll = LLHelpers
         self.malloc = mallocunicode
 
+    def ll_str(self, s):
+        # XXX crazy that this is here, but I don't want to break
+        #     rmodel logic
+        lgt = len(s.chars)
+        result = mallocstr(lgt)
+        for i in range(lgt):
+            c = s.chars[i]
+            if ord(c) > 127:
+                raise ValueError("character not in ascii range")
+            result.chars[i] = cast_primitive(Char, c)
+        return result
+
 class CharRepr(AbstractCharRepr, StringRepr):
     lowleveltype = Char
 

Modified: pypy/branch/pypy-rpython-unicode/rpython/rstr.py
==============================================================================
--- pypy/branch/pypy-rpython-unicode/rpython/rstr.py	(original)
+++ pypy/branch/pypy-rpython-unicode/rpython/rstr.py	Thu Nov  8 15:52:44 2007
@@ -264,7 +264,6 @@
     def ll_str(self, s):
         return s
 
-
 class __extend__(pairtype(AbstractStringRepr, Repr)):
     def rtype_mod((r_str, _), hop):
         # for the case where the 2nd argument is a tuple, see the

Modified: pypy/branch/pypy-rpython-unicode/rpython/test/test_runicode.py
==============================================================================
--- pypy/branch/pypy-rpython-unicode/rpython/test/test_runicode.py	(original)
+++ pypy/branch/pypy-rpython-unicode/rpython/test/test_runicode.py	Thu Nov  8 15:52:44 2007
@@ -46,6 +46,13 @@
 
         assert self.ll_to_string(self.interpret(f, [])) == 'xxx'
 
+    def test_str_unicode_nonconst(self):
+        def f(x):
+            y = u'xxx' + unichr(x)
+            return str(y)
+
+        assert self.ll_to_string(self.interpret(f, [38])) == f(38)
+
     def test_unichar_const(self):
         def fn(c):
             return c



More information about the Pypy-commit mailing list