Skip to content

Commit

Permalink
Only store the module's module_t pointer in module_instance_t
Browse files Browse the repository at this point in the history
This reduces the number of dereferences and makes the code clearer
  • Loading branch information
arr2036 committed Dec 20, 2015
1 parent 3380fca commit d665d60
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 138 deletions.
6 changes: 3 additions & 3 deletions src/include/modpriv.h
Expand Up @@ -52,9 +52,9 @@ char const *lt_dlerror(void);
*/
typedef struct module_handle {
char const *name; //!< Name of the module e.g. sql.
module_t const *interface; //!< Symbol exported by the module, containing its public
module_t const *module; //!< Symbol exported by the module, containing its public
//!< functions, name and behaviour control flags.
lt_dlhandle dlhandle; //!< Handle returned by dlopen.
lt_dlhandle handle; //!< Handle returned by dlopen.
} module_dl_t;

typedef struct fr_module_hup_t fr_module_hup_t;
Expand All @@ -68,7 +68,7 @@ typedef struct fr_module_hup_t fr_module_hup_t;
typedef struct module_instance_t {
char const *name; //!< Instance name e.g. user_database.

module_dl_t *module; //!< Module this is an instance of.
module_t const *module; //!< Module this is an instance of.

void *data; //!< The module's private instance data, containing.
//!< its parsed configuration and static state.
Expand Down
18 changes: 5 additions & 13 deletions src/main/command.c
Expand Up @@ -847,7 +847,7 @@ static int command_hup(rad_listen_t *listener, int argc, char *argv[])
return CMD_FAIL;
}

if ((instance->module->interface->type & RLM_TYPE_HUP_SAFE) == 0) {
if ((instance->module->type & RLM_TYPE_HUP_SAFE) == 0) {
cprintf_error(listener, "Module %s cannot be hup'd\n",
argv[0]);
return CMD_FAIL;
Expand Down Expand Up @@ -1049,7 +1049,6 @@ static int command_show_module_methods(rad_listen_t *listener, int argc, char *a
int i;
CONF_SECTION *cs;
module_instance_t const *instance;
module_t const *mod;

if (argc != 1) {
cprintf_error(listener, "No module name was given\n");
Expand All @@ -1065,10 +1064,8 @@ static int command_show_module_methods(rad_listen_t *listener, int argc, char *a
return CMD_FAIL;
}

mod = instance->module->interface;

for (i = 0; i < MOD_COUNT; i++) {
if (mod->methods[i]) cprintf(listener, "%s\n", method_names[i]);
if (instance->module->methods[i]) cprintf(listener, "%s\n", method_names[i]);
}

return CMD_OK;
Expand All @@ -1079,7 +1076,6 @@ static int command_show_module_flags(rad_listen_t *listener, int argc, char *arg
{
CONF_SECTION *cs;
module_instance_t const *instance;
module_t const *mod;

if (argc != 1) {
cprintf_error(listener, "No module name was given\n");
Expand All @@ -1095,13 +1091,9 @@ static int command_show_module_flags(rad_listen_t *listener, int argc, char *arg
return CMD_FAIL;
}

mod = instance->module->interface;

if ((mod->type & RLM_TYPE_THREAD_UNSAFE) != 0)
cprintf(listener, "thread-unsafe\n");
if ((instance->module->type & RLM_TYPE_THREAD_UNSAFE) != 0) cprintf(listener, "thread-unsafe\n");

if ((mod->type & RLM_TYPE_HUP_SAFE) != 0)
cprintf(listener, "reload-on-hup\n");
if ((instance->module->type & RLM_TYPE_HUP_SAFE) != 0) cprintf(listener, "reload-on-hup\n");

return CMD_OK;
}
Expand Down Expand Up @@ -2370,7 +2362,7 @@ static int command_set_module_config(rad_listen_t *listener, int argc, char *arg
return 0;
}

if ((instance->module->interface->type & RLM_TYPE_HUP_SAFE) == 0) {
if ((instance->module->type & RLM_TYPE_HUP_SAFE) == 0) {
cprintf_error(listener, "Cannot change configuration of module as it is cannot be HUP'd.\n");
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/interpreter.c
Expand Up @@ -104,7 +104,7 @@ static rlm_rcode_t CC_HINT(nonnull) call_modsingle(rlm_components_t component, m
request->module = sp->modinst->name;

safe_lock(sp->modinst);
request->rcode = sp->modinst->module->interface->methods[component](sp->modinst->data, request);
request->rcode = sp->modinst->module->methods[component](sp->modinst->data, request);
safe_unlock(sp->modinst);

request->module = "";
Expand Down
2 changes: 1 addition & 1 deletion src/main/mainconfig.c
Expand Up @@ -1124,7 +1124,7 @@ static int hup_callback(void *ctx, void *data)
instance = module_find(modules, name);
if (!instance) return 0;

if ((instance->module->interface->type & RLM_TYPE_HUP_SAFE) == 0) return 0;
if ((instance->module->type & RLM_TYPE_HUP_SAFE) == 0) return 0;

if (!module_hup_module(instance->cs, instance, time(NULL))) return 0;

Expand Down
6 changes: 3 additions & 3 deletions src/main/modcall.c
Expand Up @@ -2519,8 +2519,8 @@ static modcallable *compile_csingle(modcallable *parent, rlm_components_t compon
* Check if the module in question has the necessary
* component.
*/
if (!this->module->interface->methods[component]) {
cf_log_err(ci, "\"%s\" modules aren't allowed in '%s' sections -- they have no such method.", this->module->interface->name,
if (!this->module->methods[component]) {
cf_log_err(ci, "\"%s\" modules aren't allowed in '%s' sections -- they have no such method.", this->module->name,
comp2str[component]);
return NULL;
}
Expand Down Expand Up @@ -2822,7 +2822,7 @@ static modcallable *compile_item(modcallable *parent, rlm_components_t component
*/
this = module_instantiate_method(modules, realname, &method);
if (this) {
*modname = this->module->interface->name;
*modname = this->module->name;
return compile_csingle(parent, method, ci, this, parent_grouptype, realname);
}

Expand Down

0 comments on commit d665d60

Please sign in to comment.