Perl / perl5

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

No subject provided #4009

Closed p5pRT closed 20 years ago

p5pRT commented 23 years ago

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

Searchable as RT7019$

p5pRT commented 23 years ago

From mstevens@globnix.org


[Please enter your report here]

I'm getting the following error running make test on bleadperl​:

michaels@​orbit​:\~/perl-current> ./perl -Ilib t/lib/b-stash.t Can't declare another package's variables at t/lib/b-stash.t line 42 BEGIN failed--compilation aborted at t/lib/b-stash.t line 42.

The version info is​:

Summary of my perl5 (revision 5.0 version 7 subversion 1) configuration​:   Platform​:   osname=linux\, osvers=2.4.4\, archname=i686-linux   uname='linux orbit.iii.co.uk 2.4.4 #1 mon apr 30 14​:23​:17 bst 2001 i686 unknown '   config_args='-des -Dusedevel'   hint=recommended\, useposix=true\, d_sigaction=define   usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef   useperlio=define d_sfio=undef uselargefiles=define usesocks=undef   use64bitint=undef use64bitall=undef uselongdouble=undef   Compiler​:   cc='cc'\, ccflags ='-fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'\,   optimize='-O2'\,   cppflags='-fno-strict-aliasing -I/usr/local/include'   ccversion=''\, gccversion='2.95.2 20000220 (Debian GNU/Linux)'\, gccosandvers=''   intsize=4\, longsize=4\, ptrsize=4\, doublesize=8\, byteorder=1234   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 -lndbm -ldb -ldl -lm -lc -lposix -lcrypt -lutil   perllibs=-lnsl -ldl -lm -lc -lposix -lcrypt -lutil   libc=/lib/libc-2.1.3.so\, 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'

Characteristics of this binary (from libperl)​:   Compile-time options​: USE_LARGE_FILES   Locally applied patches​:   DEVEL10155   Built under linux   Compiled at May 21 2001 11​:19​:00   @​INC​:   lib   /usr/local/lib/perl5/5.7.1/i686-linux   /usr/local/lib/perl5/5.7.1   /usr/local/lib/perl5/site_perl/5.7.1/i686-linux   /usr/local/lib/perl5/site_perl/5.7.1   /usr/local/lib/perl5/site_perl/5.6.1/i686-linux   /usr/local/lib/perl5/site_perl/5.6.1   /usr/local/lib/perl5/site_perl/5.6.0/i686-linux   /usr/local/lib/perl5/site_perl/5.6.0   /usr/local/lib/perl5/site_perl   .

Michael

p5pRT commented 23 years ago

From @schwern

If this is the line...

  42 if (($Config{static_ext} eq ' ' ||   43 ($Config{static_ext} eq 'Socket' && $Is_VMS))   44 && !($^O eq 'os2' and $OS2​::is_aout)   45 ) {

Then its probably tripping over the $OS2​::is_aout. I don't have a copy of bleadperl compiled at the moment\, working on it. Interestingly enough\, that error message comes from vars.pm.

p5pRT commented 23 years ago

From [Unknown Contact. See original ticket]

Line 42 in my copy is​:

use vars qw($OS2​::is_aout);

Michael

p5pRT commented 23 years ago

From @schwern

Well\, that's the problem. Seems to have already been fixed\, though. Grab the next patch and give a yell.

p5pRT commented 23 years ago

From [Unknown Contact. See original ticket]

Just rsynced again\, no change.

.patch says 10172\, patchlevel.h says DEVEL10155.

What patch do we think fixed it?

Michael

p5pRT commented 23 years ago

From @schwern

The one that exists only in my small\, happy little world.

Seems that 'use vars' was plopped in to shut up a warning. Hmmm... where does that magic little $OS2​::is_aout spring from anyway?

Here's a quick little patch to clear up the error\, but I'd still like to know where that variable comes from. README.os2 lists some "prebuilt" variables that look like they should go into %Configure or a real OS2.pm instead. ETOOMAGICAL.

--- t/lib/b-stash.t 2001/05/21 11​:33​:31 1.1 +++ t/lib/b-stash.t 2001/05/21 11​:39​:08 @​@​ -17\,7 +17\,7 @​@​

sub ok { print "ok $test\n"; $test++ }

- +() = $OS2​::is_aout; # shut up a 'variable used only once' warning my $a; my $Is_VMS = $^O eq 'VMS'; my $Is_MacOS = $^O eq 'MacOS'; @​@​ -39\,7 +39\,6 @​@​   $a =~ s/-uVMS\,-uVMS​::Filespec\,//;   $a =~ s/-uSocket\,//; # Socket is optional/compiler version dependent } -use vars qw($OS2​::is_aout); if (($Config{static_ext} eq ' ' ||   ($Config{static_ext} eq 'Socket' && $Is_VMS))   && !($^O eq 'os2' and $OS2​::is_aout)

p5pRT commented 23 years ago

From @jhi

Already fixed in my little copy (not yet synced back to the repository\, though...)

p5pRT commented 23 years ago

From [Unknown Contact. See original ticket]

And also\, any such "prebuilt" variables should be flagged as "already seen" so that you don't get "used once" errors\, as already happens for\, e.g. %ENV.

Mike Guy

p5pRT commented 23 years ago

From @jhi

Yeah\, $Config{OS2_xxx} would be nicer.

a real OS2.pm instead. ETOOMAGICAL.

And also\, any such "prebuilt" variables should be flagged as "already seen" so that you don't get "used once" errors\, as already happens for\, e.g. %ENV.

Mike Guy

p5pRT commented 23 years ago

From [Unknown Contact. See original ticket]

This is what OS/2 port is doing. Do you want this to be done with $OS2​::is_omf on other platforms too? ;-)

Hmm\, an interesting solution may be to have it in $^O{is_aout} etc.\, and mark %^O as used-already everywhere...

Ilya

p5pRT commented 23 years ago

From [Unknown Contact. See original ticket]

It has long been a pet hate of mine that one has to write circumlocutions like

  { package DB; use vars '$single' };

in order to avoid "used once" warnings. And the restriction in vars.pm is entirely undocumented.

So here's a patch (for bleadperl) to vars.pm to support qualified variables. And also a test suite for vars.pm since there wasn't one.

And before people start shouting "But 'use vars' is obsolete"\, note that this case is not supported by "our"\, and Larry has decreed that it never will be.

Mike Guy

