Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 8a1abe39 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

Corrections in reg_pick

parent 0739a4ff
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!92Mod
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include <lektor/config.h> #include <lektor/config.h>
#include <lektor/database.h> #include <lektor/database.h>
#include <lektor/net.h> #include <lektor/net.h>
#include <lektor/reg.h>
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
...@@ -121,23 +123,13 @@ load_so(const char *const mod_path, const char *const mod_init, void *mod, struc ...@@ -121,23 +123,13 @@ load_so(const char *const mod_path, const char *const mod_init, void *mod, struc
Uppon successfull completion, the function shall return 0, and return Uppon successfull completion, the function shall return 0, and return
a non zero value if something bad happened. */ a non zero value if something bad happened. */
int (*module_set_function)(void *const, struct lkt_state *, void *const); int (*module_set_function)(void *const, struct lkt_state *, void *const);
char *error; void *handle = NULL;
void *handle = dlopen(mod_path, RTLD_NOW); *(void **) (&module_set_function) = reg_pick(mod_path, &handle, mod_init);
if (NULL == handle) {
LOG_ERROR("libdl error in dlopen on file '%s': %s", mod_path, dlerror());
return 1;
}
dlerror();
*(void **) (&module_set_function) = dlsym(handle, mod_init);
if ((error = dlerror()) != NULL) {
LOG_ERROR("libdl error in dlsym on file '%s': %s\n", mod_path, error);
return 1;
}
if (module_set_function)
return ! module_set_function(mod, srv, handle); return ! module_set_function(mod, srv, handle);
else
return 1;
} }
inline int inline int
......
...@@ -12,13 +12,15 @@ struct module_reg *reg; ...@@ -12,13 +12,15 @@ struct module_reg *reg;
void * void *
reg_pick(const char *file, void **handle, const char *symbol) reg_pick(const char *file, void **handle, const char *symbol)
{ {
int i;
if (!symbol) if (!symbol)
return NULL; return NULL;
/* Use the register instead of dlfcn? */
if (!file || STR_MATCH(file, "STATIC") || handle == NULL)
goto use_reg;
/* Use dlsym */ /* Use dlsym */
if (handle) {
if (!file)
return NULL;
char *error; char *error;
*handle = dlopen(file, RTLD_NOW); *handle = dlopen(file, RTLD_NOW);
...@@ -28,7 +30,7 @@ reg_pick(const char *file, void **handle, const char *symbol) ...@@ -28,7 +30,7 @@ reg_pick(const char *file, void **handle, const char *symbol)
} }
dlerror(); dlerror();
void *sym = dlsym(handle, symbol); void *sym = dlsym(*handle, symbol);
if ((error = dlerror()) != NULL) { if ((error = dlerror()) != NULL) {
LOG_ERROR("libdl error in dlsym on file '%s': %s\n", file, error); LOG_ERROR("libdl error in dlsym on file '%s': %s\n", file, error);
...@@ -36,11 +38,9 @@ reg_pick(const char *file, void **handle, const char *symbol) ...@@ -36,11 +38,9 @@ reg_pick(const char *file, void **handle, const char *symbol)
} }
return sym; return sym;
}
/* Read the reg */ /* Read the reg */
else { use_reg:
int i;
for (i = 0; reg[i].name && reg[i].func && !STR_MATCH(reg[i].name, symbol); ++i) for (i = 0; reg[i].name && reg[i].func && !STR_MATCH(reg[i].name, symbol); ++i)
continue; continue;
...@@ -49,7 +49,6 @@ reg_pick(const char *file, void **handle, const char *symbol) ...@@ -49,7 +49,6 @@ reg_pick(const char *file, void **handle, const char *symbol)
else else
return NULL; return NULL;
} }
}
void void
reg_set(struct module_reg *_reg) reg_set(struct module_reg *_reg)
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter