Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Remove struct iparam hack



The patch below removes the struct iparam hack to initialise the parameter
hash table which might cause problems on machines where
sizeof(long) != sizeof(void*).  It does not fix any visible bugs but I
kindly ask everyone to try it.  Use cc instead of gcc and use the oldest
and most buggy cc you have on your system.  It assumes that a union can be
initialised with its first element.  This idea comes from Zefram.

That patch can be applied to all released and test zsh versions out there.

Patch below is a unified diff, I think in that case that's more readable than
the context diff.

Zoltan


--- Src/hashtable.h	1996/12/26 17:05:49	3.1.1.1
+++ Src/hashtable.h	1996/12/26 17:03:11
@@ -65,31 +65,17 @@
 #endif
 
 
-struct iparam {
-    struct hashnode *next;
-    char *nam;			/* hash data                             */
-    int flags;			/* PM_* flags (defined in zsh.h)         */
-    void *value;
-    int (*func1) _((void));	/* set func                              */
-    int (*func2) _((void));	/* get func                              */
-    int ct;			/* output base or field width            */
-    void *data;			/* used by getfns                        */
-    char *env;			/* location in environment, if exported  */
-    char *ename;		/* name of corresponding environment var */
-    Param old;			/* old struct for use with local         */
-    int level;			/* if (old != NULL), level of localness  */
-};
-
-#define IFN(X) ((int (*)_((void)))(X))
+#define SFN(X) {((void (*)_((Param, char *)))(X))}
+#define GFN(X) {((char *(*)_((Param)))(X))}
 
 /* Nodes for special parameters for parameter hash table */
 
 #ifdef GLOBALS