Inline Patch ```diff --- ./t/pragma/vars.t.orig Mon May 21 13:46:24 2001 +++ ./t/pragma/vars.t Tue May 22 12:23:39 2001 @@ -0,0 +1,105 @@ +#!./perl + +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; + $ENV{PERL5LIB} = '../lib'; +} + +$| = 1; + +print "1..27\n"; + +# catch "used once" warnings +my @warns; +BEGIN { $SIG{__WARN__} = sub { push @warns, @_ }; $^W = 1 }; + +%x = (); +$y = 3; +@z = (); +$X::x = 13; + +use vars qw($p @q %r *s &t $X::p); + +my $e = !(grep /^Name "X::x" used only once: possible typo/, @warns) && 'not '; +print "${e}ok 1\n"; +$e = !(grep /^Name "main::x" used only once: possible typo/, @warns) && 'not '; +print "${e}ok 2\n"; +$e = !(grep /^Name "main::y" used only once: possible typo/, @warns) && 'not '; +print "${e}ok 3\n"; +$e = !(grep /^Name "main::z" used only once: possible typo/, @warns) && 'not '; +print "${e}ok 4\n"; +($e, @warns) = @warns != 4 && 'not '; +print "${e}ok 5\n"; + +# this is inside eval() to avoid creation of symbol table entries and +# to avoid "used once" warnings +eval <<'EOE'; +$e = ! $main::{p} && 'not '; +print "${e}ok 6\n"; +$e = ! *q{ARRAY} && 'not '; +print "${e}ok 7\n"; +$e = ! *r{HASH} && 'not '; +print "${e}ok 8\n"; +$e = ! $main::{s} && 'not '; +print "${e}ok 9\n"; +$e = ! *t{CODE} && 'not '; +print "${e}ok 10\n"; +$e = defined $X::{q} && 'not '; +print "${e}ok 11\n"; +$e = ! $X::{p} && 'not '; +print "${e}ok 12\n"; +EOE +$e = $@ && 'not '; +print "${e}ok 13\n"; + +eval q{use vars qw(@X::y !abc); $e = ! *X::y{ARRAY} && 'not '}; +print "${e}ok 14\n"; +$e = $@ !~ /^'!abc' is not a valid variable name/ && 'not '; +print "${e}ok 15\n"; + +eval 'use vars qw($x[3])'; +$e = $@ !~ /^Can't declare individual elements of hash or array/ && 'not '; +print "${e}ok 16\n"; + +{ local $^W; + eval 'use vars qw($!)'; + ($e, @warns) = ($@ || @warns) ? 'not ' : ''; + print "${e}ok 17\n"; +}; + +# NB the next test only works because vars.pm has already been loaded +eval 'use warnings "vars"; use vars qw($!)'; +$e = ($@ || (shift(@warns)||'') !~ /^No need to declare built-in vars/) + && 'not '; +print "${e}ok 18\n"; + +no strict 'vars'; +eval 'use vars qw(@x%%)'; +$e = $@ && 'not '; +print "${e}ok 19\n"; +$e = ! *{'x%%'}{ARRAY} && 'not '; +print "${e}ok 20\n"; +eval '$u = 3; @v = (); %w = ()'; +$e = $@ && 'not '; +print "${e}ok 21\n"; + +use strict 'vars'; +eval 'use vars qw(@y%%)'; +$e = $@ !~ /^'\@y%%' is not a valid variable name under strict vars/ && 'not '; +print "${e}ok 22\n"; +$e = *{'y%%'}{ARRAY} && 'not '; +print "${e}ok 23\n"; +eval '$u = 3; @v = (); %w = ()'; +my @errs = split /\n/, $@; +$e = @errs != 3 && 'not '; +print "${e}ok 24\n"; +$e = !(grep(/^Global symbol "\$u" requires explicit package name/, @errs)) + && 'not '; +print "${e}ok 25\n"; +$e = !(grep(/^Global symbol "\@v" requires explicit package name/, @errs)) + && 'not '; +print "${e}ok 26\n"; +$e = !(grep(/^Global symbol "\%w" requires explicit package name/, @errs)) + && 'not '; +print "${e}ok 27\n"; --- ./t/lib/1_compile.t.orig Wed May 16 22:02:07 2001 +++ ./t/lib/1_compile.t Mon May 21 14:34:43 2001 @@ -241,6 +241,5 @@ strict subs utf8 -vars warnings warnings::register --- ./lib/vars.pm.orig Wed Dec 6 15:10:18 2000 +++ ./lib/vars.pm Tue May 22 11:42:37 2001 @@ -17,31 +17,29 @@ sub import { my $callpack = caller; my ($pack, @imports, $sym, $ch) = @_; - foreach $sym (@imports) { - ($ch, $sym) = unpack('a1a*', $sym); + foreach (@imports) { + ($ch, $sym) = unpack('a1a*', $_); if ($sym =~ tr/A-Za-z_0-9//c) { # time for a more-detailed check-up - if ($sym =~ /::/) { - require Carp; - Carp::croak("Can't declare another package's variables"); - } elsif ($sym =~ /^\w+[[{].*[]}]$/) { + if ($sym =~ /^\w+[[{].*[]}]$/) { require Carp; Carp::croak("Can't declare individual elements of hash or array"); } elsif (warnings::enabled() and length($sym) == 1 and $sym !~ tr/a-zA-Z//) { warnings::warn("No need to declare built-in vars"); } elsif ( $^H &= strict::bits('vars') ) { - Carp::croak("'$ch$sym' is not a valid variable name under strict vars"); + Carp::croak("'$_' is not a valid variable name under strict vars"); } } - *{"${callpack}::$sym"} = - ( $ch eq "\$" ? \$ {"${callpack}::$sym"} - : $ch eq "\@" ? \@ {"${callpack}::$sym"} - : $ch eq "\%" ? \% {"${callpack}::$sym"} - : $ch eq "\*" ? \* {"${callpack}::$sym"} - : $ch eq "\&" ? \& {"${callpack}::$sym"} + $sym = "${callpack}::$sym" unless $sym =~ /::/; + *$sym = + ( $ch eq "\$" ? \$$sym + : $ch eq "\@" ? \@$sym + : $ch eq "\%" ? \%$sym + : $ch eq "\*" ? \*$sym + : $ch eq "\&" ? \&$sym : do { require Carp; - Carp::croak("'$ch$sym' is not a valid variable name"); + Carp::croak("'$_' is not a valid variable name"); }); } }; @@ -59,9 +57,9 @@ =head1 DESCRIPTION -NOTE: The functionality provided by this pragma has been superseded -by C declarations, available in Perl v5.6.0 or later. See -L. +NOTE: For variables in the current package, the functionality provided +by this pragma has been superseded by C declarations, available +in Perl v5.6.0 or later. See L. This will predeclare all the variables whose names are in the list, allowing you to use them under "use strict", and End of patch ```
p5pRT commented 23 years ago

