From 8a9f3151962c17e0d886475bdaa5964540a83fe7 Mon Sep 17 00:00:00 2001 From: Rick Bird Date: Mon, 18 Apr 2011 18:27:05 -0400 Subject: [PATCH] Mucked with Module function calling Macros for ISO C compliance & generaly prettiness. ISO C IssueID #238 --- hdrs/modules.h | 9 +++------ src/bsd.c | 2 -- src/modules.c | 8 ++------ src/utils.c | 8 ++------ 4 files changed, 7 insertions(+), 20 deletions(-) diff --git a/hdrs/modules.h b/hdrs/modules.h index f95a979..d4b5500 100644 --- a/hdrs/modules.h +++ b/hdrs/modules.h @@ -19,7 +19,6 @@ int module_open(char *path, char *name); int module_close(struct module_entry_t *m); int modules_shutdown(void); -extern void *module_utility_fptr; /* This gets us through the ISO C warnings about our POSIX compliance macros */ /* Iterate through Module List */ #define MODULE_ITER(m) for(m = module_list ; m != NULL ; m = m->next) @@ -29,19 +28,17 @@ extern void *module_utility_fptr; /* This gets us through the ISO C warnings abo /* Retrieve Module Function */ /* This Macro can only be used for non-returning calls */ #define MODULE_FUNC(h, m, func, ...) \ - module_utility_fptr = lt_dlsym(m, func); \ - memcpy(&h, &module_utility_fptr, sizeof(module_utility_fptr)); \ + *((void **) (&h)) = lt_dlsym(m, func); \ if(h) { \ h(__VA_ARGS__); \ } #define MODULE_FUNC_NOARGS(h, m, func) \ - module_utility_fptr = lt_dlsym(m, func); \ - memcpy(&h, &module_utility_fptr, sizeof(module_utility_fptr)); \ + *((void **) (&h)) = lt_dlsym(m, func); \ if(h) { \ h(); \ } -#define MODULE_FUNCRET(m, func) lt_dlsym(m, func) +#define MODULE_FUNCRET(var, m, func) *((void **) (&var)) = lt_dlsym(m, func) #endif /* _MODULES_H_ */ diff --git a/src/bsd.c b/src/bsd.c index 1dee0be..59ea2d3 100644 --- a/src/bsd.c +++ b/src/bsd.c @@ -1043,8 +1043,6 @@ shovechars(Port_t port, Port_t sslport __attribute__ ((__unused__))) #ifdef COMPILE_CONSOLE d = initializesock(0, "localhost", "127.0.0.1", 0); - if (2 >= maxd) - maxd = 3; #else if (!restarting) { sock = make_socket(port, SOCK_STREAM, NULL, NULL, MUSH_IP_ADDR); diff --git a/src/modules.c b/src/modules.c index ff2a0ec..a687103 100644 --- a/src/modules.c +++ b/src/modules.c @@ -23,7 +23,6 @@ struct module_entry_t *module_list = NULL; /* Function utility pointer for module system macros. * This gets us through the ISO C warnings about our posix compliance issues. **/ -void *module_utility_fptr; /* Ads a module entry and returns */ struct module_entry_t *module_entry_add(char *name) { @@ -93,9 +92,7 @@ int module_open(char *path, char *name) { } /* Some OSes may need symbols to be prefixed with _.. Will need to look into autoconfig code for this */ - /* FIXME: This is hideous, but ISO C prohibits casting from an object pointer - * to a function pointer and lt_dlsym() returns void *. */ - *((void **) (&module_loader)) = MODULE_FUNCRET(handle, "module_load"); + MODULE_FUNCRET(module_loader, handle, "module_load"); if(!module_loader) { do_rawlog(LT_ERR, "Error Loading Module: Could not call module_load | %s", file); @@ -109,8 +106,7 @@ int module_open(char *path, char *name) { } module->handle = handle; module->load = module_loader; - /* FIXME: See comment above. */ - *((void **) (&module->unload)) = MODULE_FUNCRET(handle, "module_unload"); + MODULE_FUNCRET(module->unload, handle, "module_unload"); /* Grab info and version from module & put it in */ /* Success.. Call the module */ diff --git a/src/utils.c b/src/utils.c index 2f3dfaf..148f934 100644 --- a/src/utils.c +++ b/src/utils.c @@ -889,9 +889,7 @@ can_interact(dbref from, dbref to, int type) /* This function can override standard checks! */ /* This doohicky is the replacement for local_can_interact_first */ MODULE_ITER(m) { - /* FIXME: This is hideous but is required because ISO C prohibits assignment - * from void * to a function pointer. */ - *((void **) &handle) = MODULE_FUNCRET(m->handle, "module_can_interact_first"); + MODULE_FUNCRET(handle, m->handle, "module_can_interact_first"); if (handle) { if ((lci = handle(from, to , type)) != NOTHING) return lci; @@ -915,9 +913,7 @@ can_interact(dbref from, dbref to, int type) return 1; MODULE_ITER(m) { - /* TODO: This is required because ISO C prohibits assignment from void * - * to function pointer. */ - *((void **) &handle) = MODULE_FUNCRET(m->handle, "module_can_interact_last"); + MODULE_FUNCRET(handle, m->handle, "module_can_interact_last"); if (handle) { if ((lci = handle(from, to , type)) != NOTHING) return lci; -- 2.30.2