commit 365972e5bc11cb5dfbba12cc0560a30a6f787941 Author: Nathaniel McCallum npmccallum@redhat.com Date: Mon Oct 10 10:40:06 2011 -0400
[core] make modules have unique table names
src/verto-module.h | 6 ++-- src/verto.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 62 insertions(+), 6 deletions(-) --- diff --git a/src/verto-module.h b/src/verto-module.h index 05a920f..243fb6b 100644 --- a/src/verto-module.h +++ b/src/verto-module.h @@ -30,7 +30,7 @@ #include <verto.h>
#define VERTO_MODULE_VERSION 1 -#define VERTO_MODULE_TABLE verto_module_table +#define VERTO_MODULE_TABLE(name) verto_module_table_ ## name #define VERTO_MODULE(name, symb, types) \ static verto_ctx_funcs name ## _funcs = { \ name ## _ctx_free, \ @@ -41,7 +41,7 @@ name ## _ctx_add, \ name ## _ctx_del \ }; \ - verto_module VERTO_MODULE_TABLE = { \ + verto_module VERTO_MODULE_TABLE(name) = { \ VERTO_MODULE_VERSION, \ # name, \ # symb, \ @@ -83,7 +83,7 @@ typedef struct { * @return A new _ev_ctx, or NULL on error. Call verto_free() when done. */ #define verto_convert(name, priv) \ - verto_convert_funcs(&name ## _funcs, &VERTO_MODULE_TABLE, priv) + verto_convert_funcs(&name ## _funcs, &VERTO_MODULE_TABLE(name), priv)
/** * Converts an existing implementation specific loop to a verto_ctx. diff --git a/src/verto.c b/src/verto.c index 34d453c..36a95ff 100644 --- a/src/verto.c +++ b/src/verto.c @@ -208,17 +208,69 @@ int_asprintf(char **strp, const char *fmt, ...) { return size; }
+static char * +int_get_table_name(const char *suffix) +{ + char *tmp; + + tmp = malloc(strlen(suffix) + strlen(__str(VERTO_MODULE_TABLE())) + 1); + if (tmp) { + strcpy(tmp, __str(VERTO_MODULE_TABLE())); + strcat(tmp, suffix); + } + return tmp; +} + +static char * +int_get_table_name_from_filename(const char *filename) +{ + char *bn = NULL, *tmp = NULL; + + if (!filename) + return NULL; + + tmp = strdup(filename); + if (!tmp) + return NULL; + + bn = basename(tmp); + if (bn) + bn = strdup(bn); + free(tmp); + if (!bn) + return NULL; + + tmp = strchr(bn, '-'); + if (tmp) { + if (strchr(tmp+1, '.')) { + *strchr(tmp+1, '.') = '\0'; + tmp = int_get_table_name(tmp + 1); + } else + tmp = NULL; + } + + free(bn); + return tmp; +} + static int do_load_file(const char *filename, int reqsym, verto_ev_type reqtypes, pdlmtype *dll, const verto_module **module) { + char *tblname; + + tblname = int_get_table_name_from_filename(filename); + if (!tblname) + return 0; + *dll = pdlopenl(filename); if (!*dll) { /* printf("%s -- %s\n", filename, pdlerror()); */ + free(tblname); return 0; }
- *module = (verto_module*) pdlsym(*dll, __str(VERTO_MODULE_TABLE)); + *module = (verto_module*) pdlsym(*dll, tblname); if (!*module || (*module)->vers != VERTO_MODULE_VERSION || !(*module)->new_ctx || !(*module)->def_ctx) goto error; @@ -233,17 +285,21 @@ do_load_file(const char *filename, int reqsym, verto_ev_type reqtypes,
/* Re-open in execution mode */ *dll = pdlreopen(filename, *dll); - if (!*dll) + if (!*dll) { + free(tblname); return 0; + }
/* Get the module struct again */ - *module = (verto_module*) pdlsym(*dll, __str(VERTO_MODULE_TABLE)); + *module = (verto_module*) pdlsym(*dll, tblname); if (!*module) goto error;
+ free(tblname); return 1;
error: + free(tblname); pdlclose(*dll); return 0; }
libverto-commits@lists.fedorahosted.org