Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bizarre copy of ARRAY #7277

Closed
p5pRT opened this issue May 4, 2004 · 5 comments
Closed

Bizarre copy of ARRAY #7277

p5pRT opened this issue May 4, 2004 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented May 4, 2004

Migrated from rt.perl.org#29340 (status was 'resolved')

Searchable as RT29340$

@p5pRT
Copy link
Author

p5pRT commented May 4, 2004

From cubic@acronis.ru

Created by cubic@cubic.acronis.ru

VCP.pm uses next code which fails under perl5.8.4​:

#!/usr/bin/perl

BEGIN {
  my @​arr = ();
  sub foo {
# fill in @​arr here
  return @​arr;
  }
}

exit(0);

Perl Info

Flags:
    category=core
    severity=high

Site configuration information for perl v5.8.4:

Configured by cubic at Mon May  3 18:44:21 MSD 2004.

Summary of my perl5 (revision 5 version 8 subversion 4) configuration:
  Platform:
    osname=linux, osvers=2.4.23, archname=i686-linux-thread-multi
    uname='linux cubic 2.4.23 #1 âòî ÿíâ 6 15:46:53 msk 2004 i686 i686 i386 gnulinux '
    config_args=''
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
    optimize='-g',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -I/usr/local/include -I/usr/include/gdbm'
    ccversion='', gccversion='3.3.2 20031022 (ASPLinux 3.3.2-1)', 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 -lpthread -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=/lib/libc-2.3.2.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.3.2'
  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.4:
    /usr/lib/perl5/5.8.4/i686-linux-thread-multi
    /usr/lib/perl5/5.8.4
    /usr/lib/perl5/site_perl/5.8.4/i686-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.4
    /usr/lib/perl5/site_perl
    .


Environment for perl v5.8.4:
    HOME=/home/cubic
    LANG=ru_RU.CP1251
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/usr/local/mysql/bin:/usr/java/j2re1.4.2_01/bin/:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/usr/local/svn/bin:/sbin:/usr/sbin/:/usr/local/sbin:/home/cubic/bin
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented May 4, 2004

From @nwc10

On Tue, May 04, 2004 at 08​:24​:48AM -0000, Ruslan U. Zakirov wrote​:

VCP.pm uses next code which fails under perl5.8.4​:

#!/usr/bin/perl

BEGIN {
my @​arr = ();
sub foo {
# fill in @​arr here
return @​arr;
}
}

It fails here.

exit(0);

Thanks for this report.

Most strange. It fails the same way on the current development version.
valgrind produces no errors.

Nicholas Clark

@p5pRT
Copy link
Author

p5pRT commented May 4, 2004

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented May 4, 2004

From @iabyn

On Tue, May 04, 2004 at 05​:38​:54PM +0100, Nicholas Clark wrote​:

On Tue, May 04, 2004 at 08​:24​:48AM -0000, Ruslan U. Zakirov wrote​:

VCP.pm uses next code which fails under perl5.8.4​:

#!/usr/bin/perl

BEGIN {
my @​arr = ();
sub foo {
# fill in @​arr here
return @​arr;
}
}

It fails here.

exit(0);

Thanks for this report.

Most strange. It fails the same way on the current development version.
valgrind produces no errors.

It's caused by Change 22520, Rafael's thinggy to optimise away the
assignment on my @​arr = ();

You can get the same effect with​:

  sub f { my @​arr = () }
  $x = f();

In the induced scalar context, the padav op should be pushing the contents
of the array onto the stack rather than the AV itself. Fixed by the change
below. This wasn't happening because the some flags were left set on the
pad op after the optimisation.

--
print+qq&$}$"$/$s$,$*${d}$g$s$@​$.$q$,$​:$.$q$^$,$@​$*$$;$.$q$m&if+map{m,^\d{0\,},,${$​::{$'}}=chr($"+=$&||1)}q&10m22,42}6​:17*22.3@​3;^2dg3q/s"&=~m*\d\*.*g

Change 22781 by davem@​davem-percy on 2004/05/04 19​:20​:36

  [perl #29340] Bizarre copy of ARRAY
  make sure a pad op's flags are updated after optimising away
  the assignment in my @​a = () (see change 22520).

Affected files ...

... //depot/perl/op.c#625 edit
... //depot/perl/t/op/my.t#9 edit

Differences ...

==== //depot/perl/op.c#625 (text) ====

@​@​ -3130,6 +3130,7 @​@​
  && (left->op_private & OPpLVAL_INTRO))
  {
  op_free(right);
+ left->op_flags &= ~(OPf_REF|OPf_SPECIAL);
  return left;
  }
  curop = list(force_list(left));

==== //depot/perl/t/op/my.t#9 (xtext) ====

@​@​ -2,7 +2,7 @​@​

# $RCSfile​: my.t,v $

-print "1..31\n";
+print "1..33\n";

sub foo {
  my($a, $b) = @​_;
@​@​ -99,3 +99,15 @​@​
  # Supposed to be copy-on-write via force_normal after a THINKFIRST check.
  print "$full $fonts{nok}\n";
}
+
+# [perl #29340] optimising away the = () left the padav returning the
+# array rather than the contents, leading to 'Bizarre copy of array' error
+
+sub opta { my @​a=() }
+sub opth { my %h=() }
+eval { my $x = opta };
+print "not " if $@​;
+print "ok 32\n";
+eval { my $x = opth };
+print "not " if $@​;
+print "ok 33\n";

@p5pRT
Copy link
Author

p5pRT commented May 4, 2004

@iabyn - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant