20.1.1 Initialising the Module Loader

back: a module loading subsystem
forward: managing module loader errors
fastback: a complex gnu autotools project
up: a module loading subsystem
fastforward: a loadable module
top: autoconf, automake, and libtool
contents: table of contents
index: index
about: about this document

Before using this code (or any other libltdl based module loader for that matter), a certain amount of initialisation is required:

  • libltdl itself requires initialisation.
    1. libltdl should be told to use the same memory allocation routines used by the rest of Sic.
    2. Any preloaded modules (see section 18.4 dlpreopen Loading) need to be initialised with LTDL_SET_PRELOADED_SYMBOLS() .
    3. ltdl_init() must be called.
  • The module search path needs to be set. Here I allow the installer to specify a default search path to correspond with the installed Sic modules at compile time, but search the directories in the runtime environment variable `SIC_MODULES_PATH' first.
  • The internal error handling needs to be initialised.

Here is the start of the module loader, `sic/module.c' , including the initialisation code for libltdl:

 #if HAVE_CONFIG_H #  include <config.h> #endif #include "common.h" #include "builtin.h" #include "eval.h" #include "ltdl.h" #include "module.h" #include "sic.h" #ifndef SIC_MODULE_PATH_ENV #  define SIC_MODULE_PATH_ENV   "SIC_MODULE_PATH" #endif int module_init (void) {   static int initialised = 0;   int errors = 0;   /* Only perform the initialisation once. */   if (!initialised)     {       /* ltdl should use the same mallocation as us. */       lt_dlmalloc = (lt_ptr_t (*) (size_t)) xmalloc;       lt_dlfree = (void (*) (lt_ptr_t)) free;       /* Make sure preloaded modules are initialised. */       LTDL_SET_PRELOADED_SYMBOLS();       last_error = NULL;       /* Call ltdl initialisation function. */       errors = lt_dlinit();       /* Set up the module search directories. */       if (errors == 0)         {           const char *path = getenv (SIC_MODULE_PATH_ENV);           if (path != NULL)             errors = lt_dladdsearchdir(path);         }       if (errors == 0)         errors = lt_dladdsearchdir(MODULE_PATH);       if (errors != 0)         last_error = lt_dlerror ();       ++initialised;       return errors ? SIC_ERROR : SIC_OKAY;     }   last_error = multi_init_error;   return SIC_ERROR; } 

This document was generated by Gary V. Vaughan on May, 24 2001 using texi2html

GNU Autoconf, Automake and Libtool
GNU Autoconf, Automake, and Libtool
ISBN: 1578701902
EAN: 2147483647
Year: 2002
Pages: 290

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net