[pypy-commit] pypy default: pff, the usual rpython test&fix dance

antocuni noreply at buildbot.pypy.org
Thu Jul 19 10:18:25 CEST 2012


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: 
Changeset: r56219:c8cdf66b371a
Date: 2012-07-19 10:16 +0200
http://bitbucket.org/pypy/pypy/changeset/c8cdf66b371a/

Log:	pff, the usual rpython test&fix dance

diff --git a/pypy/rpython/lltypesystem/rstr.py b/pypy/rpython/lltypesystem/rstr.py
--- a/pypy/rpython/lltypesystem/rstr.py
+++ b/pypy/rpython/lltypesystem/rstr.py
@@ -4,7 +4,7 @@
 from pypy.rpython.error import TyperError
 from pypy.rlib.objectmodel import malloc_zero_filled, we_are_translated
 from pypy.rlib.objectmodel import _hash_string, enforceargs
-from pypy.rlib.objectmodel import keepalive_until_here
+from pypy.rlib.objectmodel import keepalive_until_here, specialize
 from pypy.rlib.debug import ll_assert
 from pypy.rlib import jit
 from pypy.rlib.rarithmetic import ovfcheck
@@ -174,7 +174,7 @@
         if s:
             return s
         else:
-            return self.ll.ll_constant(u'None')
+            return self.ll.ll_constant_unicode(u'None')
 
     @jit.elidable
     def ll_encode_latin1(self, s):
@@ -963,14 +963,13 @@
     def ll_build_finish(builder):
         return LLHelpers.ll_join_strs(len(builder), builder)
 
+    @specialize.memo()
     def ll_constant(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'
+        return string_repr.convert_const(s)
+
+    @specialize.memo()
+    def ll_constant_unicode(s):
+        return unicode_repr.convert_const(s)
 
     def do_stringformat(cls, hop, sourcevarsrepr):
         s_str = hop.args_s[0]
diff --git a/pypy/rpython/ootypesystem/rstr.py b/pypy/rpython/ootypesystem/rstr.py
--- a/pypy/rpython/ootypesystem/rstr.py
+++ b/pypy/rpython/ootypesystem/rstr.py
@@ -1,5 +1,6 @@
 from pypy.tool.pairtype import pairtype
 from pypy.annotation import model as annmodel
+from pypy.rlib.objectmodel import specialize
 from pypy.rlib.rarithmetic import ovfcheck
 from pypy.rpython.error import TyperError
 from pypy.rpython.rstr import AbstractStringRepr,AbstractCharRepr,\
@@ -84,7 +85,7 @@
         if s:
             return s
         else:
-            return self.ll.ll_constant(u'None')
+            return self.ll.ll_constant_unicode(u'None')
 
     def ll_encode_latin1(self, value):
         sb = ootype.new(ootype.StringBuilder)
@@ -310,14 +311,13 @@
     def ll_build_finish(buf):
         return buf.ll_build()
 
+    @specialize.memo()
     def ll_constant(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'
+        return ootype.make_string(s)
+
+    @specialize.memo()
+    def ll_constant_unicode(s):
+        return ootype.make_unicode(s)
 
     def do_stringformat(cls, hop, sourcevarsrepr):
         InstanceRepr = hop.rtyper.type_system.rclass.InstanceRepr
diff --git a/pypy/rpython/test/test_runicode.py b/pypy/rpython/test/test_runicode.py
--- a/pypy/rpython/test/test_runicode.py
+++ b/pypy/rpython/test/test_runicode.py
@@ -209,6 +209,18 @@
         assert self.ll_to_string(res) == const(u'before None after')
         #
 
+    def test_strformat_unicode_and_str(self):
+        # test that we correctly specialize ll_constant when we pass both a
+        # string and an unicode to it
+        const = self.const
+        def percentS(ch):
+            x = "%s" % (ch + "bc")
+            y = u"%s" % (unichr(ord(ch)) + u"bc")
+            return len(x)+len(y)
+        #
+        res = self.interpret(percentS, ["a"])
+        assert res == 6
+
     def unsupported(self):
         py.test.skip("not supported")
 


More information about the pypy-commit mailing list