perl-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stas Bekman <s...@stason.org>
Subject Re: DynaLoader's "special case"
Date Fri, 19 Nov 2004 20:41:53 GMT
Radoslaw Zielinski wrote:
> Each time I upgrade perl and the DynaLoader's version changes, I have to
> rebuild mod_perl, or I'll get this error:
>   DynaLoader object version 1.05 does not match $DynaLoader::VERSION 1.06
> 
> It happens when I add "PerlModule AnyXSmodule" to my httpd.conf (of
> course any more complicated thing, like adding a handler or a <perl>
> section also triggers it).  The module itself of course works just fine
> outside mod_perl.
> 
> I finally found some time to dig the issue; when I grepped out the
> 
>   src/modules/perl/modperl_xsinit.c:    /* DynaLoader is a special case */
> 
> line I knew I'm home... ;-)  The problematic call is:
> 
>   newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
> 
> It's triggered in mod_perl.c::modperl_xs_init(), for whatever reason.
> DynaLoader.pm contains:
> 
>   boot_DynaLoader('DynaLoader') if defined(&boot_DynaLoader) &&
>                                   !defined(&dl_error);
> 
> When I test it from the command line, the &dl_error is always defined,
> so I think on my system the condition is always false.
> 
> My question is: what's the point of that newXS() call?  Can it be done
> in any other way?

1) You need to have DynaLoader loaded before anything else, so you can 
load .so Perl extensions. That's why you see all those things. more 
explanation below.

2) DynaLoader.a is statically linked with mod_perl.so, therefore every 
time you upgrade perl you need to rebuild mod_perl (which is not the only 
reason).

--------

if you ever write an embedded perl app, which needs to load .pm files with 
.so extensions, you need to write:

#include <EXTERN.h>
#include <perl.h>

EXTERN_C void xs_init (pTHX);

EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);

EXTERN_C void
xs_init(pTHX)
{
        char *file = __FILE__;
        dXSUB_SYS;
        /* DynaLoader is a special case */
        newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
}
int main(int argc, char **argv, char **env)
{
[...]
     perl_construct(perl);
     perl_parse(one_perl, xs_init, 3, embedding, (char **)NULL);
     /* DynaLoader must be preloaded before perl_clone, if DynaLoader
      * is to be required later */
     eval_pv("require DynaLoader;", TRUE);

now you can continue loading other things.
See perlembed.pod for more info.

-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Mime
View raw message