Subject: rpcgen and -fshort-enums round 2
To: None <tech-toolchain@netbsd.org>
From: Ben Harris <bjh21@netbsd.org>
List: tech-toolchain
Date: 02/18/2002 22:17:40
People suggested that hardcoding 0x7fffffff into rpcgen's output was ugly,
so how about this?  Note that the rpcgen changes are complicated by having
to undo one of christos' fixes, and I'm not entirely sure that my defines
either have the right names or are in the right place.  I'll commit this
if no-one comes up with a better idea by Saturday though.

Index: include/rpc/types.h
===================================================================
RCS file: /cvsroot/basesrc/include/rpc/types.h,v
retrieving revision 1.13
diff -u -r1.13 types.h
--- include/rpc/types.h	2000/06/13 01:02:44	1.13
+++ include/rpc/types.h	2002/02/18 22:11:31
@@ -43,6 +43,9 @@
 typedef int32_t bool_t;
 typedef int32_t enum_t;

+#define XDR_ENUM_MAX	0x7fffffff
+#define XDR_ENUM_MIN	(-0x7fffffff-1)
+
 typedef u_int32_t rpcprog_t;
 typedef u_int32_t rpcvers_t;
 typedef u_int32_t rpcproc_t;
Index: usr.bin/rpcgen/rpc_hout.c
===================================================================
RCS file: /cvsroot/basesrc/usr.bin/rpcgen/rpc_hout.c,v
retrieving revision 1.18
diff -u -r1.18 rpc_hout.c
--- usr.bin/rpcgen/rpc_hout.c	2002/02/05 22:03:01	1.18
+++ usr.bin/rpcgen/rpc_hout.c	2002/02/18 22:11:32
@@ -384,11 +384,10 @@
 	enumval_list *l;
 	char   *last = NULL;
 	int     count = 0;
-	char   *first = "";

 	f_print(fout, "enum %s {\n", name);
 	for (l = def->def.en.vals; l != NULL; l = l->next) {
-		f_print(fout, "%s\t%s", first, l->name);
+		f_print(fout, "\t%s", l->name);
 		if (l->assignment) {
 			f_print(fout, " = %s", l->assignment);
 			last = l->assignment;
@@ -400,9 +399,16 @@
 				f_print(fout, " = %s + %d", last, count++);
 			}
 		}
-		first = ",\n";
+		f_print(fout, ",\n");
 	}
-	f_print(fout, "\n};\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 = XDR_ENUM_MIN,\n", name);
+	f_print(fout, "\t__rpcgen_%s_max = XDR_ENUM_MAX\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/>