(U+6215): Apply new conventions for glyph granularity.
[chise/xemacs-chise.git.1] / src / emodules.c
index b8f2e6e..22eda2b 100644 (file)
@@ -49,7 +49,7 @@ static dll_handle dlhandle;
 static emodules_list *modules;
 static int modnum;
 
-static int find_make_module (CONST char *mod, CONST char *name, CONST char *ver, int make_or_find);
+static int find_make_module (const char *mod, const char *name, const char *ver, int make_or_find);
 static Lisp_Object module_load_unwind (Lisp_Object);
 static void attempt_module_delete (int mod);
 
@@ -73,13 +73,13 @@ modules have been loaded as dynamic shared objects by examining the
 return value of the function `list-modules'.
 
 It is possible, although unwise, to unload modules using `unload-module'.
-The prefered mechanism for unloading or reloading modules is to quit
+The preferred mechanism for unloading or reloading modules is to quit
 XEmacs, and then reload those new or changed modules that are required.
 
 Messages informing you of the progress of the load are displayed unless
 the variable `load-modules-quietly' is non-NIL.
 */
-       (file,name,version))
+       (file, name, version))
 {
   char *mod, *mname, *mver;
   int speccount = specpdl_depth();
@@ -114,11 +114,11 @@ Unload a module previously loaded with load-module.
 As with load-module, this function requires at least the module FILE, and
 optionally the module NAME and VERSION to unload.  It may not be possible
 for the module to be unloaded from memory, as there may be Lisp objects
-refering to variables inside the module code.  However, once you have
+referring to variables inside the module code.  However, once you have
 requested a module to be unloaded, it will be unloaded from memory as
 soon as the last reference to symbols within the module is destroyed.
 */
-       (file,name,version))
+       (file, name, version))
 {
   int x;
   char *mod, *mname, *mver;
@@ -184,7 +184,7 @@ is a bug, and you are encouraged to report it.
 }
 
 static int
-find_make_module (CONST char *mod, CONST char *name, CONST char *ver, int mof)
+find_make_module (const char *mod, const char *name, const char *ver, int mof)
 {
   int i, fs = -1;
 
@@ -209,13 +209,13 @@ find_make_module (CONST char *mod, CONST char *name, CONST char *ver, int mof)
     return fs; /* First free slot */
 
   /*
-   * We only get here if we havent found a free slot and the module was
+   * We only get here if we haven't found a free slot and the module was
    * not previously loaded.
    */
   if (modules == (emodules_list *)0)
-    modules = (emodules_list *)xmalloc (sizeof(emodules_list));
+    modules = (emodules_list *) xmalloc (sizeof (emodules_list));
   modnum++;
-  modules = xrealloc (modules, modnum * sizeof(emodules_list));
+  modules = (emodules_list *) xrealloc (modules, modnum * sizeof (emodules_list));
 
   fs = modnum - 1;
   memset (&modules[fs], 0, sizeof(emodules_list));
@@ -278,7 +278,7 @@ module_load_unwind (Lisp_Object upto)
  * Do the actual grunt-work of loading in a module. We first try and
  * dlopen() the module. If that fails, we have an error and we bail
  * out immediately. If the dlopen() succeeds, we need to check for the
- * existance of certain special symbols.
+ * existence of certain special symbols.
  *
  * All modules will have complete access to the variables and functions
  * defined within XEmacs itself.  It is up to the module to declare any
@@ -288,30 +288,30 @@ module_load_unwind (Lisp_Object upto)
  *
  * We need to be very careful with how we load modules. If we encounter an
  * error along the way, we need to back out completely to the point at
- * which the user started. Since we can be called resursively, we need to
+ * which the user started. Since we can be called recursively, we need to
  * take care with marking modules as loaded. When we first start loading
  * modules, we set the counter to zero. As we enter the function each time,
- * we incremement the counter, and before we leave we decrement it. When
+ * we increment the counter, and before we leave we decrement it. When
  * we get back down to 0, we know we are at the end of the chain and we
  * can mark all the modules in the list as loaded.
  *
  * When we signal an error, we need to be sure to unwind all modules loaded
  * thus far (but only for this module chain). It is assumed that if any
  * modules in a chain fail, then they all do. This is logical, considering
- * that the only time we recurse is when we have dependant modules. So in
+ * that the only time we recurse is when we have dependent modules. So in
  * the error handler we take great care to close off the module chain before
  * we call "error" and let the Fmodule_load unwind_protect() function handle
  * the cleaning up.
  */
 void
-emodules_load(CONST char *module, CONST char *modname, CONST char *modver)
+emodules_load(const char *module, const char *modname, const char *modver)
 {
   Lisp_Object filename;
   Lisp_Object foundname;
   int fd, x, mpx;
   char *soname, *tmod;
-  CONST char **f;
-  CONST long *ellcc_rev;
+  const char **f;
+  const long *ellcc_rev;
   char *mver, *mname, *mtitle, *symname;
   void (*modload)(void) = 0;
   void (*modsyms)(void) = 0;
@@ -326,7 +326,7 @@ emodules_load(CONST char *module, CONST char *modname, CONST char *modver)
   emodules_depth++;
   dlhandle = 0;
 
-  if ((module == (CONST char *)0) || (module[0] == '\0'))
+  if ((module == (const char *)0) || (module[0] == '\0'))
     error ("Empty module name");
 
   /* This is to get around the fact that build_string() is not declared
@@ -350,15 +350,15 @@ emodules_load(CONST char *module, CONST char *modname, CONST char *modver)
   if (dlhandle == (dll_handle)0)
     error ("Opening dynamic module: %s", dll_error (dlhandle));
 
-  ellcc_rev = (CONST long *)dll_variable (dlhandle, "emodule_compiler");
-  if ((ellcc_rev == (CONST long *)0) || (*ellcc_rev <= 0))
+  ellcc_rev = (const long *)dll_variable (dlhandle, "emodule_compiler");
+  if ((ellcc_rev == (const long *)0) || (*ellcc_rev <= 0))
     error ("Missing symbol `emodule_compiler': Invalid dynamic module");
   if (*ellcc_rev > EMODULES_REVISION)
     error ("Unsupported version `%ld(%ld)': Invalid dynamic module",
            *ellcc_rev, EMODULES_REVISION);
 
