[pypy-commit] pypy win32-fixes5: make msvc happier for 0-length unions (test_raw_array_field_prebuilt)

mattip noreply at buildbot.pypy.org
Fri Sep 12 14:07:35 CEST 2014


Author: mattip <matti.picus at gmail.com>
Branch: win32-fixes5
Changeset: r73500:d69db21b9810
Date: 2014-08-28 23:32 +0300
http://bitbucket.org/pypy/pypy/changeset/d69db21b9810/

Log:	make msvc happier for 0-length unions
	(test_raw_array_field_prebuilt)

diff --git a/rpython/translator/c/node.py b/rpython/translator/c/node.py
--- a/rpython/translator/c/node.py
+++ b/rpython/translator/c/node.py
@@ -521,12 +521,16 @@
             return []
         lines = list(self.initializationexpr())
         type, name = self.get_declaration()
-        if name != self.name:
-            lines[0] = '{ ' + lines[0]    # extra braces around the 'a' part
-            lines[-1] += ' }'             # of the union
-        lines[0] = '%s = %s' % (
-            cdecl(type, name, self.is_thread_local()),
-            lines[0])
+        if name != self.name and len(lines) < 2:
+            # a union with length 0
+            lines[0] = cdecl(type, name, self.is_thread_local())
+        else:
+            if name != self.name:    
+                lines[0] = '{ ' + lines[0]    # extra braces around the 'a' part
+                lines[-1] += ' }'             # of the union
+            lines[0] = '%s = %s' % (
+                cdecl(type, name, self.is_thread_local()),
+                lines[0])
         lines[-1] += ';'
         return lines
 
@@ -563,6 +567,11 @@
     def initializationexpr(self, decoration=''):
         T = self.getTYPE()
         is_empty = True
+        type, name = self.get_declaration()
+        if name != self.name and self.getvarlength() < 1:
+            # an empty union
+            yield ''
+            return
         yield '{'
         defnode = self.db.gettypedefnode(T)
 


More information about the pypy-commit mailing list