[pypy-svn] r46708 - in pypy/dist/pypy/translator/c: . test
arigo at codespeak.net
arigo at codespeak.net
Tue Sep 18 10:24:47 CEST 2007
Author: arigo
Date: Tue Sep 18 10:24:47 2007
New Revision: 46708
Modified:
pypy/dist/pypy/translator/c/node.py
pypy/dist/pypy/translator/c/test/test_lltyped.py
Log:
Uh oh. Prebuilt arrays with the 'nolength' hint were no rendered correctly.
Modified: pypy/dist/pypy/translator/c/node.py
==============================================================================
--- pypy/dist/pypy/translator/c/node.py (original)
+++ pypy/dist/pypy/translator/c/node.py Tue Sep 18 10:24:47 2007
@@ -523,15 +523,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%s' % length.rstrip(', ')
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/dist/pypy/translator/c/test/test_lltyped.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_lltyped.py (original)
+++ pypy/dist/pypy/translator/c/test/test_lltyped.py Tue Sep 18 10:24:47 2007
@@ -340,3 +340,40 @@
fn = self.getcompiled(f, [int])
res = fn(100)
assert res == 100 + len(list(names))
+
+ def test_array_nolength(self):
+ A = Array(Signed, hints={'nolength': True})
+ a1 = malloc(A, 3, immortal=True)
+ a1[0] = 30
+ a1[1] = 300
+ a1[2] = 3000
+
+ def f(n):
+ a2 = malloc(A, n, flavor='raw')
+ for i in range(n):
+ a2[i] = a1[i % 3] + i
+ res = a2[n // 2]
+ free(a2, flavor='raw')
+ return res
+
+ fn = self.getcompiled(f, [int])
+ res = fn(100)
+ assert res == 3050
+
+ def test_gcarray_nolength(self):
+ A = GcArray(Signed, hints={'nolength': True})
+ a1 = malloc(A, 3, immortal=True)
+ a1[0] = 30
+ a1[1] = 300
+ a1[2] = 3000
+
+ def f(n):
+ a2 = malloc(A, n)
+ for i in range(n):
+ a2[i] = a1[i % 3] + i
+ res = a2[n // 2]
+ return res
+
+ fn = self.getcompiled(f, [int])
+ res = fn(100)
+ assert res == 3050
More information about the Pypy-commit
mailing list