develooper Front page | perl.perl5.porters | Postings from December 2004

[perl #2562] wantarray fails in END, INIT, and CHECK blocks

From:
Steve Peters via RT
Date:
December 9, 2004 18:14
Subject:
[perl #2562] wantarray fails in END, INIT, and CHECK blocks
Message ID:
rt-3.0.11-2562-102512.15.042356204653@perl.org
> [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
 



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About