From @schwern

I have mixed feelings on this. Using other variable's packages is bad\, and I'd like it to remain relatively difficult to do so. However\, explicitly declaring that you're going to use someone else's variable is better than just nabbing the thing directly. And yes\, the tricks necessary to get around the "used only once" warnings are annoying.

How about this. C\< use vars '$OS2​::is_aout'; > will only work if that variable has already been declared/used by the other package.

As an alternative/addition\, a seperate pragma. C\< use your '$OS2​::is_aout' > I particularly like this as it reduces the scope of vars.pm\, its complexity and what it should do. your.pm can be distributed independently as a CPAN module\, thus the new syntax will be useful before 5.8.0 (something that makes things like our() not yet entirely useful).

And as a brain fart\, perhaps a 'your' keyword? C\< your $OS2​::is_aout; >

p5pRT commented 23 years ago

From @mjdominus

I supplied a patch for this one year ago. It was not accepted.

http​://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2000-05/msg00713.html http​://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2000-05/msg00745.html

p5pRT commented 23 years ago

From @schwern

If it hasn't made it to your local mirror\, it can always be gotten from http​://www.pobox.com/~schwern/src/your-0.01.tar.gz

Also\, I noticed in the patch you've added a bunch of new tests for vars.pm. Could you tear this out into a seperate patch less the %Foo​::bar stuff? I don't want to lose the new test in the noise of figuring out if this new vars.pm feature is in or not.

p5pRT commented 23 years ago

From @abigail

Argh. No. Please.

It's against DWIM which is so typical Perl.

Let Perl figure out what the programmer wants\, don't let her dance a different dance just because you are referring to someone elses package.

The "It doesn't stroke with my programming style\, so it should be forbidden/hard to do" reasoning should die.

Abigail

p5pRT commented 23 years ago

From @gbarr

Absolutely

Graham.

p5pRT commented 23 years ago

From [Unknown Contact. See original ticket]

Surely it should be their.pm ? only 1/2 ;-)

Also\, I noticed in the patch you've added a bunch of new tests for vars.pm. Could you tear this out into a seperate patch less the %Foo​::bar stuff? I don't want to lose the new test in the noise of figuring out if this new vars.pm feature is in or not.

p5pRT commented 23 years ago

From [Unknown Contact. See original ticket]

To clarify​: that patch was to upgrade "our". And as I noted in my message\, Larry has specifically rejected that. But AFAIK no patch for "use vars" has been submitted previously. Everyone posting in the referenced thread seemed to be in favour of changing "use vars". I didn't see any objection.

To repeat what I said - the fact that "our" is not to be upgraded strengthens the case for upgrading "use vars".

Mike Guy