[pypy-svn] r48374 - in pypy/branch/pypy-rpython-unicode/rpython: lltypesystem test

fijal at codespeak.net fijal at codespeak.net
Wed Nov 7 23:19:34 CET 2007


Author: fijal
Date: Wed Nov  7 23:19:32 2007
New Revision: 48374

Modified:
   pypy/branch/pypy-rpython-unicode/rpython/lltypesystem/rstr.py
   pypy/branch/pypy-rpython-unicode/rpython/test/test_rstr.py
Log:
* fix test
* a bit of code simplification


Modified: pypy/branch/pypy-rpython-unicode/rpython/lltypesystem/rstr.py
==============================================================================
--- pypy/branch/pypy-rpython-unicode/rpython/lltypesystem/rstr.py	(original)
+++ pypy/branch/pypy-rpython-unicode/rpython/lltypesystem/rstr.py	Wed Nov  7 23:19:32 2007
@@ -12,7 +12,8 @@
 from pypy.rpython.lltypesystem import ll_str
 from pypy.rpython.lltypesystem.lltype import \
      GcStruct, Signed, Array, Char, UniChar, Ptr, malloc, \
-     Bool, Void, GcArray, nullptr, pyobjectptr, cast_primitive, typeOf
+     Bool, Void, GcArray, nullptr, pyobjectptr, cast_primitive, typeOf,\
+     staticAdtMethod, GcForwardReference
 from pypy.rpython.rmodel import Repr
 
 # ____________________________________________________________
@@ -24,11 +25,30 @@
 #        chars: array of Char
 #    }
 
-STR = GcStruct('rpy_string', ('hash',  Signed),
-                             ('chars', Array(Char, hints={'immutable': True,
-                                                          'isrpystring': True})))
-UNICODE = GcStruct('rpy_unicode', ('hash', Signed),
-                   ('chars', Array(UniChar, hints={'immutable': True})))
+STR = GcForwardReference()
+UNICODE = GcForwardReference()
+
+def new_malloc(TP):
+    def mallocstr(length):
+        debug_assert(length >= 0, "negative string length")
+        r = malloc(TP, length)
+        if not we_are_translated() or not malloc_zero_filled:
+            r.hash = 0
+        return r
+    mallocstr._annspecialcase_ = 'specialize:semierased'
+    return mallocstr
+
+mallocstr = new_malloc(STR)
+mallocunicode = new_malloc(UNICODE)
+
+STR.become(GcStruct('rpy_string', ('hash',  Signed),
+                    ('chars', Array(Char, hints={'immutable': True,
+                                                 'isrpystring': True})),
+                    adtmeths={'malloc':staticAdtMethod(mallocstr)}))
+UNICODE.become(GcStruct('rpy_unicode', ('hash', Signed),
+                        ('chars', Array(UniChar, hints={'immutable': True})),
+                        adtmeths={'malloc':staticAdtMethod(mallocunicode)}
+                        ))
 SIGNED_ARRAY = GcArray(Signed)
 CONST_STR_CACHE = WeakValueDictionary()
 CONST_UNICODE_CACHE = WeakValueDictionary()
@@ -121,19 +141,6 @@
                                  resulttype=pyobj_repr,
                                  _callable= lambda v: pyobjectptr(''.join(v.chars)))
 
-def new_malloc(TP):
-    def mallocstr(length):
-        debug_assert(length >= 0, "negative string length")
-        r = malloc(TP, length)
-        if not we_are_translated() or not malloc_zero_filled:
-            r.hash = 0
-        return r
-    mallocstr._annspecialcase_ = 'specialize:semierased'
-    return mallocstr
-
-mallocstr = new_malloc(STR)
-mallocunicode = new_malloc(UNICODE)
-
 # ____________________________________________________________
 #
 #  Low-level methods.  These can be run for testing, but are meant to
@@ -221,12 +228,7 @@
     def ll_strconcat(s1, s2):
         len1 = len(s1.chars)
         len2 = len(s2.chars)
-        if typeOf(s1).TO == STR and typeOf(s2).TO == STR:
-            malloc = mallocstr
-        else:
-            malloc = mallocunicode
-
-        newstr = malloc(len1 + len2)
+        newstr = s1.malloc(len1 + len2)
         j = 0
         while j < len1:
             newstr.chars[j] = s1.chars[j]

Modified: pypy/branch/pypy-rpython-unicode/rpython/test/test_rstr.py
==============================================================================
--- pypy/branch/pypy-rpython-unicode/rpython/test/test_rstr.py	(original)
+++ pypy/branch/pypy-rpython-unicode/rpython/test/test_rstr.py	Wed Nov  7 23:19:32 2007
@@ -651,7 +651,7 @@
 
     def test_float(self):
         const = self.const
-        f = [const(''), const('    '), const('0'), const('1'), const('-1.5'), CONST('1.5E2'), const('2.5e-1'), const(' 0 '), const('?')]
+        f = [const(''), const('    '), const('0'), const('1'), const('-1.5'), const('1.5E2'), const('2.5e-1'), const(' 0 '), const('?')]
         def fn(i):
             s = f[i]
             return float(s)



More information about the Pypy-commit mailing list