List Info

Thread: @_ ends up incorrectly aliasing user array




@_ ends up incorrectly aliasing user array
user name
2007-10-19 18:24:26
# New Ticket Created by  owlbarnowl.research.intel-research.net 
# Please include the string:  [perl #46565]
# in the subject line of all future correspondence about
this issue. 
# <URL: h
ttp://rt.perl.org/rt3/Ticket/Display.html?id=46565 >



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


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

The following program

  sub Backwards_stacked($$) { my($a,$b) = _; $a lt
$b ? 1 : $a gt $b ? -1 : 0 }

  a
= ( 5, 19, 1996, 255, 90 );
  b
= sort main::Backwards_stacked a;

  {
      sub routine { "one", "two" };
      a = sort(routine(1));
      print "a" eq "one two" ? "ok
58n" : "not ok 58n";
  }

  print "an";
  $_[0] .= "x";
  print "an";

prints

  barnowl:~/ivy/mm/perl owl$ perl perlbug3.pl
  ok 58
  one two
  onex two

The assignment to $_[0] ends up corrupting a. Note
that the following program

  sub Backwards_stacked($$) { my($a,$b) = _; $a lt
$b ? 1 : $a gt $b ? -1 : 0 }

  z
= ( 5, 19, 1996, 255, 90 );
  b
= sort main::Backwards_stacked z;

  # Bug 19991001.003
  {
      sub routine { "one", "two" };
      a = sort(routine(1));
      print "a" eq "one two" ? "ok
58n" : "not ok 58n";
  }

  print "an";
  $_[0] .= "x";
  print "an";

prints

  barnowl:~/ivy/mm/perl owl$ perl p3a.pl
  ok 58
  one two
  one two


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

Configured by owl at Tue Sep 25 23:53:19 PDT 2007.

Summary of my perl5 (revision 5 version 8 subversion 8)
configuration:
  Platform:
    osname=darwin, osvers=8.10.1, archname=darwin-2level
    uname='darwin barnowl.research.intel-research.net 8.10.1
darwin kernel version 8.10.1: wed may 23 16:33:00 pdt 2007;
rootnu-79
2.22.5~1release_i386 i386 i386 '
    config_args='-des -Dprefix=/opt/local
-Dccflags=-I'/opt/local/include' -Dldflags=-L/opt/local/lib
-Dvendorprefix=/opt/local -Dcc=/usr/bin/gcc-4.0'
    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='/usr/bin/gcc-4.0', ccflags ='-I/opt/local/include
-fno-common -DPERL_DARWIN -no-cpp-precomp
-fno-strict-aliasing -pipe -Wdeclaration-after-statement
-I/opt/local/include',
    optimize='-O3',
    cppflags='-no-cpp-precomp -I/opt/local/include
-fno-common -DPERL_DARWIN -no-cpp-precomp
-fno-strict-aliasing -pipe -Wdeclaration-after-statement
-I/opt/local/include'
    ccversion='', gccversion='4.0.1 (Apple Computer, Inc.
build 5363)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8,
byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define,
longdblsize=16
    ivtype='long', ivsize=4, nvtype='double', nvsize=8,
Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='env MACOSX_DEPLOYMENT_TARGET=10.3 cc', ldflags
='-L/opt/local/lib -L/usr/local/lib'
    libpth=/usr/local/lib /opt/local/lib /usr/lib
    libs=-ldbm -ldl -lm -lc
    perllibs=-ldl -lm -lc
    libc=/usr/lib/libc.dylib, so=dylib, useshrplib=false,
libperl=libperl.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef,
ccdlflags=' '
    cccdlflags=' ', lddlflags='-L/opt/local/lib -bundle
-undefined dynamic_lookup -L/usr/local/lib'

Locally applied patches:
    

---
INC
for perl v5.8.8:
    /opt/local/lib/perl5/5.8.8/darwin-2level
    /opt/local/lib/perl5/5.8.8
    /opt/local/lib/perl5/site_perl/5.8.8/darwin-2level
    /opt/local/lib/perl5/site_perl/5.8.8
    /opt/local/lib/perl5/site_perl
    /opt/local/lib/perl5/vendor_perl/5.8.8/darwin-2level
    /opt/local/lib/perl5/vendor_perl/5.8.8
    /opt/local/lib/perl5/vendor_perl
    .

---
Environment for perl v5.8.8:
    DYLD_LIBRARY_PATH (unset)
    HOME=/Users/owl
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
   
PATH=/Users/owl/bin:/usr/X11R6/bin:/usr/local/bin:/opt/local
/bin:/opt/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin
    PERL_BADLANG (unset)
    SHELL=/bin/bash


Re: @_ ends up incorrectly aliasing user array
user name
2007-10-20 09:34:31
On 20/10/2007, via RT owl  barnowl. research.
intel-research. net >
The following program
>
>   sub Backwards_stacked($$) { my($a,$b) = _; $a lt
$b ? 1 : $a gt $b ? -1 : 0 }
>
>   a = ( 5, 19, 1996, 255, 90 );
>   b = sort main::Backwards_stacked a;
>
>   {
>       sub routine { "one", "two"
};
>       a = sort(routine(1));
>       print "a" eq "one two" ? "ok
58n" : "not ok 58n";
>   }
>
>   print "an";
>   $_[0] .= "x";
>   print "an";
>
> prints
>
>   barnowl:~/ivy/mm/perl owl$ perl perlbug3.pl
>   ok 58
>   one two
>   onex two
>
> The assignment to $_[0] ends up corrupting a.

Using a $$ prototype makes _ an alias to the sort
subroutine arguments.
That explains the strange behaviour you're seeing --
aliasing persists
after the sorting has occurred. _ should probably be
emptied
afterwards.

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )