[pypy-svn] r49376 - in pypy/dist/pypy/rpython: . module ootypesystem test

fijal at codespeak.net fijal at codespeak.net
Wed Dec 5 13:15:48 CET 2007


Author: fijal
Date: Wed Dec  5 13:15:48 2007
New Revision: 49376

Modified:
   pypy/dist/pypy/rpython/module/support.py
   pypy/dist/pypy/rpython/ootypesystem/ootype.py
   pypy/dist/pypy/rpython/rlist.py
   pypy/dist/pypy/rpython/test/test_llinterp.py
   pypy/dist/pypy/rpython/test/test_rstr.py
   pypy/dist/pypy/rpython/test/test_runicode.py
   pypy/dist/pypy/rpython/test/tool.py
Log:
Add a few hacks to be able to test one-line diff to support inplace_add
of list of unichars and unicode string.


Modified: pypy/dist/pypy/rpython/module/support.py
==============================================================================
--- pypy/dist/pypy/rpython/module/support.py	(original)
+++ pypy/dist/pypy/rpython/module/support.py	Wed Dec  5 13:15:48 2007
@@ -56,6 +56,10 @@
     def to_rstr(s):
         return ootype.oostring(s, -1)
     to_rstr = staticmethod(to_rstr)
+
+    def to_runicode(u):
+        return ootype.oounicode(u, -1)
+    to_runicode = staticmethod(to_runicode)
     
     def from_rstr(rs):
         if not rs:   # null pointer

Modified: pypy/dist/pypy/rpython/ootypesystem/ootype.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/ootype.py	(original)
+++ pypy/dist/pypy/rpython/ootypesystem/ootype.py	Wed Dec  5 13:15:48 2007
@@ -1571,7 +1571,6 @@
     """
     assert base == -1
     if isinstance(obj, unicode):
-        assert len(obj) == 1
         return make_unicode(obj)
     elif isinstance(obj, _string):
         s = unicode(obj._str)

Modified: pypy/dist/pypy/rpython/rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/rlist.py	(original)
+++ pypy/dist/pypy/rpython/rlist.py	Wed Dec  5 13:15:48 2007
@@ -359,7 +359,7 @@
         if r_lst1.item_repr.lowleveltype not in (Char, UniChar):
             raise TyperError('"lst += string" only supported with a list '
                              'of chars or unichars')
-        string_repr = r_lst1.rtyper.type_system.rstr.string_repr
+        string_repr = r_str2.repr
         v_lst1, v_str2 = hop.inputargs(r_lst1, string_repr)
         c_strlen  = hop.inputconst(Void, string_repr.ll.ll_strlen)
         c_stritem = hop.inputconst(Void, string_repr.ll.ll_stritem_nonneg)

Modified: pypy/dist/pypy/rpython/test/test_llinterp.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_llinterp.py	(original)
+++ pypy/dist/pypy/rpython/test/test_llinterp.py	Wed Dec  5 13:15:48 2007
@@ -11,6 +11,7 @@
 from pypy.annotation import model as annmodel
 from pypy.annotation.model import lltype_to_annotation
 from pypy.rlib.rarithmetic import r_uint, ovfcheck
+from pypy.rpython.ootypesystem import ootype
 from pypy import conftest
 
 # switch on logging of interp to show more info on failing tests
@@ -84,9 +85,9 @@
             T = typeOf(x)
             if T == Ptr(PyObject) and someobjects:
                 return object
-            elif T == Ptr(rstr.STR):
+            elif T == Ptr(rstr.STR) or T == ootype.String:
                 return str
-            elif T == Ptr(rstr.UNICODE):
+            elif T == Ptr(rstr.UNICODE) or T == ootype.Unicode:
                 return unicode
             else:
                 return lltype_to_annotation(T)

Modified: pypy/dist/pypy/rpython/test/test_rstr.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rstr.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rstr.py	Wed Dec  5 13:15:48 2007
@@ -779,6 +779,18 @@
         if conftest.option.view:
             t.view()
         assert summary(fgraph) == {}
+
+    def test_inplace_add(self):
+        const = self.const
+        def f(x, y):
+            if x > 0:
+                l = [const('a'), const('b')]
+            else:
+                l = [const('a')]
+            l += y
+            return const('').join(l)
+
+        assert self.ll_to_string(self.interpret(f, [1, self.string_to_ll(const('abc'))])) == 'ababc'
         
 
 def FIXME_test_str_to_pystringobj():

Modified: pypy/dist/pypy/rpython/test/test_runicode.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_runicode.py	(original)
+++ pypy/dist/pypy/rpython/test/test_runicode.py	Wed Dec  5 13:15:48 2007
@@ -215,6 +215,19 @@
         py.test.skip("We should think how to solve this problem")
     test_rfind_empty_string = test_find_empty_string
 
+
+    def test_inplace_add(self):
+        const = self.const
+        def f(x, y):
+            if x > 0:
+                l = [const('a'), const('b')]
+            else:
+                l = [const('a')]
+            l += y
+            return const('').join(l)
+
+        assert self.ll_to_unicode(self.interpret(f, [1, self.unicode_to_ll(const('abc'))])) == 'ababc'
+
 class TestLLtype(BaseTestRUnicode, LLRtypeMixin):
     EMPTY_STRING_HASH = -1
 

Modified: pypy/dist/pypy/rpython/test/tool.py
==============================================================================
--- pypy/dist/pypy/rpython/test/tool.py	(original)
+++ pypy/dist/pypy/rpython/test/tool.py	Wed Dec  5 13:15:48 2007
@@ -94,6 +94,10 @@
         from pypy.rpython.module.support import OOSupport        
         return OOSupport.to_rstr(s)
 
+    def unicode_to_ll(self, u):
+        from pypy.rpython.module.support import OOSupport
+        return OOSupport.to_runicode(u)
+
     def ll_to_list(self, l):
         return l._list[:]
 



More information about the Pypy-commit mailing list