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

[perl #85508] regression in print length undef

Thread Next
From:
Nicholas Clark
Date:
March 6, 2011 05:50
Subject:
[perl #85508] regression in print length undef
Message ID:
rt-3.6.HEAD-28241-1299414918-1588.85508-75-0@perl.org
# New Ticket Created by  Nicholas Clark 
# Please include the string:  [perl #85508]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=85508 >


This is a bug report for perl from nick@ccl4.org,
generated with the help of perlbug 1.39 running under perl 5.13.4.


-----------------------------------------------------------------
[Please describe your issue here]

In fixing a related bug, d88e091f66003672 introduced a regression when printing
the length of an undefined value:

$ ./perl  -wle 'print length undef'

$ ./perl  -wle 'print length $a'
Name "main::a" used only once: possible typo at -e line 1.

$ ./perl^  -wle 'print length undef'
Use of uninitialized value in print at -e line 1.

$ ./perl^  -wle 'print length $a'
Name "main::a" used only once: possible typo at -e line 1.
Use of uninitialized value in print at -e line 1.


It's not obvious to me why this code change causes this behaviour change.
It doesn't seem to be to do with list context.

commit d88e091f660036722622a815efa9ef3779605ea6
Author: Ben Morrow <ben@morrow.me.uk>
Date:   Fri Aug 20 18:35:58 2010 +0100

    Fix my $x = 3; $x = length(undef);.
    
    Assignment of length() to a lexical is optimized by passing the
    assigned-to variable as TARG, avoiding a pp_padsv and pp_sassign.
    9f621b which changed length(undef) to return undef didn't take this into
    account, and used SETs (which doesn't set TARG), so the code above left
    $x == 3.

diff --git a/pp.c b/pp.c
index 0da8bba..fcb7ff2 100644
--- a/pp.c
+++ b/pp.c
@@ -3105,8 +3105,10 @@ PP(pp_length)
            = sv_2pv_flags(sv, &len,
                           SV_UNDEF_RETURNS_NULL|SV_CONST_RETURN|SV_GMAGIC);
 
-       if (!p)
-           SETs(&PL_sv_undef);
+       if (!p) {
+           sv_setsv(TARG, &PL_sv_undef);
+           SETTARG;
+       }
        else if (DO_UTF8(sv)) {
            SETi(utf8_length((U8*)p, (U8*)p + len));
        }
@@ -3119,7 +3121,8 @@ PP(pp_length)
        else
            SETi(sv_len(sv));
     } else {
-       SETs(&PL_sv_undef);
+       sv_setsv_nomg(TARG, &PL_sv_undef);
+       SETTARG;
     }
     RETURN;
 }

[snip tests for bug fixed]

Nicholas Clark

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

Configured by nick at Sun Mar  6 11:55:52 GMT 2011.

Summary of my perl5 (revision 5 version 13 subversion 4) configuration:
  Commit id: d88e091f660036722622a815efa9ef3779605ea6
  Platform:
    osname=linux, osvers=2.6.35.4, archname=x86_64-linux-thread-multi
    uname='linux eris 2.6.35.4 #4 smp tue sep 21 09:54:22 bst 2010 x86_64 gnulinux '
    config_args='-Dusethreads -Dprefix=~/Sandpit/bisect -Dcc=ccache gcc -Dld=gcc -Dnoextensions=IPC/SysV -Dusedevel -de'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='ccache gcc', ccflags ='-DFOO -D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2',
    cppflags='-DFOO -D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
    ccversion='', gccversion='4.3.2', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -fstack-protector -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib /lib64 /usr/lib64
    libs=-lnsl -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=/lib/libc-2.7.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.7'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector'

Locally applied patches:
    

---
@INC for perl 5.13.4:
    lib
    /home/nick/Sandpit/bisect/lib/perl5/site_perl/5.13.4/x86_64-linux-thread-multi
    /home/nick/Sandpit/bisect/lib/perl5/site_perl/5.13.4
    /home/nick/Sandpit/bisect/lib/perl5/5.13.4/x86_64-linux-thread-multi
    /home/nick/Sandpit/bisect/lib/perl5/5.13.4
    .

---
Environment for perl 5.13.4:
    HOME=/home/nick
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/nick/bin:/usr/local/bin:/usr/bin:/bin:/usr/games:/usr/local/sbin:/sbin:/usr/sbin
    PERL_BADLANG (unset)
    SHELL=/bin/bash


Thread Next


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