-  f = (CONST char **)dll_variable (dlhandle, "emodule_name");
-  if ((f == (CONST char **)0) || (*f == (CONST char *)0))
+  f = (const char **)dll_variable (dlhandle, "emodule_name");
+  if ((f == (const char **)0) || (*f == (const char *)0))
     error ("Missing symbol `emodule_name': Invalid dynamic module");
 
   mname = (char *)alloca (strlen (*f) + 1);
@@ -366,15 +366,15 @@ emodules_load(CONST char *module, CONST char *modname, CONST char *modver)
   if (mname[0] == '\0')
     error ("Empty value for `emodule_name': Invalid dynamic module");
 
-  f = (CONST char **)dll_variable (dlhandle, "emodule_version");
-  if ((f == (CONST char **)0) || (*f == (CONST char *)0))
+  f = (const char **)dll_variable (dlhandle, "emodule_version");
+  if ((f == (const char **)0) || (*f == (const char *)0))
     error ("Missing symbol `emodule_version': Invalid dynamic module");
 
   mver = (char *)alloca (strlen (*f) + 1);
   strcpy (mver, *f);
 
-  f = (CONST char **)dll_variable (dlhandle, "emodule_title");
-  if ((f == (CONST char **)0) || (*f == (CONST char *)0))
+  f = (const char **)dll_variable (dlhandle, "emodule_title");
+  if ((f == (const char **)0) || (*f == (const char *)0))
     error ("Missing symbol `emodule_title': Invalid dynamic module");
 
   mtitle = (char *)alloca (strlen (*f) + 1);
@@ -386,7 +386,7 @@ emodules_load(CONST char *module, CONST char *modname, CONST char *modver)
   strcat (symname, mname);
   modload = (void (*)(void))dll_function (dlhandle, symname);
   /*
-   * modload is optional. If the module doesnt require other modules it can
+   * modload is optional. If the module doesn't require other modules it can
    * be left out.
    */
 
@@ -418,7 +418,7 @@ emodules_load(CONST char *module, CONST char *modname, CONST char *modver)
    * Attempt to make a new slot for this module. If this really is the
    * first time we are loading this module, the used member will be 0.
    * If that is non-zero, we know that we have a previously loaded module
