[pypy-svn] r32363 - in pypy/branch/kill-keepalives/pypy/translator/c: . test

arigo at codespeak.net arigo at codespeak.net
Fri Sep 15 15:20:44 CEST 2006


Author: arigo
Date: Fri Sep 15 15:20:41 2006
New Revision: 32363

Modified:
   pypy/branch/kill-keepalives/pypy/translator/c/node.py
   pypy/branch/kill-keepalives/pypy/translator/c/test/test_lltyped.py
Log:
Added missing support for prebuilt arrays that have the nolength hint.


Modified: pypy/branch/kill-keepalives/pypy/translator/c/node.py
==============================================================================
--- pypy/branch/kill-keepalives/pypy/translator/c/node.py	(original)
+++ pypy/branch/kill-keepalives/pypy/translator/c/node.py	Fri Sep 15 15:20:41 2006
@@ -510,15 +510,19 @@
                                                    '%sgcheader%d' % (decoration, i))
                 for line in lines:
                     yield line
+        if self.T._hints.get('nolength', False):
+            length = ''
+        else:
+            length = '%d, ' % len(self.obj.items)
         if self.T.OF is Void or len(self.obj.items) == 0:
-            yield '\t%d' % len(self.obj.items)
+            yield '\t' + length[:-2]   # skip the ', '
             yield '}'
         elif self.T.OF == Char:
-            yield '\t%d, %s' % (len(self.obj.items),
-                                c_char_array_constant(''.join(self.obj.items)))
+            yield '\t%s%s' % (length,
+                              c_char_array_constant(''.join(self.obj.items)))
             yield '}'
         else:
-            yield '\t%d, {' % len(self.obj.items)
+            yield '\t%s{' % (length,)
             for j in range(len(self.obj.items)):
                 value = self.obj.items[j]
                 lines = generic_initializationexpr(self.db, value,

Modified: pypy/branch/kill-keepalives/pypy/translator/c/test/test_lltyped.py
==============================================================================
--- pypy/branch/kill-keepalives/pypy/translator/c/test/test_lltyped.py	(original)
+++ pypy/branch/kill-keepalives/pypy/translator/c/test/test_lltyped.py	Fri Sep 15 15:20:41 2006
@@ -79,6 +79,39 @@
         fn = self.getcompiled(llf)
         fn()
 
+    def test_prebuilt_nolength_array(self):
+        A = Array(Signed, hints={'nolength': True})
+        a = malloc(A, 5, immortal=True)
+        a[0] = 8
+        a[1] = 5
+        a[2] = 12
+        a[3] = 12
+        a[4] = 15
+        def llf():
+            s = ''
+            for i in range(5):
+                s += chr(64+a[i])
+            assert s == "HELLO"
+        fn = self.getcompiled(llf)
+        fn()
+
+    def test_prebuilt_nolength_char_array(self):
+        for lastchar in ('\x00', 'X'):
+            A = Array(Char, hints={'nolength': True})
+            a = malloc(A, 5, immortal=True)
+            a[0] = '8'
+            a[1] = '5'
+            a[2] = '?'
+            a[3] = '!'
+            a[4] = lastchar
+            def llf():
+                s = ''
+                for i in range(5):
+                    s += a[i]
+                assert s == "85?!" + lastchar
+            fn = self.getcompiled(llf)
+            fn()
+
     def test_call_with_fixedsizearray(self):
         A = FixedSizeArray(Struct('s1', ('x', Signed)), 5)
         S = GcStruct('s', ('a', Ptr(A)))



More information about the Pypy-commit mailing list