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

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

Steve Peters via RT
December 9, 2004 18:14
[perl #2562] wantarray fails in END, INIT, and CHECK blocks
Message ID:
> [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/
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

eval {
    fails("in eval");


    fails("in INIT");

    fails("in CHECK");

    fails("in END"); # void context

> ./perl -Ilib ~/sandbox/perl_rt/
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

SV = PVNV(0x3c03141c) at 0x3c03064c
  REFCNT = 2147483647
  IV = 0
  NV = 0
  PV = 0x3c02b040 ""\0
  CUR = 0
  LEN = 1
in END, not void context Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About