Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.97k stars 560 forks source link

use lib 'dir' does not also use 'dir/<archname>' #4604

Closed p5pRT closed 21 years ago

p5pRT commented 22 years ago

Migrated from rt.perl.org#7931 (status was 'resolved')

Searchable as RT7931$

p5pRT commented 22 years ago

From @jimav


The pod documentation in lib.pm says that​:

  use lib "dir" is supposed to also put dir/\ into @​INC if   dir/\/auto exists.

  no lib "dir" is supposed to remove dir and dir/\ from @​INC   if the directory dir/\/auto exists on the system.

The actual code behavior is different​:

  import() [code for "use lib"] looks for dir/\ and   dir/\/\ where \ is either the current perl version or   from Config{inc_version_list}\, and does not care whether there is an   auto subdirectory.

  unimport() [code "no lib"] works as documented\, i.e.\, removes dir/\   from @​INC if dir/\/auto exists in the system\, but it does not look   for any of the directories inserted by import().

Suggested fix (patch attached)​:

1. Make import() set up @​INC to contain the following dirs if the exist​:

  dir/\/\ (first in @​INC)   dir/\<any of inc_version_list>/\   dir/\   dir/\   dir/\<any of inc_version_list>   dir

2. Remove the remaining checks for /auto subdir from unimport()

3. Make unimport() remove the same 4 directories from @​INC\, without   checking to see if any exist on the system.

4. Fix the pod text.

Here is a patch which I think does that​:

Inline Patch ```diff --- /usr/lib/perl5/5.6.0/lib.pm Mon Jun 18 02:09:05 2001 +++ lib.pm Fri Nov 23 19:02:50 2001 @@ -4,7 +4,7 @@ use Config; my $archname = defined($Config{'archname'}) ? $Config{'archname'} : ''; -my $ver = defined($Config{'version'}) ? $Config{'version'} : ''; +my $version = defined($Config{'version'}) ? $Config{'version'} : ''; my @inc_version_list = defined($Config{'inc_version_list'}) ? reverse split / /, $Config{'inc_version_list'} : (); @@ -25,15 +25,20 @@ Carp::carp("Parameter to use lib must be directory, not file"); } unshift(@INC, $_); - # Add any previous version directories we found at configure time - foreach my $incver (@inc_version_list) + # Put any architecture- and/or version-specific dirs first + my @found_vers; + foreach my $ver (@inc_version_list, $version) { - unshift(@INC, "$_/$incver") if -d "$_/$incver"; + if (-d "$_/$ver") { + push @found_vers, $ver; # avoid repeated stat calls + unshift @INC, "$_/$ver"; + } + } + unshift(@INC, "$_/$archname") if -d "$_/$archname"; + foreach my $ver (@found_vers) + { + unshift(@INC, "$_/$ver/$archname") if -d "$_/$ver/$archname"; } - # Put a corresponding archlib directory infront of $_ if it - # looks like $_ has an archlib directory below it. - unshift(@INC, "$_/$ver") if -d "$_/$ver"; - unshift(@INC, "$_/$ver/$archname") if -d "$_/$ver/$archname"; } # remove trailing duplicates @@ -47,8 +52,15 @@ my %names; foreach (@_) { - ++$names{$_}; - ++$names{"$_/$archname"} if -d "$_/$archname/auto"; + ++$names{$_}; + foreach my $ver (@inc_version_list, $version) + { + if (-d "$_/$ver") { + ++$names{"$_/$ver"}; + ++$names{"$_/$ver/$archname"} if -d "$_/$ver/$archname"; + } + } + ++$names{"$_/$archname"} if -d "$_/$archname"; } # Remove ALL instances of each named directory. @@ -90,9 +102,13 @@ BEGIN { unshift(@INC, LIST) } For each directory in LIST (called $dir here) the lib module also -checks to see if a directory called $dir/$archname/auto exists. -If so the $dir/$archname directory is assumed to be a corresponding -architecture specific directory and is added to @INC in front of $dir. +checks for architecture- and perl-version-specific subdirectories and, +if they exist, puts them into @INC first: + + $dir/$version/$archname (appears first in @INC) + $dir/$archname + $dir/$version + $dir (appears last in @INC) To avoid memory leaks, all trailing duplicate entries in @INC are removed. @@ -108,10 +124,8 @@ The C statement deletes all instances of each named directory from @INC. -For each directory in LIST (called $dir here) the lib module also -checks to see if a directory called $dir/$archname/auto exists. -If so the $dir/$archname directory is assumed to be a corresponding -architecture specific directory and is also deleted from @INC. +In addition, the version- and architecture-specific subdirectory +names described above are also removed from @INC, if present. =head2 Restoring original @INC ----------------------------------------------------------------- --- ```

