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

Re: PATCH: separate watch/log functionality out into a module



> 2021/10/30 7:15, Oliver Kiddle <opk@xxxxxxx> wrote:
> 
> This patch extracts the functionality out into a zsh/watch module.

With this patch (either with or without the one in worker/49544⁩),
build fails on Cygwin as follows:

gcc -c ...(snip)...  -o watch..o watch.c
In file included from ../../Src/zsh.mdh:16,
                 from watch.mdh:15,
                 from watch.c:30:
../../Src/zsh.h:2097:34: error: initializer element is not constant
 2097 |     { name, flags, (void *) var, (void *) gsu, \
      |                                  ^
watch.c:643:5: note: in expansion of macro ‘PARAMDEF’
  643 |     PARAMDEF("WATCH", PM_SCALAR|PM_SPECIAL, &watch, &colonarr_gsu),
      |     ^~~~~~~~

(and the same error for &vararray_gsu)

On Cygwin, params.o (in which colonarr_gsu is defined) is not included in
the main zsh.exe but in libzsh.dll (I don't know why).
This means &colonarr_gsu is not a build-time constant and can't be used
for the initialization of the static variable partab[].
A simple workaround is to set the .gsu in the setup_() function.
This takes virtually no time to execute and I think we don't need to use
#ifdef __CYGWIN__.




diff --git a/Src/Modules/watch.c b/Src/Modules/watch.c
index 5ce604c63..1c2766dda 100644
--- a/Src/Modules/watch.c
+++ b/Src/Modules/watch.c
@@ -640,8 +640,8 @@ static struct builtin bintab[] = {
 };
 
 static struct paramdef partab[] = {
-    PARAMDEF("WATCH", PM_SCALAR|PM_SPECIAL, &watch, &colonarr_gsu),
-    PARAMDEF("watch", PM_ARRAY|PM_SPECIAL, &watch, &vararray_gsu),
+    PARAMDEF("WATCH", PM_SCALAR|PM_SPECIAL, &watch, NULL),
+    PARAMDEF("watch", PM_ARRAY|PM_SPECIAL, &watch, NULL),
 };
 
 static struct features module_features = {
@@ -656,6 +656,10 @@ static struct features module_features = {
 int
 setup_(UNUSED(Module m))
 {
+    /* On Cygwin, colonarr_gsu exists in libzsh.dll and we can't
+     * use &colonarr_gsu in the initialization of bintab[] above */
+    partab[0].gsu = (void *)&colonarr_gsu;
+    partab[1].gsu = (void *)&vararray_gsu;
     return 0;
 }
 






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