develooper Front page | perl.perl5.porters | Postings from March 2006

[perl #38809] Bad return value from a block with variable localization

From:
vince @ midori . profvince . com
Date:
March 28, 2006 15:24
Subject:
[perl #38809] Bad return value from a block with variable localization
Message ID:
rt-3.0.11-38809-131578.4.30270872782081@perl.org
# New Ticket Created by  vince@midori.profvince.com 
# Please include the string:  [perl #38809]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/rt3/Ticket/Display.html?id=38809 >



This is a bug report for perl from vince@midori.profvince.com,
generated with the help of perlbug 1.35 running under perl v5.8.8.


-----------------------------------------------------------------
[Please enter your report here]

Hello,

I've run into this strange behaviour when playing with trying
to make functions return different values from the number of
parameters they were called with. If you test @_, and that you
return from a do { ... } block where a variable is localized,
the return value is undef if you don't add an else statement.

Looks like some parsing bug, but not that I'm good enough to have
any real clue about it.

Regards,

Vincent Pit

#################################################################
Test case: (line 1 is #!)

#!/usr/bin/perl

use strict;
use warnings;

sub foo {
 if (@_) {
  return do { my $dummy; 1; };
 } else {
  return 0;
 }
}

# let's just remove the else

sub bar {
 if (@_) {
  return do { my $dummy; 1; };
 }
 return 0;
}

print foo().' '.foo('baz')."\n"; # that was expected
print bar().' '.bar('baz')."\n"; # undef

#################################################################
Expected output:

0 1
0 1

#################################################################
Actual output:

0 1
Use of uninitialized value in concatenation (.) or string at ./bug.pl line 24.
0

#################################################################
Remarks:

The name of the localized variable doesn't matter.
Moreover, it will actually fail as well for local $_ (or any perl
variable). But the my/local itself is important, since do { 1 }
returns what it should.

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=core
    severity=medium
---
Site configuration information for perl v5.8.8:

Configured by vince at Tue Mar 28 18:29:28 CEST 2006.

Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
  Platform:
    osname=linux, osvers=2.6.15.1-lfs6.0+cvs-midori.profvince.com, archname=i686-linux
    uname='linux midori 2.6.15.1-lfs6.0+cvs-midori.profvince.com #1 preempt sun jan 22 15:51:10 cet 2006 i686 athlon-4 i386 gnulinux '
    config_args='-ds -e -Dprefix=/usr -Dpager=/usr/bin/less -isR -Dccflags= -march=athlon-xp -m3dnow -msse -mfpmath=sse -mmmx -O3 -pipe -funroll-loops'
    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
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-march=athlon-xp -m3dnow -msse -mfpmath=sse -mmmx -O3 -pipe -funroll-loops -fno-strict-aliasing -Wdeclaration-after-statement -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2',
    cppflags='-march=athlon-xp -m3dnow -msse -mfpmath=sse -mmmx -O3 -pipe -funroll-loops -fno-strict-aliasing -Wdeclaration-after-statement -I/usr/local/include'
    ccversion='', gccversion='3.4.3', 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, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
    libc=/lib/libc-2.3.4.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.3.4'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    

---
@INC for perl v5.8.8:
    /usr/lib/perl5/5.8.8/i686-linux
    /usr/lib/perl5/5.8.8
    /usr/lib/perl5/site_perl/5.8.8/i686-linux
    /usr/lib/perl5/site_perl/5.8.8
    /usr/lib/perl5/site_perl/5.8.6/i686-linux
    /usr/lib/perl5/site_perl/5.8.6
    /usr/lib/perl5/site_perl
    .

---
Environment for perl v5.8.8:
    HOME=/home/vince
    LANG=fr_FR.ISO-8859-1
    LANGUAGE=fr_FR.ISO-8859-1
    LC_ALL=fr_FR.ISO-8859-1
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/home/vince/bin
    PERL_BADLANG (unset)
    SHELL=/bin/bash




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