Commits

Antonio Cuni committed 8fb327e

test&fix for when the unicode %s argument is None: we cannot call convert_const, it's not rpython at all

Comments (0)

Files changed (4)

pypy/rpython/lltypesystem/rstr.py

         if s:
             return s
         else:
-            return self.convert_const(u'None')
+            return self.ll.ll_constant(u'None')
 
     @jit.elidable
     def ll_encode_latin1(self, s):
         return LLHelpers.ll_join_strs(len(builder), builder)
 
     def ll_constant(s):
-        return string_repr.convert_const(s)
+        if isinstance(s, str):
+            return string_repr.convert_const(s)
+        elif isinstance(s, unicode):
+            return unicode_repr.convert_const(s)
+        else:
+            assert False
     ll_constant._annspecialcase_ = 'specialize:memo'
 
     def do_stringformat(cls, hop, sourcevarsrepr):

pypy/rpython/ootypesystem/ooregistry.py

     _type_ = ootype._string
 
     def compute_annotation(self):
-        return annmodel.SomeOOInstance(ootype=ootype.String)
+        return annmodel.SomeOOInstance(ootype=ootype.typeOf(self.instance))
 
 
 class Entry_ooparse_int(ExtRegistryEntry):

pypy/rpython/ootypesystem/rstr.py

         if s:
             return s
         else:
-            return self.convert_const(u'None')
+            return self.ll.ll_constant(u'None')
 
     def ll_encode_latin1(self, value):
         sb = ootype.new(ootype.StringBuilder)
         return buf.ll_build()
 
     def ll_constant(s):
-        return ootype.make_string(s)
+        if isinstance(s, str):
+            return ootype.make_string(s)
+        elif isinstance(s, unicode):
+            return ootype.make_unicode(s)
+        else:
+            assert False
     ll_constant._annspecialcase_ = 'specialize:memo'
 
     def do_stringformat(cls, hop, sourcevarsrepr):

pypy/rpython/test/test_runicode.py

 
     def test_strformat_unicode_arg(self):
         const = self.const
-        def percentS(s):
+        def percentS(s, i):
+            s = [s, None][i]
             return const("before %s after") % (s,)
         #
-        res = self.interpret(percentS, [const(u'à')])
+        res = self.interpret(percentS, [const(u'à'), 0])
         assert self.ll_to_string(res) == const(u'before à after')
         #
+        res = self.interpret(percentS, [const(u'à'), 1])
+        assert self.ll_to_string(res) == const(u'before None after')
+        #
 
     def unsupported(self):
         py.test.skip("not supported")