Flags:   category=library   severity=medium


Site configuration information for perl v5.6.0​:

Configured by root at Mon Jun 18 09​:01​:54 GMT 2001.

Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration​:   Platform​:   osname=linux\, osvers=2.4.3\, archname=i586-linux   uname='linux armstrong 2.4.3 #1 wed may 16 00​:37​:55 gmt 2001 i686 unknown '   config_args='-ds -e -Dprefix=/usr -Di_db -Di_dbm -Di_ndbm -Di_gdbm'   hint=recommended\, useposix=true\, d_sigaction=define   usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef   useperlio=undef d_sfio=undef uselargefiles=define   use64bitint=undef use64bitall=undef uselongdouble=undef usesocks=undef   Compiler​:   cc='cc'\, optimize='-O2 -pipe'\, gccversion=2.95.3 20010315 (SuSE)   cppflags='-fno-strict-aliasing -I/usr/local/include'   ccflags ='-fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'   stdchar='char'\, d_stdstdio=define\, usevfork=false   intsize=4\, longsize=4\, ptrsize=4\, doublesize=8   d_longlong=define\, longlongsize=8\, d_longdbl=define\, longdblsize=12   ivtype='long'\, ivsize=4\, nvtype='double'\, nvsize=8\, Off_t='off_t'\, lseeksize=8   alignbytes=4\, usemymalloc=n\, prototype=define   Linker and Libraries​:   ld='cc'\, ldflags =' -L/usr/local/lib'   libpth=/usr/local/lib /lib /usr/lib   libs=-lnsl -ldl -lm -lc -lcrypt   libc=\, so=so\, useshrplib=false\, libperl=libperl.a   Dynamic Linking​:   dlsrc=dl_dlopen.xs\, dlext=so\, d_dlsymun=undef\, ccdlflags='-rdynamic'   cccdlflags='-fpic'\, lddlflags='-shared -L/usr/local/lib'

Locally applied patches​:  


@​INC for perl v5.6.0​:   /usr/lib/perl5/5.6.0/i586-linux   /usr/lib/perl5/5.6.0   /usr/lib/perl5/site_perl/5.6.0/i586-linux   /usr/lib/perl5/site_perl/5.6.0   /usr/lib/perl5/site_perl   .


Environment for perl v5.6.0​:   HOME=/home/jima   LANG=en_US   LANGUAGE (unset)   LC_COLLATE=POSIX   LD_LIBRARY_PATH (unset)   LOGDIR (unset)   PATH=/home/jima/bin​:/usr/local/bin​:/usr/bin​:/usr/X11R6/bin​:/bin​:/usr/lib/java/bin​:/var/lib/dosemu​:/usr/games/bin​:/usr/games​:/opt/bin​:/opt/gnome/bin​:/opt/kde2/bin​:/opt/kde/bin​:/usr/openwin/bin​:.​:/opt/pilotsdk/bin​:/opt/jima/bin​:/usr/sbin​:/sbin   PERL_BADLANG (unset)   SHELL=/bin/bash

p5pRT commented 22 years ago

From [Unknown Contact. See original ticket]

Moin\,

you wrote​:

