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

[PATCH] Fix support for AUTOALL



If a builtin is marked for autoloading with "zmodload -ab <module-name> <builtin-name>", then when the builtin is used for the first time, the named module should be loaded and all its features (i.e., all its builtins, condition codes, parameters, and math functions) should be enabled. The same should happen when an autoloading condition code, parameter, or math function is used. Currently this only works for builtins and condition codes. The support for parameters was broken (by me) in workers/53781 (when an autoloading parameter is used for the first time, the module is loaded but only that parameter gets enabled, not all the module's features). The support for math functions never existed or was lost at some point. This patch restores support for enabling all the module's features on the first use of autoloading parameters and math functions.

Fix support for AUTOALL
  (depends on workers/55145)

Philippe

diff --git a/Src/module.c b/Src/module.c
index 9577cc278..b1708c1dd 100644
--- a/Src/module.c
+++ b/Src/module.c
@@ -1420,6 +1420,8 @@ add_automathfunc(const char *module, const char *fnam, int flags)
     f->name = ztrdup(fnam);
     f->module = ztrdup(module);
     f->flags = 0;
+    if (flags & FEAT_AUTOALL)
+	f->flags |= MFF_AUTOALL;
 
     if (addmathfunc(f)) {
 	zsfree(f->name);
diff --git a/Src/params.c b/Src/params.c
index c5248a40f..9625c5fd5 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -654,7 +654,7 @@ loadparam_pm(Param pm)
     char *module = dupstring(pm->u.str);
     char *name = dupstring(pm->node.nam);
     int level = pm->level;
-    ensurefeature(module, "p:", name);
+    ensurefeature(module, "p:", (pm->node.flags & PM_AUTOALL) ? NULL : name);
     pm = getparam(name);
     while (pm && pm->level > level)
 	pm = pm->old;
diff --git a/Test/V01zmodload.ztst b/Test/V01zmodload.ztst
index ec55e0f95..3cbae163b 100644
--- a/Test/V01zmodload.ztst
+++ b/Test/V01zmodload.ztst
@@ -42,6 +42,13 @@
  mkdir zmodload.tmp
  cd zmodload.tmp
 
+ alias skip-test-if-module-is-not-available=';
+   if [[ $mods[(r)$mod] != $mod ]]; then
+     ZTST_skip="$mod module not available"
+     return
+   fi
+ '
+
 %test
 
 # This first test depends on knowing that zsh is run with +Z from the
@@ -69,16 +76,18 @@
 0d:Test loading of all compiled modules
 
  zmodload -e $mods
-0d:Check that zsh believes the modules did load
+0:Check that zsh believes the modules did load
 
 # Now check for proper failure conditions by trying some operations on
 # a nonexistent module.
 
  zmodload bogus/notamodule
-1D:Check that loading a nonexistent module fails
+1:Check that loading a nonexistent module fails
+*?\(eval\):1: failed to load module `bogus/notamodule':*
 
  zmodload -u bogus/notamodule
-1D:Check that unloading a nonexistent module fails
+1:Check that unloading a nonexistent module fails
+?(eval):zmodload:1: no such module bogus/notamodule
 
 # Test adding and removing autoloads, using a nonexistent module.
 
@@ -116,20 +125,39 @@
 
 # If the "example" module is available, test various autoloading behavior.
 
- if [[ $mods[(r)zsh/example] == zsh/example ]]; then
+   mod=zsh/example skip-test-if-module-is-not-available
    zmodload -u zsh/example
    zmodload -ab zsh/example example
-   builtin example
+   builtin example >/dev/null
+   type example
+   typeset -p exarr
    zmodload -e zsh/example
- else print -u$ZTST_fd Warning: zsh/example not linked: not checking autoloading
- fi
-0d:Autoload a module via a builtin
+0:Autoload a module via a builtin
+>Thank you for using the example module.  Have a nice day.
+>The example module has now been set up.
+>example is a shell builtin
+>typeset -g -a exarr=(  )
+
+  mod=zsh/example skip-test-if-module-is-not-available
+  zmodload -u zsh/example
+  builtin example >/dev/null
+0:Autoloads are persistent
+>Thank you for using the example module.  Have a nice day.
+>The example module has now been set up.
 
- if [[ $mods[(r)zsh/example] == zsh/example ]]; then
+  mod=zsh/example skip-test-if-module-is-not-available
+  type example
   zmodload -u zsh/example
-  builtin example
- fi
-0d:Autoloads are persistent
+  type example
+  zmodload -ub example
+  type example
+  zmodload zsh/example
+0:Autoloads can be removed
+>example is a shell builtin
+>Thank you for using the example module.  Have a nice day.
+>example is a shell builtin
+>example not found
+>The example module has now been set up.
 
   (zmodload -u zsh/parameter
   zmodload -aF zsh/parameter b:fail
@@ -209,40 +237,52 @@
 >p:userdirs
 >p:usergroups
 
- if [[ $mods[(r)zsh/example] == zsh/example ]]; then
+   mod=zsh/example skip-test-if-module-is-not-available
    zmodload -u zsh/example
    zmodload -ac -I zsh/example ex
-   [[ exam -ex ple ]]
+   [[ exam -ex ple ]]; echo status=$?
+   type example
+   typeset -p exarr
    zmodload -e zsh/example
- else :
- fi
-0d:Autoload a module via a condition
-
- if [[ $mods[(r)zsh/example] == zsh/example ]]; then
+0:Autoload a module via a condition
+>Thank you for using the example module.  Have a nice day.
+>The example module has now been set up.
+>status=0
+>example is a shell builtin
+>typeset -g -a exarr=( example array )
+
+   mod=zsh/example skip-test-if-module-is-not-available
    zmodload -u zsh/example
    zmodload -ap zsh/example exint
-   : $exint
+   echo exint=$exint
+   type example
+   typeset -p exarr
    zmodload -e zsh/example
- else :
- fi
-0d:Autoload a module via a parameter
-
- if [[ $mods[(r)zsh/example] == zsh/example ]]; then
+0:Autoload a module via a parameter
+>Thank you for using the example module.  Have a nice day.
+>The example module has now been set up.
+>exint=42
+>example is a shell builtin
+>typeset -g -a exarr=( example array )
+
+   mod=zsh/example skip-test-if-module-is-not-available
    zmodload -u zsh/example
    zmodload -af zsh/example sum
-   (( sum(1) ))
+   echo sum=$(( sum(1,2,3) ))
+   type example
+   typeset -p exarr
    zmodload -e zsh/example
- else :
- fi
-0d:Autoload a module via a math function
-
- if [[ $mods[(r)zsh/watch] == zsh/watch ]]; then
+0:Autoload a module via a math function
+>Thank you for using the example module.  Have a nice day.
+>The example module has now been set up.
+>sum=6
+>example is a shell builtin
+>typeset -g -a exarr=( example array )
+
+   mod=zsh/watch skip-test-if-module-is-not-available
    zmodload -u zsh/watch
    WATCH=foo:bar
    typeset -p WATCH watch
- else
-   ZTST_skip="zsh/watch module not available"
- fi
 0:Autoload tied parameters
 >typeset -g -T WATCH watch=( foo bar )
 >typeset -g -aT WATCH watch=( foo bar )
@@ -254,14 +294,18 @@
 0:Test creating a module alias
 >example -> zsh/example
 
- if [[ $mods[(r)zsh/example] == zsh/example ]]; then
+   mod=zsh/example skip-test-if-module-is-not-available
    zmodload -u example
    zmodload -ab example
-   builtin example
+   builtin example >/dev/null
+   type example
+   typeset -p exarr
    zmodload -e example
- else :
- fi
-0d:Unload/autoload the module via its alias
+0:Unload/autoload the module via its alias
+>Thank you for using the example module.  Have a nice day.
+>The example module has now been set up.
+>example is a shell builtin
+>typeset -g -a exarr=(  )
 
  zmodload -R example
  zmodload -e example
@@ -285,9 +329,8 @@
 0:Listing feature autoloads includes unloaded modules
 >zmodload -Fa zsh/zftp b:zftp
 
-  if ! zmodload zsh/system >/dev/null 2>&1; then
-    ZTST_skip="zsh/system module not available"
-  else
+    mod=zsh/system skip-test-if-module-is-not-available
+    zmodload zsh/system
     zmodload -lF zsh/system
     zmodload -F zsh/system -p:errnos
     print ${+errnos}
@@ -295,7 +338,6 @@
     zmodload -F zsh/system +p:errnos
     print ${+errnos}
     zmodload -lF zsh/system
-  fi
 0:Regression tests for index bug with math functions.
 >+b:syserror
 >+b:sysread
@@ -327,16 +369,14 @@
 >+p:errnos
 >+p:sysparams
 
-  if ! zmodload zsh/system >/dev/null 2>&1; then
-    ZTST_skip="zsh/system module not available"
-  else
+    mod=zsh/system skip-test-if-module-is-not-available
+    zmodload zsh/system
     zmodload -F zsh/system -f:systell
     zmodload -lF zsh/system
     (print $(( systell(-1) )))
     zmodload -F zsh/system +f:systell
     zmodload -lF zsh/system
     (print $(( systell(-1) )))
-  fi
 1:Module Features for math functions
 >+b:syserror
 >+b:sysread
@@ -356,8 +396,8 @@
 >+f:systell
 >+p:errnos
 >+p:sysparams
-?(eval):6: unknown function: systell
-?(eval):9: file descriptor out of range
+?(eval):5: unknown function: systell
+?(eval):8: file descriptor out of range
 
  $ZTST_testdir/../Src/zsh -fc "
    MODULE_PATH=${(q)MODULE_PATH}


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