Closed p5pRT closed 19 years ago
This is a bug report for perl from khwilliamson@lucent.com\, generated with the help of perlbug 1.26 running under perl 5.00503.
# wantarray in the END block returns true in void context instead of the proper 'undefined'. This program illustrates:
use strict;
sub fails($) { my $string = shift; print $string\, "\, not void context\n" if defined wantarray; print $string\, "\, in void context\n" unless defined wantarray; }
fails("not in END"); # void context
END { fails("in END"); # void context }
# both calls to 'fails' should print the same result\, but they don't # on my system. And by the way\, the O'Reilly "Programming Perl" p. 241 # 2nd edition fails to mention wantarray being undefined in void context # It's in perlpod perlfunc.
Site configuration information for perl 5.00503:
Configured by expmake at Fri Sep 10 16:33:51 CDT 1999.
Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration: Platform: osname=solaris\, osvers=2.4\, archname=sun4-solaris uname='sunos nwpep 5.4 generic_101945-61 sun4d sparc ' hint=recommended\, useposix=true\, d_sigaction=define usethreads=undef useperlio=undef d_sfio=undef Compiler: cc='cc'\, optimize='-O'\, gccversion= cppflags='' ccflags ='' stdchar='unsigned char'\, d_stdstdio=define\, usevfork=false intsize=4\, longsize=4\, ptrsize=4\, doublesize=8 d_longlong=define\, longlongsize=8\, d_longdbl=define\, longdblsize=16 alignbytes=8\, usemymalloc=y\, prototype=define Linker and Libraries: ld='cc'\, ldflags ='' libpth=/lib /usr/lib /usr/ccs/lib libs=-lsocket -lnsl -ldl -lm -lc -lcrypt libc=/lib/libc.so\, so=so\, useshrplib=false\, libperl=libperl.a Dynamic Linking: dlsrc=dl_dlopen.xs\, dlext=so\, d_dlsymun=undef\, ccdlflags=' ' cccdlflags='-KPIC'\, lddlflags='-G'
Locally applied patches:
@INC for perl 5.00503: /opt/exp/perl/lib/5.00503/sun4-solaris /opt/exp/perl/lib/5.00503 /opt/exp/perl/lib/site_perl/5.005/sun4-solaris /opt/exp/perl/lib/site_perl/5.005 .
Environment for perl 5.00503: HOME=/home/khw LANG (unset) LANGUAGE (unset) LD_LIBRARY_PATH=/usr/openwin/lib:/usr/lib LOGDIR (unset) PATH=/usr/local/src/post/src/post:/home/khw/specbin:/home/khw/bin:/home/khw/print/bin:/usr/add-on/dwb/bin:/usr/5bin:/usr/ucb:/usr/add-on/local/bin:/usr/add-on/unison/bin:/opt/exp/bin:/usr/sbin:/usr/add-on/zmail/bin:/usr/add-on/ncmp/630/bin:/usr/add-on/SUNWspro/bin:/usr/openwin/bin:/usr/openwin/demo:/usr/bin/X11:/usr/add-on/ncmp/bin:/usr/ccs/bin:/etc:/usr/add-on/defty5/bin:/usr/add-on/tools/bin:/opt/exp/perl/bin: PERL_BADLANG (unset) SHELL=/bin/ksh
khw@bighorn.dr.lucent.com wrote:
generated with the help of perlbug 1.26 running under perl 5.00503. ----------------------------------------------------------------- # wantarray in the END block returns true in void context instead of the proper 'undefined'. This program illustrates:
This is still true in RC3. It's apparently only true for the last statement in the END block\, though.
On Wed\, Mar 22\, 2000 at 10:29:33AM -0500\, Norton Allen wrote:
khw@bighorn.dr.lucent.com wrote:
generated with the help of perlbug 1.26 running under perl 5.00503. ----------------------------------------------------------------- # wantarray in the END block returns true in void context instead of the proper 'undefined'. This program illustrates:
This is still true in RC3. It's apparently only true for the last statement in the END block\, though.
Clearly\, the END block itself is not being called in void context.
Ronald
Ronald J Kimball wrote:
On Wed\, Mar 22\, 2000 at 10:29:33AM -0500\, Norton Allen wrote:
khw@bighorn.dr.lucent.com wrote:
generated with the help of perlbug 1.26 running under perl 5.00503. ----------------------------------------------------------------- # wantarray in the END block returns true in void context instead of the proper 'undefined'. This program illustrates:
This is still true in RC3. It's apparently only true for the last statement in the END block\, though.
Clearly\, the END block itself is not being called in void context.
Of course\, it appears to be called in scalar context.
[khw@bighorn.dr.lucent.com - Tue Mar 21 08:54:01 2000]:
This is a bug report for perl from khwilliamson@lucent.com\, generated with the help of perlbug 1.26 running under perl 5.00503.
# wantarray in the END block returns true in void context instead of the proper 'undefined'. This program illustrates:
use strict;
sub fails($) { my $string = shift; print $string\, "\, not void context\n" if defined wantarray; print $string\, "\, in void context\n" unless defined wantarray; }
fails("not in END"); # void context
END { fails("in END"); # void context }
# both calls to 'fails' should print the same result\, but they don't # on my system. And by the way\, the O'Reilly "Programming Perl" p. 241 # 2nd edition fails to mention wantarray being undefined in void context # It's in perlpod perlfunc.
Confirmed to fail against @17821 (5.8/5.9 development track).
[coral - Sun Sep 1 16:17:31 2002]:
Still exists in 5.8.1 RC2
[schwern - Tue Jul 15 19:50:14 2003]:
[coral - Sun Sep 1 16:17:31 2002]:
Still exists in 5.8.1 RC2
Rather than reconfirm the existance of this bug\, I thought I'd investigate a bit further. It does\, in fact\, continue to exist in today's blead. My investigations found that wantarry has issues in INIT and CHECK as well as END. I modified the bug title to clarify this. Also\, using Devel::Peek\, I was able to confirm that wantarray() returns a different value in a void context inside of END\, INIT\, and CHECK than outside. In END\, INIT\, and CHECK\, wantarry returns a PVNV. Outside those functions\, it returns NULL. See the example program below for examples and output.
cat ~/sandbox/perl_rt/rt_2562.pl use Devel::Peek 'Dump';
sub foo { fails("in foo()"); # void context }
sub fails($) { my $string = $_[0]; print $string\, "\, not void context\n" if defined wantarray; print $string\, "\, in void context\n" if ! defined wantarray; print ref wantarray; print "\n"; }
fails("not in END"); # void context foo();
eval { fails("in eval"); };
Dump(wantarray());
INIT { fails("in INIT"); }
CHECK { fails("in CHECK"); }
END { Dump(wantarray()); fails("in END"); # void context }
./perl -Ilib ~/sandbox/perl_rt/rt_2562.pl in CHECK\, not void context
in INIT\, not void context
not in END\, in void context
in foo()\, in void context
in eval\, in void context
SV = NULL(0x0) at 0x3c030640 REFCNT = 2147483617 FLAGS = (READONLY)
SV = PVNV(0x3c03141c) at 0x3c03064c REFCNT = 2147483647 FLAGS = (IOK\,NOK\,POK\,READONLY\,pIOK\,pNOK\,pPOK) IV = 0 NV = 0 PV = 0x3c02b040 ""\0 CUR = 0 LEN = 1 in END\, not void context
Steve Peters wrote
In END\, INIT\, and CHECK\, wantarry returns a PVNV. Outside those functions\, it returns NULL.
Those values are just the standard builtin values of 'true'\, 'false' and 'undef'\, i.e. PL_sv_yes\, PL_sv_no and PL_sv_undef.
I haven't looked at the original bug but I assume it is making some some comment about the values of wantarray() in END{}. But this is a pretty stupid thing to worry about. The answer is to document it as not being specified\, as in the attached patch.
Mike Guy
Mike Guy wrote in perl.perl5.porters :
Those values are just the standard builtin values of 'true'\, 'false' and 'undef'\, i.e. PL_sv_yes\, PL_sv_no and PL_sv_undef.
I haven't looked at the original bug but I assume it is making some some comment about the values of wantarray() in END{}. But this is a pretty stupid thing to worry about. The answer is to document it as not being specified\, as in the attached patch.
--- ./pod/perlfunc.pod.orig 2003-07-27 22:47:22.000000000 +0100 +++ ./pod/perlfunc.pod 2004-12-10 18:56:58.051871000 +0000
Thanks\, applied as #23639.
@smpeters - Status changed from 'open' to 'resolved'
Migrated from rt.perl.org#2562 (status was 'resolved')
Searchable as RT2562$