use lib "dir" is supposed to also put dir/\ into @​INC if dir/\/auto exists.

no lib "dir" is supposed to remove dir and dir/\ from @​INC if the directory dir/\/auto exists on the system.

The actual code behavior is different​:

import() [code for "use lib"] looks for dir/\ and dir/\/\ where \ is either the current perl version or from Config{inc_version_list}\, and does not care whether there is an auto subdirectory.

unimport() [code "no lib"] works as documented\, i.e.\, removes dir/\ from @​INC if dir/\/auto exists in the system\, but it does not look for any of the directories inserted by import().

Suggested fix (patch attached)​:

1. Make import() set up @​INC to contain the following dirs if the exist​:

   dir/\<version>/\<archname>  \(first in @&#8203;INC\)
   dir/\<any of inc\_version\_list>/\<archname>
   dir/\<archname>
   dir/\<version>
   dir/\<any of inc\_version\_list>
   dir

Iif I read this correctly\,

  use lib 'lib';

would put 'lib' at the 6th place into @​INC\, but the dir/\/\ comes first\, which means that a script like this​:

  lib/Math/BigInt.pm # v1.47   test.pl

and test.pl is​:

  use lib 'lib';   use Math​::BigInt;

  print $Math​::BigInt​::VERSION\,"\n";

will print whatever version is installed of Math​::BigInt\, not the one that isin lib/Math/. This will break things greatly (or read​: a lot of my scripts) and generally be a pain in the lower uhm regions\, because then you would have no longer a way to pick up the local libraries first (that is\, without doing unshift 'lib'\, @​INC; which use lib 'lib' was to avoid in the first place - or so I thought.)

Uhm? Do I miss something?

Cheers\,

Tels

- -- perl -MDev​::Bollocks -e'print Dev​::Bollocks->rand()\,"\n"' administratively grow enterprise infrastructures

http​://bloodgate.com/perl My current Perl projects PGP key available on http​://bloodgate.com/tels.asc or via email

-----BEGIN PGP SIGNATURE----- Version​: 2.6.3i Charset​: latin1

iQEVAwUBO/9iQHcLPEOTuEwVAQFCjwf+NOCNFhjYmkx/GrhZpvf4YI6nGLggOCvH upmWs+J5MyFzccQLQvtDn8U224u1j7tUcK4y5x/2/dZGgUj25nzDwDUa3T88MCU6 xx5ht5FeFjQilWhS66+30po2WSLh6KOlzPcD+hAaPC5Thi/t5SX5DqnFPtwCAaYW VGnCdDGjE1eFNQldvx8pn8yCFR2eMJYTnumZJn8Ei1Ijwe0bSkW9tMPpgoHhv7Fi uCB+PQU16kRYYZxa1EO72hh8yGd2z0vAjUt8fe6QftQSH3bHgGypvGnkbIUdR1Ec UfVuBta4uphNm5JJihs3CEz1Z2e2pat715foqnzvkJA2Wd2s05KUSw== =VQTY -----END PGP SIGNATURE-----

p5pRT commented 22 years ago

From @doughera88

This is a bug report for perl from james_avera@​yahoo.com\, generated with the help of perlbug 1.28 running under perl v5.6.0.

The pod documentation in lib.pm says that​:

use lib "dir" is supposed to also put dir/\ into @​INC if dir/\/auto exists.

no lib "dir" is supposed to remove dir and dir/\ from @​INC if the directory dir/\/auto exists on the system.

The actual code behavior is different​:

This was fixed in perl-5.6.1\, which was released in April\, 2001. Could you please check if the version included in perl-5.6.1 does what you need it to do? (Also note that 5.6.1 correctly updated perl.c to do the same auto-searching for -I directives.)

Thanks\,

  Andy Dougherty doughera@​lafayette.edu   Dept. of Physics   Lafayette College\, Easton PA 18042

p5pRT commented 21 years ago

@doughera88 - Status changed from 'open' to 'resolved'