From 8bfdd08db3158dbb4075e661da3ac56ae6b75657 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Thu, 8 Aug 2002 02:08:10 +0000 Subject: [PATCH] Initialize and shut down libltdl. svn path=/trunk/yasm/; revision=664 --- frontends/yasm/yasm.c | 37 +++++++++++++++++++++++++++++++++++++ src/main.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/frontends/yasm/yasm.c b/frontends/yasm/yasm.c index 4a8b9600..cfa00b28 100644 --- a/frontends/yasm/yasm.c +++ b/frontends/yasm/yasm.c @@ -22,6 +22,8 @@ #include "util.h" /*@unused@*/ RCSID("$IdPath$"); +#include "ltdl.h" + #include "bitvect.h" #include "file.h" @@ -42,6 +44,11 @@ #include "arch.h" +/* Extra path to search for our modules. */ +#ifndef YASM_MODULE_PATH_ENV +# define YASM_MODULE_PATH_ENV "YASM_MODULE_PATH" +#endif + /* Preprocess-only buffer size */ #define PREPROC_BUF_SIZE 16384 @@ -114,6 +121,7 @@ main(int argc, char *argv[]) /*@null@*/ FILE *in = NULL, *obj = NULL; sectionhead *sections; size_t i; + int errors; #if defined(HAVE_SETLOCALE) && defined(HAVE_LC_MESSAGES) setlocale(LC_MESSAGES, ""); @@ -123,6 +131,32 @@ main(int argc, char *argv[]) #endif textdomain(PACKAGE); + /* Set libltdl malloc/free functions. */ +#ifdef DMALLOC + lt_dlmalloc = malloc; + lt_dlfree = free; +#else + lt_dlmalloc = xmalloc; + lt_dlfree = xfree; +#endif + + /* Initialize preloaded symbol lookup table. */ + LTDL_SET_PRELOADED_SYMBOLS(); + + /* Initialize libltdl. */ + errors = lt_dlinit(); + + /* Set up extra module search directories. */ + if (errors == 0) { + const char *path = getenv(YASM_MODULE_PATH_ENV); + if (path) + errors = lt_dladdsearchdir(path); + } + if (errors != 0) { + ErrorNow(_("Module loader initialization failed")); + return EXIT_FAILURE; + } + if (parse_cmdline(argc, argv, options, NELEMS(options))) return EXIT_FAILURE; @@ -347,6 +381,9 @@ cleanup(sectionhead *sections) intnum_shutdown(); BitVector_Shutdown(); + + /* Finish with libltdl. */ + lt_dlexit(); } /* diff --git a/src/main.c b/src/main.c index 4a8b9600..cfa00b28 100644 --- a/src/main.c +++ b/src/main.c @@ -22,6 +22,8 @@ #include "util.h" /*@unused@*/ RCSID("$IdPath$"); +#include "ltdl.h" + #include "bitvect.h" #include "file.h" @@ -42,6 +44,11 @@ #include "arch.h" +/* Extra path to search for our modules. */ +#ifndef YASM_MODULE_PATH_ENV +# define YASM_MODULE_PATH_ENV "YASM_MODULE_PATH" +#endif + /* Preprocess-only buffer size */ #define PREPROC_BUF_SIZE 16384 @@ -114,6 +121,7 @@ main(int argc, char *argv[]) /*@null@*/ FILE *in = NULL, *obj = NULL; sectionhead *sections; size_t i; + int errors; #if defined(HAVE_SETLOCALE) && defined(HAVE_LC_MESSAGES) setlocale(LC_MESSAGES, ""); @@ -123,6 +131,32 @@ main(int argc, char *argv[]) #endif textdomain(PACKAGE); + /* Set libltdl malloc/free functions. */ +#ifdef DMALLOC + lt_dlmalloc = malloc; + lt_dlfree = free; +#else + lt_dlmalloc = xmalloc; + lt_dlfree = xfree; +#endif + + /* Initialize preloaded symbol lookup table. */ + LTDL_SET_PRELOADED_SYMBOLS(); + + /* Initialize libltdl. */ + errors = lt_dlinit(); + + /* Set up extra module search directories. */ + if (errors == 0) { + const char *path = getenv(YASM_MODULE_PATH_ENV); + if (path) + errors = lt_dladdsearchdir(path); + } + if (errors != 0) { + ErrorNow(_("Module loader initialization failed")); + return EXIT_FAILURE; + } + if (parse_cmdline(argc, argv, options, NELEMS(options))) return EXIT_FAILURE; @@ -347,6 +381,9 @@ cleanup(sectionhead *sections) intnum_shutdown(); BitVector_Shutdown(); + + /* Finish with libltdl. */ + lt_dlexit(); } /*