[pypy-svn] r32611 - in pypy/dist/pypy/translator/c: . test

mwh at codespeak.net mwh at codespeak.net
Sat Sep 23 18:40:15 CEST 2006


Author: mwh
Date: Sat Sep 23 18:40:14 2006
New Revision: 32611

Modified:
   pypy/dist/pypy/translator/c/primitive.py
   pypy/dist/pypy/translator/c/test/test_lltyped.py
Log:
make constant sizeof(something containing an array of Void)s compile and give
likely sounding results.


Modified: pypy/dist/pypy/translator/c/primitive.py
==============================================================================
--- pypy/dist/pypy/translator/c/primitive.py	(original)
+++ pypy/dist/pypy/translator/c/primitive.py	Sat Sep 23 18:40:14 2006
@@ -21,14 +21,19 @@
                 cdecl(db.gettype(value.TYPE), ''),
                 structnode.c_struct_field_name(value.fldname))
         elif isinstance(value, ItemOffset):
-            return '(sizeof(%s) * %s)'%(
-                cdecl(db.gettype(value.TYPE), ''), value.repeat)
+	    if value.TYPE != Void:
+                return '(sizeof(%s) * %s)'%(
+                    cdecl(db.gettype(value.TYPE), ''), value.repeat)
+            else:
+	    	return '0'
         elif isinstance(value, ArrayItemsOffset):
             if isinstance(value.TYPE, FixedSizeArray):
                 return '0'
-            else:
+            elif value.TYPE.OF != Void:
                 return 'offsetof(%s, items)'%(
                     cdecl(db.gettype(value.TYPE), ''))
+            else:
+                return 'sizeof(%s)'%(cdecl(db.gettype(value.TYPE), ''),)
         elif isinstance(value, ArrayLengthOffset):
             return 'offsetof(%s, length)'%(
                 cdecl(db.gettype(value.TYPE), ''))

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	Sat Sep 23 18:40:14 2006
@@ -251,3 +251,18 @@
         fn = self.getcompiled(llf)
         res = fn(0x33)
         assert res in [0x1033, 0x3320]
+
+    def test_sizeof_void_array(self):
+        from pypy.rpython.lltypesystem import llmemory
+        A = Array(Void)
+        size1 = llmemory.sizeof(A, 1)
+	size2 = llmemory.sizeof(A, 14)
+        def f(x=int):
+	    if x:
+	        return size1
+	    else:
+	        return size2
+	fn = self.getcompiled(f)
+	res1 = fn(1)
+	res2 = fn(0)
+	assert res1 == res2



More information about the Pypy-commit mailing list