Author: Maciej Fijalkowski <fij...@gmail.com>
Branch: use-file-star-for-file
Changeset: r72930:311385061a9b
Date: 2014-08-20 14:38 +0200
http://bitbucket.org/pypy/pypy/changeset/311385061a9b/

Log:    fix the case of llstr(char)

diff --git a/rpython/rtyper/annlowlevel.py b/rpython/rtyper/annlowlevel.py
--- a/rpython/rtyper/annlowlevel.py
+++ b/rpython/rtyper/annlowlevel.py
@@ -422,11 +422,13 @@
 
         def specialize_call(self, hop):
             hop.exception_cannot_occur()
-            assert hop.args_r[0].lowleveltype == hop.r_result.lowleveltype
             v_ll_str, = hop.inputargs(*hop.args_r)
-            return hop.genop('same_as', [v_ll_str],
-                             resulttype = hop.r_result.lowleveltype)
-
+            if hop.args_r[0].lowleveltype == hop.r_result.lowleveltype:
+                return hop.genop('same_as', [v_ll_str],
+                                 resulttype = hop.r_result.lowleveltype)
+            else:
+                return hop.gendirectcall(hop.args_r[0].ll.ll_chr2str, v_ll_str)
+        
     return hlstr, llstr
 
 hlstr, llstr = make_string_entries(str)
diff --git a/rpython/rtyper/test/test_annlowlevel.py 
b/rpython/rtyper/test/test_annlowlevel.py
--- a/rpython/rtyper/test/test_annlowlevel.py
+++ b/rpython/rtyper/test/test_annlowlevel.py
@@ -34,6 +34,14 @@
         res = self.interpret(f, [self.string_to_ll("abc")])
         assert res == 3
 
+    def test_llstr_const_char(self):
+        def f(arg):
+            s = llstr(hlstr(arg)[0])
+            return len(s.chars)
+
+        res = self.interpret(f, [self.string_to_ll("abc")])
+        assert res == 1
+
     def test_hlunicode(self):
         s = mallocunicode(3)
         s.chars[0] = u"a"
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to