On Tue, 2 Oct 2001, Philippe M . Chiasson wrote:

> Hi, this patch implements the Apache->module() functionnality with a few differences.
> 
> Apache->module() is in Apache::compat and the real name for this is 
>Apache::Module::loaded()
> and I am open for better suggestions.  "if (Apache->module('Apache::Auth'))" doesn't 
>quite
> make as much sense to me than "if (Apache::Module::loaded('Apache::Auth'))"

name is fine.

> +
> +MP_INLINE module *modperl_get_ap_module(const char *name)
> +{
> +    module *modp;
> +    for (modp = ap_top_module; modp; modp = modp->next) {
> +        if (modp && modp->name && ( 0 == apr_strnatcmp(modp->name, name))) {
> +           return modp;
> +        }
> +    }
> +    return NULL;
> +}

why not just use ap_find_linked_module like 1.x does?

> +MP_INLINE int modperl_is_module_loaded(pTHX_ const char *name)
> +{
> +    return (NULL != gv_stashpv(name, FALSE));
> +}

this also needs to be as 1.x is, checking that the module exists in %INC

as for the malloc, we should avoid that.  see if you can work off
this..

#include <stdio.h>
#include <string.h>

int module_loaded(const char *module_name)
{
    char name[256]; /* should be plenty of space */
    const char *nameptr = name, *base;

    if ((base = strchr(module_name, '.'))) {
        int len = base - module_name;
        int shared;
 
        memcpy((void*)nameptr, module_name, len);
        memcpy((void*)nameptr + len, ".c\0", 3);

        fprintf(stderr, "cmodule name=%s\n", nameptr);
        /* if (!(modp = ap_find_linked_module(nameptr))) return 0; */

        shared = *(base + 1) == 'c' ? 0 : 1;

        if (shared) {
            fprintf(stderr, "checking for shared module\n");
            /* if (!modp->dynamic_load_handle) return 0; */
        }

        return 1;
    }


    fprintf(stderr, "perl module name=%s\n", module_name);
    /* if (modperl_perl_module_loaded(module_name) return 1; else */
    return 0;
}

static const char *modules[] = {
    "mod_perl.c", "mod_perl.so", "Apache::Status", NULL,
};

int main(int argc, char **argv, char **env)
{
    int i;
    for (i=0; modules[i]; i++) {
        module_loaded(modules[i]);
    }
    return 0;
}



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to