zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: Zsh Hackers' List <zsh-workers@zsh.org>
Subject: PATCH: autoloading already loaded features
Date: Wed, 13 Nov 2013 20:11:49 +0000	[thread overview]
Message-ID: <20131113201149.284354fb@pws-pc.ntlworld.com> (raw)
In-Reply-To: <20131109223250.706e20fb@pws-pc.ntlworld.com>

On Sat, 9 Nov 2013 22:32:50 +0000
Peter Stephenson <p.w.stephenson@ntlworld.com> wrote:
> For autoloads from modules, which may be builtins, conditions, math
> functions or parameters, we can actually do a bit better, with a little
> more work but nothing like to the same extent (no additional loading is
> required).  Suppose we load builtin bar from zsh/foo at some point,
> doesn't matter how, then run "zmodload -a bar zsh/foo".  We find that a
> builtin bar exists.  We can then check that zsh/foo is already loaded,
> and is already providing builtin bar.

Gah.  This turns out to be completely trivial.  We already check if the
module is loaded, so we can ensure that it does in fact provide that
feature.  We just need to check at that point if it *is* providing that
feature.  Then we can be absolutely confident that simply telling the
user everything is OK is the right thing to do: they're already getting
the feature they've just asked for.  If it's not yet providing the
feature, marking it for autoload works unless there's a clash (it's a
little pointless since we could just enable it immediately but that's a
bit more work).

diff --git a/Src/module.c b/Src/module.c
index 5cc595c..c567b3c 100644
--- a/Src/module.c
+++ b/Src/module.c
@@ -3419,12 +3419,15 @@ autofeatures(const char *cmdnam, const char *module, char **features,
     int ret = 0, subret;
     Module defm, m;
     char **modfeatures = NULL;
+    int *modenables = NULL;
     if (module) {
 	defm = (Module)find_module(module,
 				   FINDMOD_ALIASP|FINDMOD_CREATE, NULL);
 	if ((defm->node.flags & MOD_LINKED) ? defm->u.linked :
-	    defm->u.handle)
+	    defm->u.handle) {
 	    (void)features_module(defm, &modfeatures);
+	    (void)enables_module(defm, &modenables);
+	}
     } else
 	defm = NULL;
 
@@ -3544,6 +3547,16 @@ autofeatures(const char *cmdnam, const char *module, char **features,
 		    ret = 1;
 		    continue;
 		}
+		/*
+		 * If the feature is already provided by the module, there's
+		 * nothing more to do.
+		 */
+		if (modenables[ptr-modfeatures])
+		    continue;
+		/*
+		 * Otherwise, marking it for autoload will do the
+		 * right thing when the feature is eventually usd.
+		 */
 	    }
 	    if (!m->autoloads) {
 		m->autoloads = znewlinklist();

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


      parent reply	other threads:[~2013-11-13 21:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20131106202321.4a48c77b@pws-pc.ntlworld.com>
     [not found] ` <20131107153315.GW3544@sym.noone.org>
     [not found]   ` <20131107160551.7aa195dc@pwslap01u.europe.root.pri>
     [not found]     ` <20131107191806.GA85153@redoubt.spodhuis.org>
     [not found]       ` <131107173627.ZM24325@torch.brasslantern.com>
     [not found]         ` <20131108071627.GA6216@redoubt.spodhuis.org>
     [not found]           ` <20131108093822.1534aa88@pwslap01u.europe.root.pri>
     [not found]             ` <131108063903.ZM25660@torch.brasslantern.com>
     [not found]               ` <20131108161109.6e373049@pwslap01u.europe.root.pri>
     [not found]                 ` <131108181143.ZM26121@torch.brasslantern.com>
     [not found]                   ` <20131109223250.706e20fb@pws-pc.ntlworld.com>
2013-11-10 20:03                     ` Errors on module feature [auto]loading (Re: zsh 5.0.2-test-1 is available) Bart Schaefer
2013-11-10 20:44                       ` Peter Stephenson
2013-11-13 20:11                     ` Peter Stephenson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131113201149.284354fb@pws-pc.ntlworld.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).