-   * of the same name and version, and we dont need to go any further.
+   * of the same name and version, and we don't need to go any further.
    */
   mpx = find_make_module (soname, mname, mver, 0);
   mp = &modules[mpx];
@@ -426,6 +426,7 @@ emodules_load(CONST char *module, CONST char *modname, CONST char *modver)
     {
       emodules_depth--;
       dll_close (dlhandle);
+      dlhandle = 0;  /* Zero this out before module_load_unwind runs */
       return;
     }
 
@@ -478,11 +479,11 @@ emodules_load(CONST char *module, CONST char *modname, CONST char *modver)
 }
 
 void
-emodules_doc_subr(CONST char *symname, CONST char *doc)
+emodules_doc_subr(const char *symname, const char *doc)
 {
   Bytecount len = strlen (symname);
-  Lisp_Object sym = oblookup (Vobarray, (CONST Bufbyte *)symname, len);
-  struct Lisp_Subr *subr;
+  Lisp_Object sym = oblookup (Vobarray, (const Bufbyte *)symname, len);
+  Lisp_Subr *subr;
 
   if (SYMBOLP(sym))
     {
@@ -498,10 +499,10 @@ emodules_doc_subr(CONST char *symname, CONST char *doc)
 }
 
 void
-emodules_doc_sym (CONST char *symname, CONST char *doc)
+emodules_doc_sym (const char *symname, const char *doc)
 {
   Bytecount len = strlen (symname);
-  Lisp_Object sym = oblookup (Vobarray, (CONST Bufbyte *)symname, len);
+  Lisp_Object sym = oblookup (Vobarray, (const Bufbyte *)symname, len);
   Lisp_Object docstr;
   struct gcpro gcpro1;
 
@@ -526,18 +527,28 @@ syms_of_module (void)
 }
 
 void
+reinit_vars_of_module (void)
+{
+  emodules_depth = 0;
+  modules = (emodules_list *)0;
+  modnum = 0;
+}
+
+void
 vars_of_module (void)
 {
+  reinit_vars_of_module ();
+
   DEFVAR_LISP ("module-version", &Vmodule_version /*
 Emacs dynamic loading mechanism version, as a string.
 
 This string is in the form XX.YY.ppp, where XX is the major version
 number, YY is the minor version number, and ppp is the patch level.
-This variable can be used to distinquish between different versions of
+This variable can be used to distinguish between different versions of
 the dynamic loading technology used in Emacs, if required.  It is not
 a given that this value will be the same as the Emacs version number.
 */ );
-  Vmodule_version = Fpurecopy (build_string (EMODULES_VERSION));
+  Vmodule_version = build_string (EMODULES_VERSION);
 
   DEFVAR_BOOL ("load-modules-quietly", &load_modules_quietly /*
 *Set to t if module loading is to be silent.
@@ -554,7 +565,7 @@ called by a Lisp function.
 Each element is a string (directory name) or nil (try default directory).
 
 Note that elements of this list *may not* begin with "~", so you must
-call `expland-file-name' on them before adding them to this list.
+call `expand-file-name' on them before adding them to this list.
 
 Initialized based on EMACSMODULEPATH environment variable, if any, otherwise
 to default specified the file `paths.h' when XEmacs was built.  If there
@@ -563,21 +574,18 @@ value for this variable by looking around in the file-system near the
 directory in which the XEmacs executable resides.
 
 Due to the nature of dynamic modules, the path names should almost always
-refer to architecture-dependant directories.  It is unwise to attempt to
-store dynamic modules in a hetrogenous environment.  Some environments
+refer to architecture-dependent directories.  It is unwise to attempt to
+store dynamic modules in a heterogenous environment.  Some environments
 are similar enough to each other that XEmacs will be unable to determine
 the correctness of a dynamic module, which can have unpredictable results
 when a dynamic module is loaded.
 */);
 
   /* #### Export this to Lisp */
-  Vmodule_extensions = build_string (":.ell:.so:.dll");
+  Vmodule_extensions = build_string (":.ell:.so:.dll:.dylib");
   staticpro (&Vmodule_extensions);
 
   load_modules_quietly = 0;
-  emodules_depth = 0;
-  modules = (emodules_list *)0;
-  modnum = 0;
   Vmodule_load_path = Qnil;
   Fprovide (intern ("modules"));
 }