zsh-workers
 help / color / mirror / code / Atom feed
From: Sven Wischnowsky <wischnow@informatik.hu-berlin.de>
To: zsh-workers@sunsite.auc.dk
Subject: PATCH: fix for require_module()
Date: Wed, 21 Apr 1999 09:24:38 +0200 (MET DST)	[thread overview]
Message-ID: <199904210724.JAA16712@beta.informatik.hu-berlin.de> (raw)


I stumbled over this last weekend. The zle module uses
`require_module()' to make sure that the `compctl' module is loaded
when `zle -C' is invoked. But if `compctl' is linked in, this won't
work, because linked-in modules don't appear in the `modules' list.

The patch adds another list `bltinmodules' with the names of the
linked-in modules and makes `mkbltnmlst.sh' call the function
`register_module()' for them.

Bye
 Sven

diff -u os/init.c Src/init.c
--- os/init.c	Thu Mar 25 10:09:04 1999
+++ Src/init.c	Wed Apr 21 09:09:42 1999
@@ -559,6 +559,7 @@
     module_path = mkarray(ztrdup(MODULE_DIR));
     modules = newlinklist();
 #endif
+    bltinmodules = newlinklist();
 
     /* Set default prompts */
     if(unset(INTERACTIVE)) {
diff -u os/mkbltnmlst.sh Src/mkbltnmlst.sh
--- os/mkbltnmlst.sh	Wed Apr 21 09:16:05 1999
+++ Src/mkbltnmlst.sh	Wed Apr 21 09:16:47 1999
@@ -61,6 +61,6 @@
 		exit 1 ;;
 	esac
     done
-    echo "    mod.nam = \"$bin_mod\"; setup_$bin_mod(&mod); boot_$bin_mod(&mod);"
+    echo "    register_module(mod.nam = \"$bin_mod\"); setup_$bin_mod(&mod); boot_$bin_mod(&mod);"
     done_mods="$done_mods$bin_mod "
 done
diff -u os/module.c Src/module.c
--- os/module.c	Thu Feb 25 12:07:06 1999
+++ Src/module.c	Wed Apr 21 09:17:52 1999
@@ -30,6 +30,12 @@
 #include "zsh.mdh"
 #include "module.pro"
 
+/* List of builtin modules. */
+
+/**/
+LinkList bltinmodules;
+
+
 /* The `zsh' module contains all the base code that can't actually be built *
  * as a separate module.  It is initialised by main(), so there's nothing   *
  * for the boot function to do.                                             */
@@ -48,6 +54,17 @@
     return 0;
 }
 
+/* This registers a builtin module.                                   */
+
+/**/
+void
+register_module(char *n)
+{
+    PERMALLOC {
+	addlinknode(bltinmodules, n);
+    } LASTALLOC;
+}
+
 /* addbuiltin() can be used to add a new builtin.  It returns zero on *
  * success, 1 on failure.  The only possible type of failure is that  *
  * a builtin with the specified name already exists.  An autoloaded   *
@@ -573,29 +590,34 @@
  * about trying to load a module with a full path name in restricted mode.
  * The last argument should be non-zero if this function should signal an
  * error if the module is already loaded.
- * The return value is the module of NULL if the module couldn't be loaded. */
+ * The return value is non-zero if the module was found or loaded. */
 
 /**/
-Module
+int
 require_module(char *nam, char *module, int res, int test)
 {
     Module m = NULL;
     LinkNode node;
 
+    /* First see if the module is linked in. */
+    for (node = firstnode(bltinmodules); node; incnode(node)) {
+	if (!strcmp((char *) getdata(node), nam))
+	    return 1;
+    }
     node = find_module(module);
     if (node && (m = ((Module) getdata(node)))->handle &&
 	!(m->flags & MOD_UNLOAD)) {
 	if (test) {
 	    zwarnnam(nam, "module %s already loaded.", module, 0);
-	    return NULL;
+	    return 0;
 	}
     } else if (res && isset(RESTRICTED) && strchr(module, '/')) {
 	zwarnnam(nam, "%s: restricted", module, 0);
-	return NULL;
+	return 0;
     } else
-	return load_module(module);
+	return !!load_module(module);
 
-    return m;
+    return 1;
 }
 
 /**/

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


                 reply	other threads:[~1999-04-21  7:24 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=199904210724.JAA16712@beta.informatik.hu-berlin.de \
    --to=wischnow@informatik.hu-berlin.de \
    --cc=zsh-workers@sunsite.auc.dk \
    /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).