[pypy-svn] r76144 - in pypy/trunk/pypy/rpython: . test

arigo at codespeak.net arigo at codespeak.net
Mon Jul 12 15:37:22 CEST 2010


Author: arigo
Date: Mon Jul 12 15:37:20 2010
New Revision: 76144

Modified:
   pypy/trunk/pypy/rpython/rstr.py
   pypy/trunk/pypy/rpython/test/test_rstr.py
Log:
The previous fix broke unichar.encode("latin-1").  Test it and re-fix it.


Modified: pypy/trunk/pypy/rpython/rstr.py
==============================================================================
--- pypy/trunk/pypy/rpython/rstr.py	(original)
+++ pypy/trunk/pypy/rpython/rstr.py	Mon Jul 12 15:37:20 2010
@@ -288,7 +288,11 @@
         if not hop.args_s[1].is_constant():
             raise TyperError("encoding must be constant")
         encoding = hop.args_s[1].const
-        v_self = hop.inputarg(self.lowleveltype, 0)
+        if encoding == "ascii":
+            expect = self.lowleveltype   # can be a UniChar
+        else:
+            expect = self.repr           # must be a regular unicode string
+        v_self = hop.inputarg(expect, 0)
         hop.exception_is_here()
         if encoding == "ascii":
             return hop.gendirectcall(self.ll_str, v_self)

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:37:20 2010
@@ -875,6 +875,12 @@
             return c[i].encode("ascii")
         assert self.ll_to_string(self.interpret(f, [0])) == "a"
 
+    def test_encode_char_latin1(self):
+        def f(i):
+            c = u"abc"
+            return c[i].encode("latin-1")
+        assert self.ll_to_string(self.interpret(f, [0])) == "a"
+
 def FIXME_test_str_to_pystringobj():
     def f(n):
         if n >= 0:



More information about the Pypy-commit mailing list