You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Gordon Lack <gm...@ggr.co.uk> on 2005/02/07 17:08:38 UTC

[mp1] PERL5LIB handled backwards (mod_perl 1.27+)

   The Changes file notes:

> PERL5LIB support now properly unshifts paths into @INC rather than push

(added in 1.27)

   While it now does unshift rather than push (so the entries end up at
the front of @INC, not the back) it does so backwards!

  eg:

 PerlPassEnv PERL5LIB /dir1:/dir2:/dir3

will end up setting @INC to:

 /dir3
 /dir2
 /dir1
 <pr...@INC>

(you can see this via Apache::Status)


Re: [mp1] PERL5LIB handled backwards (mod_perl 1.27+)

Posted by Stas Bekman <st...@stason.org>.
Stas Bekman wrote:
> Gordon Lack wrote:
> 
>> Gordon Lack wrote:
>>
>>>>>   While it now does unshift rather than push (so the entries end up at
>>>>> the front of @INC, not the back) it does so backwards!
>>>>>
>>>>>  eg:
>>>>>
>>>>> PerlPassEnv PERL5LIB /dir1:/dir2:/dir3

I've added a reference to this suggestion into the STATUS file. So whoever 
is going to work on the release of the next version of mp1 will test and 
merge it. Thanks Gordon.


-- 
__________________________________________________________________
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

Re: [mp1] PERL5LIB handled backwards (mod_perl 1.27+)

Posted by Stas Bekman <st...@stason.org>.
Gordon Lack wrote:
> Gordon Lack wrote:
> 
>>>>   While it now does unshift rather than push (so the entries end up at
>>>>the front of @INC, not the back) it does so backwards!
>>>>
>>>>  eg:
>>>>
>>>> PerlPassEnv PERL5LIB /dir1:/dir2:/dir3
>>>
>>>You mean, PerlSetEnv, don't you? PerlPassEnv doesn't accept values.
>>
>>   Yes, I did - but you get the idea :-).
> 
> 
>    Related bug.

>    Using PERL5LIB in this way does not add architecture-specific
> sub-dirs to @INC (which setting PERL5LIB in the environment does do).

why not fixing that too? should be as easy as copying the relevant bits of 
code from the perl source (just grep for PERL5LIB).

>    Suggested fix:
> 
>   Document the use of:
> 
> <Perl>
>    use lib qw( /dir1 /dir2 /dir3 );
> /Perl>
> 
> instead if you wish to affect mod_perl, or just use SetEnv if you just
> want to affect CGI (but those scripts *should* be using use lib
> themselves....IMHO).


-- 
__________________________________________________________________
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

Re: [mp1] PERL5LIB handled backwards (mod_perl 1.27+)

Posted by Gordon Lack <gm...@ggr.co.uk>.
Gordon Lack wrote:
> 
> > >    While it now does unshift rather than push (so the entries end up at
> > > the front of @INC, not the back) it does so backwards!
> > >
> > >   eg:
> > >
> > >  PerlPassEnv PERL5LIB /dir1:/dir2:/dir3
> >
> > You mean, PerlSetEnv, don't you? PerlPassEnv doesn't accept values.
> 
>    Yes, I did - but you get the idea :-).

   Related bug.

   Using PERL5LIB in this way does not add architecture-specific
sub-dirs to @INC (which setting PERL5LIB in the environment does do).

   Suggested fix:

  Document the use of:

<Perl>
   use lib qw( /dir1 /dir2 /dir3 );
/Perl>

instead if you wish to affect mod_perl, or just use SetEnv if you just
want to affect CGI (but those scripts *should* be using use lib
themselves....IMHO).


Re: [mp1] PERL5LIB handled backwards (mod_perl 1.27+)

Posted by Gordon Lack <gm...@ggr.co.uk>.
> >    While it now does unshift rather than push (so the entries end up at
> > the front of @INC, not the back) it does so backwards!
> >
> >   eg:
> >
> >  PerlPassEnv PERL5LIB /dir1:/dir2:/dir3
> 
> You mean, PerlSetEnv, don't you? PerlPassEnv doesn't accept values.

   Yes, I did - but you get the idea :-).

> Sounds right. Did you forget to attach the patch? :)

   No, I hadn't written it at the time.  But I have now.

> Though I'm not sure how sensitive that change is. I mean someone who have
> been relying on the current implementation might get bitten by this change.

   The same could have been said of the fix at 1.27.


   Anyway, here is a fix.  rather than a patch it's the entire code of
the small perl_inc_unshift() function in src/modules/perl/perl_util.c
(line 789pp).

   I've tested the loop logic, but not actually put this into a runnign
mod_perl.  So I've only copied the perl logic (the newSV(), sv_setpvn(),
av_unshift() and av_store() calls) from the current code.  Also, I'm not
sure what should happen to an empty PERL5LIB setting or empty parts.  By
dfault the code will add empty variables - if this is wrong just add in
the code by activating the relevant ifdefs (and remove the ifdef
sections which aren't needed).




src/modules/perl/perl_util.c: 789



void perl_inc_unshift(char *p)
{
    char *wp, *ep;

    if(!p) return;

#ifdef IGNORE_EMPTY_PERL5LIB
    if (!*p) return;
#endif

    wp = p + strlen(p);  /* Points at terminating null */
    ep = wp - 1;         /* Points at final non-null */

    while (wp >= p) {
        SV *libdir = newSV(0);
        while(!((--wp == p-1) || (*wp == PERLLIB_SEP)));
#ifdef IGNORE_EMPTY_PERL5LIB_PARTS
        if (ep == wp) {
            ep=wp-1;
            continue;
        }
#endif
        sv_setpvn(libdir, wp+1, (STRLEN)(ep-wp));
        av_unshift(GvAV(incgv), 1);
        av_store(GvAV(incgv), 0, libdir);
        ep=wp-1;
    }
}


Re: [mp1] PERL5LIB handled backwards (mod_perl 1.27+)

Posted by Stas Bekman <st...@stason.org>.
[when starting a new thread, please do *not* reply to a previous thread]

Gordon Lack wrote:
>    The Changes file notes:
> 
> 
>>PERL5LIB support now properly unshifts paths into @INC rather than push
> 
> 
> (added in 1.27)
> 
>    While it now does unshift rather than push (so the entries end up at
> the front of @INC, not the back) it does so backwards!
> 
>   eg:
> 
>  PerlPassEnv PERL5LIB /dir1:/dir2:/dir3

You mean, PerlSetEnv, don't you? PerlPassEnv doesn't accept values.

> will end up setting @INC to:
> 
>  /dir3
>  /dir2
>  /dir1
>  <pr...@INC>
> 
> (you can see this via Apache::Status)

Sounds right. Did you forget to attach the patch? :)

Though I'm not sure how sensitive that change is. I mean someone who have 
been relying on the current implementation might get bitten by this change.

-- 
__________________________________________________________________
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