diff macro.c @ 184:d359d9b86327

Don't rely on anonymous unions. They break on... dun dun dun... Solaris. Such a shock.
author David A. Holland
date Fri, 12 Jun 2015 03:35:01 -0400
parents 6119608a9817
children c8d4ab9aeff0
line wrap: on
line diff
--- a/macro.c	Fri Jun 12 03:28:19 2015 -0400
+++ b/macro.c	Fri Jun 12 03:35:01 2015 -0400
@@ -32,6 +32,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "union.h"
 #include "array.h"
 #include "mode.h"
 #include "place.h"
@@ -41,13 +42,19 @@
 struct expansionitem {
 	enum { EI_STRING, EI_PARAM, EI_FILE, EI_LINE } itemtype;
 	union {
-		char *string;		/* EI_STRING */
-		unsigned param;		/* EI_PARAM */
-	};
+		char *ei_string;		/* for EI_STRING */
+		unsigned ei_param;		/* for EI_PARAM */
+	} UN;
 };
 DECLARRAY(expansionitem, static UNUSED);
 DEFARRAY(expansionitem, static);
 
+#ifdef NEED_UNION_ACCESSORS
+#define ei_string un.ei_string
+#define ei_param un.ei_param
+#endif
+
+
 struct macro {
 	struct place defplace;
 	struct place expansionplace;
@@ -78,7 +85,7 @@
 
 	ei = domalloc(sizeof(*ei));
 	ei->itemtype = EI_STRING;
-	ei->string = dostrdup(string);
+	ei->ei_string = dostrdup(string);
 	return ei;
 }
 
@@ -90,7 +97,7 @@
 
 	ei = domalloc(sizeof(*ei));
 	ei->itemtype = EI_STRING;
-	ei->string = dostrndup(string, len);
+	ei->ei_string = dostrndup(string, len);
 	return ei;
 }
 
@@ -102,7 +109,7 @@
 
 	ei = domalloc(sizeof(*ei));
 	ei->itemtype = EI_PARAM;
-	ei->param = param;
+	ei->ei_param = param;
 	return ei;
 }
 
@@ -134,7 +141,7 @@
 {
 	switch (ei->itemtype) {
 	    case EI_STRING:
-		dostrfree(ei->string);
+		dostrfree(ei->ei_string);
 		break;
 	    case EI_PARAM:
 	    case EI_FILE:
@@ -154,12 +161,12 @@
 	}
 	switch (ei1->itemtype) {
 	    case EI_STRING:
-		if (strcmp(ei1->string, ei2->string) != 0) {
+		if (strcmp(ei1->ei_string, ei2->ei_string) != 0) {
 			return false;
 		}
 		break;
 	    case EI_PARAM:
-		if (ei1->param != ei2->param) {
+		if (ei1->ei_param != ei2->ei_param) {
 			return false;
 		}
 		break;
@@ -822,10 +829,10 @@
 		ei = expansionitemarray_get(&es->curmacro->expansion, i);
 		switch (ei->itemtype) {
 		    case EI_STRING:
-			len += strlen(ei->string);
+			len += strlen(ei->ei_string);
 			break;
 		    case EI_PARAM:
-			arg = stringarray_get(&es->args, ei->param);
+			arg = stringarray_get(&es->args, ei->ei_param);
 			len += strlen(arg);
 			break;
 		    case EI_FILE:
@@ -843,10 +850,10 @@
 		ei = expansionitemarray_get(&es->curmacro->expansion, i);
 		switch (ei->itemtype) {
 		    case EI_STRING:
-			strcat(ret, ei->string);
+			strcat(ret, ei->ei_string);
 			break;
 		    case EI_PARAM:
-			arg = stringarray_get(&es->args, ei->param);
+			arg = stringarray_get(&es->args, ei->ei_param);
 			strcat(ret, arg);
 			break;
 		    case EI_FILE: