diff options
author | npmccallum <npmccallum@c587cffe-e639-0410-9787-d7902ae8ed56> | 2010-02-14 00:13:51 +0000 |
---|---|---|
committer | npmccallum <npmccallum@c587cffe-e639-0410-9787-d7902ae8ed56> | 2010-02-14 00:13:51 +0000 |
commit | 0d32831d59d0e689c55964f43564db2cfef30a4b (patch) | |
tree | e1d4dc75b5be91e21586dc273fdd6ed12c8b3b4f /libmodman | |
parent | 79ec18bc210cb6d1823ccb51229959bcccd50af3 (diff) | |
download | libproxy-git-0d32831d59d0e689c55964f43564db2cfef30a4b.tar.gz |
implement lazy loading
Diffstat (limited to 'libmodman')
-rw-r--r-- | libmodman/module_manager.cpp | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/libmodman/module_manager.cpp b/libmodman/module_manager.cpp index f959105..fe594c1 100644 --- a/libmodman/module_manager.cpp +++ b/libmodman/module_manager.cpp @@ -35,9 +35,14 @@ using namespace libmodman; #ifdef WIN32 #define pdlmtype HMODULE -#define pdlopen(filename) LoadLibrary(filename) +#define pdlopenl(filename) LoadLibraryEx(filename, NULL, DONT_RESOLVE_DLL_REFERENCES) #define pdlsym GetProcAddress #define pdlclose(module) FreeLibrary((pdlmtype) module) +static pdlmtype pdlreopen(const char* filename, pdlmtype module) { + pdlclose(module); + return LoadLibrary(filename); +} + static string pdlerror() { std::string e; LPTSTR msg; @@ -61,9 +66,10 @@ static bool pdlsymlinked(const char* modn, const char* symb) { } #else #define pdlmtype void* -#define pdlopen(filename) dlopen(filename, RTLD_LAZY | RTLD_LOCAL) +#define pdlopenl(filename) dlopen(filename, RTLD_LAZY | RTLD_LOCAL) #define pdlsym dlsym #define pdlclose(module) dlclose((pdlmtype) module) +#define pdlreopen(filename, module) module static string pdlerror() { return dlerror(); @@ -97,15 +103,6 @@ module_manager::~module_manager() { pdlclose(*i); this->modules.clear(); } -/* -bool module_manager::load_module(module* mi) { - const char* debug = getenv("_MM_DEBUG"); - bool loaded = false; - for (unsigned int i=0 ; mi[i].vers == MM_MODULE_VERSION && mi[i].type && mi[i].init ; i++) { - - } - return loaded; -}*/ bool module_manager::load_file(string filename, bool symbreq) { const char* debug = getenv("_MM_DEBUG"); @@ -119,7 +116,9 @@ bool module_manager::load_file(string filename, bool symbreq) { cerr << "loading : " << filename << "\r"; // Open the module - pdlmtype dlobj = pdlopen(filename.c_str()); + bool lazy = true; + pdlmtype dlobj = pdlopenl(filename.c_str()); +loadfull: if (!dlobj) { if (debug) cerr << "failed!" << endl @@ -136,12 +135,12 @@ bool module_manager::load_file(string filename, bool symbreq) { } // Get the module info - const unsigned int* vers = (unsigned int*) pdlsym(dlobj, __str(MM_MODULE_VARNAME(vers))); + const unsigned int* vers = (unsigned int*) pdlsym(dlobj, __str(MM_MODULE_VARNAME(vers))); const char* const (**type)() = (const char* const (**)()) pdlsym(dlobj, __str(MM_MODULE_VARNAME(type))); base_extension** (**init)() = (base_extension** (**)()) pdlsym(dlobj, __str(MM_MODULE_VARNAME(init))); bool (**test)() = (bool (**)()) pdlsym(dlobj, __str(MM_MODULE_VARNAME(test))); - const char** const symb = (const char** const) pdlsym(dlobj, __str(MM_MODULE_VARNAME(symb))); - const char** const smod = (const char** const) pdlsym(dlobj, __str(MM_MODULE_VARNAME(smod))); + const char** const symb = (const char** const) pdlsym(dlobj, __str(MM_MODULE_VARNAME(symb))); + const char** const smod = (const char** const) pdlsym(dlobj, __str(MM_MODULE_VARNAME(smod))); if (!vers || !type || !init || !*type || !*init || *vers != MM_MODULE_VERSION) { if (debug) cerr << "failed!" << endl @@ -193,6 +192,12 @@ bool module_manager::load_file(string filename, bool symbreq) { } } + if (lazy) { + dlobj = pdlreopen(filename.c_str(), dlobj); + lazy = false; + goto loadfull; + } + // If our execution test succeeds, call init() if ((test && *test && (*test)()) || !test || !*test) { base_extension** extensions = (*init)(); |