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

PATCH: module parameter problems on Cygwin



Looks like no one's compiled under Cygwin for a while...  I updated the
version to 4.2.2 and tried to compile under Cygwin and it blew up.

It seems Cygwin won't let you initialise a value at compile time from
the pointer to a variable imported into a DLL.  Presumably this value
needs some code to fix it up after the import.  This came in with the
pseudo-vtable for the get/set/unset methods of parameters.

Luckily, the damage is a good deal less than I first thought.  It would
be nicer to have a way of indicating that you would like to use a
particular standard GSU class at compile time, but zsh/parameter and
zsh/zleparameter use their own ad-hoc initialisation methods and it
doesn't seem worth fixing up for one class in each case.

I also spotted a bug in zsh.h: INTPARAMDEF was using the wrong GSU
class.  This would only show up with the exint parameter in the example
module.  Whole civilizations could have gone by before anybody noticed.
It would probably be sensible to add tests for the example module, since
it will pick up interface problems like this.

Index: Src/module.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/module.c,v
retrieving revision 1.16
diff -u -r1.16 module.c
--- Src/module.c	7 Dec 2004 16:55:03 -0000	1.16
+++ Src/module.c	12 Jan 2005 12:09:38 -0000
@@ -1894,7 +1894,31 @@
 
     pm->level = 0;
     pm->u.data = d->var;
-    pm->gsu.i = (GsuInteger) d->gsu;
+    if (d->gsu)
+	pm->gsu.i = (GsuInteger) d->gsu;
+    else {
+	/*
+	 * If no get/set/unset class, use the appropriate
+	 * variable type.
+	 */
+	switch (PM_TYPE(pm->flags)) {
+	case PM_SCALAR:
+	    pm->gsu.s = &varscalar_gsu;
+	    break;
+
+	case PM_INTEGER:
+	    pm->gsu.i = &varinteger_gsu;
+	    break;
+
+	case PM_ARRAY:
+	    pm->gsu.a = &vararray_gsu;
+	    break;
+
+	default:
+	    unsetparam_pm(pm, 0, 1);
+	    return 1;
+	}
+    }
 
     return 0;
 }
Index: Src/zsh.h
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/zsh.h,v
retrieving revision 1.67
diff -u -r1.67 zsh.h
--- Src/zsh.h	7 Dec 2004 16:55:10 -0000	1.67
+++ Src/zsh.h	12 Jan 2005 12:09:38 -0000
@@ -1316,12 +1316,17 @@
 
 #define PARAMDEF(name, flags, var, gsu) \
     { name, flags, (void *) var, (void *) gsu, }
+/*
+ * Note that the following definitions are appropriate for defining
+ * parameters that reference a variable (var).  Hence the get/set/unset
+ * methods used will assume var needs dereferencing to get the value.
+ */
 #define INTPARAMDEF(name, var) \
-    { name, PM_INTEGER, (void *) var, (void *) &stdinteger_gsu }
+    { name, PM_INTEGER, (void *) var, NULL }
 #define STRPARAMDEF(name, var) \
-    { name, PM_SCALAR, (void *) var, (void *) &varscalar_gsu }
+    { name, PM_SCALAR, (void *) var, NULL }
 #define ARRPARAMDEF(name, var) \
-    { name, PM_ARRAY, (void *) var, (void *) &vararray_gsu }
+    { name, PM_ARRAY, (void *) var, NULL }
 
 #define setsparam(S,V) assignsparam(S,V,0)
 #define setaparam(S,V) assignaparam(S,V,0)
Index: Src/Modules/parameter.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/parameter.c,v
retrieving revision 1.31
diff -u -r1.31 parameter.c
--- Src/Modules/parameter.c	7 Dec 2004 16:55:10 -0000	1.31
+++ Src/Modules/parameter.c	12 Jan 2005 12:09:38 -0000
@@ -1812,6 +1812,13 @@
     Param pm;
 };
 
+/*
+ * This is a duplicate of nullsethash_gsu.  On some systems
+ * (such as Cygwin) we can't put a pointer to an imported variable
+ * in a compile-time initialiser, so we use this instead.
+ */
+static const struct gsu_hash pmnullsethash_gsu =
+{ hashgetfn, nullsethashfn, NULL };
 static const struct gsu_hash pmcommands_gsu =
 { hashgetfn, setpmcommands, stdunsetfn };
 static const struct gsu_hash pmfunctions_gsu =
@@ -1848,7 +1855,7 @@
 
 static struct pardef partab[] = {
     { "parameters", PM_READONLY,
-      getpmparameter, scanpmparameters, &nullsethash_gsu,
+      getpmparameter, scanpmparameters, &pmnullsethash_gsu,
       NULL, NULL },
     { "commands", 0,
       getpmcommand, scanpmcommands, &pmcommands_gsu,
Index: Src/Zle/zleparameter.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zleparameter.c,v
retrieving revision 1.4
diff -u -r1.4 zleparameter.c
--- Src/Zle/zleparameter.c	7 Dec 2004 16:55:12 -0000	1.4
+++ Src/Zle/zleparameter.c	12 Jan 2005 12:09:38 -0000
@@ -167,12 +167,19 @@
     Param pm;
 };
 
+/*
+ * This is a duplicate of stdhash_gsu.  On some systems
+ * (such as Cygwin) we can't put a pointer to an imported variable
+ * in a compile-time initialiser, so we use this instead.
+ */
+static const struct gsu_hash zlestdhash_gsu =
+{ hashgetfn, hashsetfn, stdunsetfn };
 static const struct gsu_array keymaps_gsu =
 { keymapsgetfn, arrsetfn, stdunsetfn };
 
 static struct pardef partab[] = {
     { "widgets", PM_READONLY,
-      getpmwidgets, scanpmwidgets, &stdhash_gsu,
+      getpmwidgets, scanpmwidgets, &zlestdhash_gsu,
       NULL, NULL },
     { "keymaps", PM_ARRAY|PM_SPECIAL|PM_READONLY,
       NULL, NULL, NULL,

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************



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