Skip to main content

module_func

Function module_func 

Source
pub fn module_func(m: &module, name: &str) -> usize
Expand description

Port of module_func(Module m, const char *name) from Src/module.c:1770.

C body (DYNAMIC_NAME_CLASH_OK off — the typical case):

module_func(Module m, const char *name)
{
    VARARR(char, buf, strlen(name) + strlen(m->node.nam)*2 + 1);
    char const *p; char *q;
    strcpy(buf, name);
    q = strchr(buf, 0);
    for(p = m->node.nam; *p; p++) {
        if(*p == '/')      { *q++ = 'Q'; *q++ = 's'; }
        else if(*p == '_') { *q++ = 'Q'; *q++ = 'u'; }
        else if(*p == 'Q') { *q++ = 'Q'; *q++ = 'q'; }
        else                 *q++ = *p;
    }
    *q = 0;
    return (Module_generic_func) dlsym(m->u.handle, buf);
}

Builds a mangled symbol name (<name><module-name-mangled>) and dlsym’s it. The mangling encodes / as Qs, _ as Qu, Q as Qq so e.g. setup_zsh_random becomes setup_zshQurandom.

Static-link path: dlsym not used; returns 0 (NULL handle).