zsh-workers
 help / color / mirror / code / Atom feed
* autoloading modules
@ 1996-11-24 15:29 Zefram
  1996-11-24 22:40 ` Zoltan Hidvegi
  0 siblings, 1 reply; 3+ messages in thread
From: Zefram @ 1996-11-24 15:29 UTC (permalink / raw)
  To: Z Shell workers mailing list

-----BEGIN PGP SIGNED MESSAGE-----

I came up with this cool function yesterday:

function zmodautoload
{
  if [[ $# != 2 ]]; then
    echo >&2 "zmodautoload: wrong number of arguments"
    return 1
  fi
  eval "function $1 { if zmodload $2; then unfunction $1; $1 \$@; fi; }"
}

In order to support autoloading of modules that provide multiple builtins,
it would be helped by an option to zmodload that says "load this module,
but keep quiet if it's already loaded".  The patch below adds such an
option, -i (for idempotent).  To make use of it in zmodautoload, change
"zmodload" to "zmodload -i" above.

Zoltan, what is "zmodload -f" for?

 -zefram

      Index: Doc/zshbuiltins.man
      ===================================================================
      RCS file: /home/zefram/usr/cvsroot/zsh/Doc/zshbuiltins.man,v
      retrieving revision 1.13
      diff -c -r1.13 zshbuiltins.man
      *** zshbuiltins.man	1996/11/23 01:18:50	1.13
      --- zshbuiltins.man	1996/11/23 21:57:21
      ***************
      *** 1199,1205 ****
        \fBwhich\fP [ \-\fBpam\fP ] \fIname\fP ...
        Same as \fBwhence \-c\fP.
        %IFDYN%.TP
      ! %IFDYN%\fBzmodload \fP[\fB-u\fP] \fIname
        %IFDYN%Load (or, with
        %IFDYN%.BR -u ,
        %IFDYN%unload) a binary module.
      --- 1199,1205 ----
        \fBwhich\fP [ \-\fBpam\fP ] \fIname\fP ...
        Same as \fBwhence \-c\fP.
        %IFDYN%.TP
      ! %IFDYN%\fBzmodload \fP[\-\fBfiu\fP] \fIname
        %IFDYN%Load (or, with
        %IFDYN%.BR -u ,
        %IFDYN%unload) a binary module.
      ***************
      *** 1209,1214 ****
      --- 1209,1220 ----
        %IFDYN%.IR name .
        %IFDYN%.RS
        %IFDYN%.PP
      + %IFDYN%If the module to be loaded is already loaded, the behaviour
      + %IFDYN%depends on the options.  If the \fB\-i\fP option is given,
      + %IFDYN%the duplicate module is ignored.  Otherwise, if the \fB\-f\fP
      + %IFDYN%option is given, an attempt is made to load the module again.
      + %IFDYN%Otherwise (if neither option is given), it is an error.
      + %IFDYN%.PP
        %IFDYN%The
        %IFDYN%.IR name d
        %IFDYN%module is searched for in the same way a command is, using
      ***************
      *** 1228,1232 ****
      --- 1234,1240 ----
        %IFDYN%.I name
        %IFDYN%must be given that was given when the module was loaded, but it is not
        %IFDYN%necessary for the module to exist in the filesystem.
      + %IFDYN%The \fB\-i\fP option suppresses the error if the module is already
      + %IFDYN%unloaded (or was never loaded).
        %IFDYN%.RE
        .RE
      Index: Src/hashtable.h
      ===================================================================
      RCS file: /home/zefram/usr/cvsroot/zsh/Src/hashtable.h,v
      retrieving revision 1.21
      diff -c -r1.21 hashtable.h
      *** hashtable.h	1996/11/15 00:30:54	1.21
      --- hashtable.h	1996/11/23 21:58:48
      ***************
      *** 304,310 ****
        #endif
        
        #ifdef DYNAMIC
      !     {NULL, "zmodload", 0, bin_zmodload, 0, -1, 0, "uf", NULL},
        #endif
            {NULL, "popd", 0, bin_cd, 0, 2, BIN_POPD, NULL, NULL},
            {NULL, "print", BINF_PRINTOPTS, bin_print, 0, -1, BIN_PRINT, "RDPnrslzNu0123456789pioOcm-", NULL},
      --- 304,310 ----
        #endif
        
        #ifdef DYNAMIC
      !     {NULL, "zmodload", 0, bin_zmodload, 0, -1, 0, "ufi", NULL},
        #endif
            {NULL, "popd", 0, bin_cd, 0, 2, BIN_POPD, NULL, NULL},
            {NULL, "print", BINF_PRINTOPTS, bin_print, 0, -1, BIN_PRINT, "RDPnrslzNu0123456789pioOcm-", NULL},
      Index: Src/module.c
      ===================================================================
      RCS file: /home/zefram/usr/cvsroot/zsh/Src/module.c,v
      retrieving revision 1.12
      diff -c -r1.12 module.c
      *** module.c	1996/11/23 01:18:00	1.12
      --- module.c	1996/11/23 21:59:45
      ***************
      *** 168,179 ****
        	    }
        	}
        	if (ops['u']) {
      ! 	    if (! found) {
        		zwarnnam(nam, "no such module %s", *args, 0);
        		ret++;
        	    }
        	} else if (found) {
      ! 	    if (! ops['f']) {
        		zwarnnam(nam, "module %s already loaded.", *args, 0);
        		ret++;
        	    } else if ((handle = load_module(*args)) != m->handle) {
      --- 168,181 ----
        	    }
        	}
        	if (ops['u']) {
      ! 	    if (!found && !ops['i']) {
        		zwarnnam(nam, "no such module %s", *args, 0);
        		ret++;
        	    }
        	} else if (found) {
      ! 	    if(ops['i'])
      ! 		;
      ! 	    else if(!ops['f']) {
        		zwarnnam(nam, "module %s already loaded.", *args, 0);
        		ret++;
        	    } else if ((handle = load_module(*args)) != m->handle) {

-----BEGIN PGP SIGNATURE-----
Version: 2.6.2

iQCVAwUBMpd2+nD/+HJTpU/hAQFlEAP/TQpSXPbcyTPjibllIlSHmXBmqAkRWvO0
KszHN+5MW5UJQUQqwHIheOxfB8lbAZbcKXCD6jMClf7rzrqCYnwdp4l8VIgp6ra8
Rd/e+4fRgmubXlV6PcYlMLANR4Heyx9BjNVdjINopgd2koKnDHk+/XyjgOt3Jesm
PokPoq24rX4=
=5Sh9
-----END PGP SIGNATURE-----


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: autoloading modules
  1996-11-24 15:29 autoloading modules Zefram
@ 1996-11-24 22:40 ` Zoltan Hidvegi
  1996-11-25 13:02   ` Zefram
  0 siblings, 1 reply; 3+ messages in thread
From: Zoltan Hidvegi @ 1996-11-24 22:40 UTC (permalink / raw)
  To: Zefram; +Cc: zsh-workers

> In order to support autoloading of modules that provide multiple builtins,
> it would be helped by an option to zmodload that says "load this module,
> but keep quiet if it's already loaded".  The patch below adds such an
> option, -i (for idempotent).  To make use of it in zmodautoload, change
> "zmodload" to "zmodload -i" above.

Would not -q (quiet) be a better name for this option?  And the same can be
achieved by redirection stderr.

> Zoltan, what is "zmodload -f" for?

Well it is quite useless, it'll probably be removed.  Originally I added
this to test dlopen on Linux.  The manual claims that if the same library
is loaded twice the same handle is returned which is not true (at least
libdl.so.1.8.2 does not behave this way).

I think that modules should be identified by their name with the extension
and pathname stripped and zsh should not allow loading two modules with the
same name (even if they have different path name).

I also like your other patch to compile in modules but this sed hack is
quite unelegant.  There must be a way to avoid that.

Zoltan


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: autoloading modules
  1996-11-24 22:40 ` Zoltan Hidvegi
@ 1996-11-25 13:02   ` Zefram
  0 siblings, 0 replies; 3+ messages in thread
From: Zefram @ 1996-11-25 13:02 UTC (permalink / raw)
  To: Zoltan Hidvegi; +Cc: zefram, zsh-workers

>Would not -q (quiet) be a better name for this option?  And the same can be
>achieved by redirection stderr.

Not quite.  -i only suppresses one type of error, that of loading an
already loaded module.  If loading is attempted and fails, it still
complains, and the zmodautoload-generated function won't unfunction
itself.  A -q option should logically suppress all error reports, but
that could indeed by done by redirecting stderr.

>I think that modules should be identified by their name with the extension
>and pathname stripped and zsh should not allow loading two modules with the
>same name (even if they have different path name).

No.  commands with the same name but different directories are
logically distinct, and modules should be treated the same way.  It
might be useful to allow unloading of a module by base name only, but
we can get a much more powerful effect by adding a -m option (i.e. a
globbing option).

-zefram


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1996-11-25 13:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-11-24 15:29 autoloading modules Zefram
1996-11-24 22:40 ` Zoltan Hidvegi
1996-11-25 13:02   ` Zefram

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).