Subject: rpcgen fix for -fshort-enums
To: None <tech-toolchain@netbsd.org>
From: Ben Harris <bjh21@netbsd.org>
List: tech-toolchain
Date: 02/05/2002 00:57:09
If (as is looking likely) NetBSD goes to -fshort-enums by default, it'd be
nice if those enums that are generated by rpcgen were protected from
causing ABI changes.  This patch arranges that by adding extra elements to
each such enum so as to ensure that it's large enough to hold all the
legal values of an XDR enum (32-bit signed integer).  Does this seem
sensible?  Should asn1_compile do something similar?

Index: rpc_hout.c
===================================================================
RCS file: /cvsroot/basesrc/usr.bin/rpcgen/rpc_hout.c,v
retrieving revision 1.17
diff -u -r1.17 rpc_hout.c
--- rpc_hout.c	2002/01/31 22:43:57	1.17
+++ rpc_hout.c	2002/02/05 00:51:17
@@ -401,6 +401,13 @@
 		}
 		f_print(fout, ",\n");
 	}
+	/*
+	 * Ensure that this enumeration gets allocated enough bits to
+	 * hold all possible future values.  This avoids ABI changes
+	 * when the set of enumerators changes.
+	 */
+	f_print(fout, "\t__rpcgen_%s_min = -0x7fffffff-1,\n", name);
+	f_print(fout, "\t__rpcgen_%s_max = 0x7fffffff,\n", name);
 	f_print(fout, "};\n");
 	f_print(fout, "typedef enum %s %s;\n", name, name);
 }

-- 
Ben Harris                                                   <bjh21@netbsd.org>
Portmaster, NetBSD/arm26               <URL:http://www.netbsd.org/Ports/arm26/>