-struct iparam special_params[] =
+struct param special_params[] =
 {
-#define IPDEF1(A,B,C,D) {NULL,A,PM_INTEGER|PM_SPECIAL|D,NULL,IFN(C),IFN(B),10,NULL,NULL,NULL,NULL,0}
-IPDEF1("#", poundgetfn, IFN(nullsetfn), PM_READONLY),
-IPDEF1("ERRNO", errnogetfn, IFN(nullsetfn), PM_READONLY),
+#define IPDEF1(A,B,C,D) {NULL,A,PM_INTEGER|PM_SPECIAL|D,{NULL},SFN(C),GFN(B),10,NULL,NULL,NULL,NULL,0}
+IPDEF1("#", poundgetfn, nullsetfn, PM_READONLY),
+IPDEF1("ERRNO", errnogetfn, nullsetfn, PM_READONLY),
 IPDEF1("GID", gidgetfn, gidsetfn, PM_DONTIMPORT),
 IPDEF1("EGID", egidgetfn, egidsetfn, PM_DONTIMPORT),
 IPDEF1("HISTSIZE", histsizegetfn, histsizesetfn, 0),
@@ -97,20 +83,20 @@
 IPDEF1("SECONDS", secondsgetfn, secondssetfn, 0),
 IPDEF1("UID", uidgetfn, uidsetfn, PM_DONTIMPORT),
 IPDEF1("EUID", euidgetfn, euidsetfn, PM_DONTIMPORT),
-IPDEF1("TTYIDLE", ttyidlegetfn, IFN(nullsetfn), PM_READONLY),
+IPDEF1("TTYIDLE", ttyidlegetfn, nullsetfn, PM_READONLY),
 
-#define IPDEF2(A,B,C,D) {NULL,A,PM_SCALAR|PM_SPECIAL|D,NULL,IFN(C),IFN(B),0,NULL,NULL,NULL,NULL,0}
+#define IPDEF2(A,B,C,D) {NULL,A,PM_SCALAR|PM_SPECIAL|D,{NULL},{C},{B},0,NULL,NULL,NULL,NULL,0}
 IPDEF2("USERNAME", usernamegetfn, usernamesetfn, PM_DONTIMPORT),
-IPDEF2("-", dashgetfn, IFN(nullsetfn), PM_READONLY),
+IPDEF2("-", dashgetfn, nullsetfn, PM_READONLY),
 IPDEF2("histchars", histcharsgetfn, histcharssetfn, PM_DONTIMPORT),
 IPDEF2("HOME", homegetfn, homesetfn, 0),
 IPDEF2("TERM", termgetfn, termsetfn, 0),
 IPDEF2("WORDCHARS", wordcharsgetfn, wordcharssetfn, 0),
 IPDEF2("IFS", ifsgetfn, ifssetfn, PM_DONTIMPORT),
-IPDEF2("_", underscoregetfn, IFN(nullsetfn), PM_READONLY),
+IPDEF2("_", underscoregetfn, nullsetfn, PM_READONLY),
 
 #ifdef LC_ALL
-#define LCIPDEF(A,B) {NULL,A,PM_SCALAR|PM_SPECIAL|PM_UNSET,NULL,IFN(lcsetfn),IFN(strgetfn),0,(void *)B,NULL,NULL,NULL,0}
+#define LCIPDEF(A,B) {NULL,A,PM_SCALAR|PM_SPECIAL|PM_UNSET,{NULL},{lcsetfn},{strgetfn},0,(void *)B,NULL,NULL,NULL,0}
 IPDEF2("LANG", strgetfn, langsetfn, PM_UNSET),
 IPDEF2("LC_ALL", strgetfn, lc_allsetfn, PM_UNSET),
 #ifdef LC_COLLATE
@@ -127,23 +113,23 @@
 #endif
 #endif
 
-#define IPDEF4(A,B) {NULL,A,PM_INTEGER|PM_READONLY|PM_SPECIAL,NULL,IFN(nullsetfn),IFN(intvargetfn),10,(void *)B,NULL,NULL,NULL,0}
+#define IPDEF4(A,B) {NULL,A,PM_INTEGER|PM_READONLY|PM_SPECIAL,{NULL},{nullsetfn},GFN(intvargetfn),10,(void *)B,NULL,NULL,NULL,0}
 IPDEF4("!", &lastpid),
 IPDEF4("$", &mypid),
 IPDEF4("?", &lastval),
 IPDEF4("LINENO", &lineno),
 IPDEF4("PPID", &ppid),
 
-#define IPDEF5(A,B,F) {NULL,A,PM_INTEGER|PM_SPECIAL,NULL,IFN(F),IFN(intvargetfn),10,(void *)B,NULL,NULL,NULL,0}
+#define IPDEF5(A,B,F) {NULL,A,PM_INTEGER|PM_SPECIAL,{NULL},SFN(F),GFN(intvargetfn),10,(void *)B,NULL,NULL,NULL,0}
 IPDEF5("COLUMNS", &columns, zlevarsetfn),
 IPDEF5("LINES", &lines, zlevarsetfn),
 IPDEF5("OPTIND", &zoptind, intvarsetfn),
 IPDEF5("SHLVL", &shlvl, intvarsetfn),
 
-#define IPDEF6(A,B) {NULL,A,PM_SCALAR|PM_READONLY|PM_SPECIAL,NULL,IFN(nullsetfn),IFN(strvargetfn),0,(void *)B,NULL,NULL,NULL,0}
+#define IPDEF6(A,B) {NULL,A,PM_SCALAR|PM_READONLY|PM_SPECIAL,{NULL},SFN(nullsetfn),{strvargetfn},0,(void *)B,NULL,NULL,NULL,0}
 IPDEF6("PWD", &pwd),
 
-#define IPDEF7(A,B) {NULL,A,PM_SCALAR|PM_SPECIAL,NULL,IFN(strvarsetfn),IFN(strvargetfn),0,(void *)B,NULL,NULL,NULL,0}
+#define IPDEF7(A,B) {NULL,A,PM_SCALAR|PM_SPECIAL,{NULL},{strvarsetfn},{strvargetfn},0,(void *)B,NULL,NULL,NULL,0}
 IPDEF7("OLDPWD", &oldpwd),
 IPDEF7("OPTARG", &zoptarg),
 IPDEF7("NULLCMD", &nullcmd),
@@ -158,7 +144,7 @@
 IPDEF7("SPROMPT", &sprompt),
 IPDEF7("0", &argzero),
 
-#define IPDEF8(A,B,C) {NULL,A,PM_SCALAR|PM_SPECIAL,NULL,IFN(colonarrsetfn),IFN(colonarrgetfn),0,(void *)B,NULL,C,NULL,0}
+#define IPDEF8(A,B,C) {NULL,A,PM_SCALAR|PM_SPECIAL,{NULL},SFN(colonarrsetfn),GFN(colonarrgetfn),0,(void *)B,NULL,C,NULL,0}
 IPDEF8("CDPATH", &cdpath, "cdpath"),
 IPDEF8("FIGNORE", &fignore, "fignore"),
 IPDEF8("FPATH", &fpath, "fpath"),
@@ -169,17 +155,17 @@
 
 #ifdef DYNAMIC
 /* MODULE_PATH is not imported for security reasons */
-{NULL, "MODULE_PATH", PM_SCALAR|PM_SPECIAL|PM_DONTIMPORT, NULL, IFN(colonarrsetfn), IFN(colonarrgetfn), 0, (void *)&module_path, NULL, "module_path", NULL, 0},
+{NULL, "MODULE_PATH", PM_SCALAR|PM_SPECIAL|PM_DONTIMPORT, {NULL}, SFN(colonarrsetfn), GFN(colonarrgetfn), 0, (void *)&module_path, NULL, "module_path", NULL, 0},
 #endif
 
-#define IPDEF9(A,B,C) {NULL,A,PM_ARRAY|PM_SPECIAL|PM_DONTIMPORT,NULL,IFN(arrvarsetfn),IFN(arrvargetfn),0,(void *)B,NULL,C,NULL,0}
+#define IPDEF9(A,B,C) {NULL,A,PM_ARRAY|PM_SPECIAL|PM_DONTIMPORT,{NULL},SFN(arrvarsetfn),GFN(arrvargetfn),0,(void *)B,NULL,C,NULL,0}
 IPDEF9("*", &pparams, NULL),
 IPDEF9("@", &pparams, NULL),
 {NULL, NULL},
 
 /* The following parameters are not avaible in sh/ksh compatibility *
  * mode. All of these has sh compatible equivalents.                */
-IPDEF1("ARGC", poundgetfn, IFN(nullsetfn), PM_READONLY),
+IPDEF1("ARGC", poundgetfn, nullsetfn, PM_READONLY),
 IPDEF2("HISTCHARS", histcharsgetfn, histcharssetfn, PM_DONTIMPORT),
 IPDEF4("status", &lastval),
 IPDEF7("prompt", &prompt),
@@ -204,7 +190,7 @@
 {NULL, NULL}
 };
 #else
-extern struct iparam special_params[];
+extern struct param special_params[];
 #endif
 
 
--- Src/params.c	1996/12/31 01:57:45	3.1.1.4
+++ Src/params.c	1997/01/01 19:01:48
@@ -41,8 +41,7 @@
 void
 createparamtable(void)
 {
-    struct iparam *ip;
-    Param pm;
+    Param ip, pm;
     char **old_environ, **envp, **envp2, **sigptr, **t;
     char buf[50], *str, *iname;
     int num_env;



Messages sorted by: Reverse Date, Date, Thread, Author