2 messages in org.perl.perl5-portersRe: [perl #52610] Bizarre copy of ARR...
FromSent OnAttachments
Chris Heath (via RT)Apr 8, 2008 11:39 am 
Nicholas ClarkApr 15, 2008 2:52 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [perl #52610] Bizarre copy of ARRAY in sassign at Carp/Heavy.pmActions
From:Nicholas Clark (ni@ccl4.org)
Date:Apr 15, 2008 2:52:29 am
List:org.perl.perl5-porters

On Tue, Apr 08, 2008 at 11:39:25AM -0700, Chris Heath wrote:

The following test program gives this error:

Bizarre copy of ARRAY in sassign at /usr/lib/perl5/5.8.8/Carp/Heavy.pm line 45.

Tested on the 5.8.x branch and on perl-current.

use Carp;

sub do_carp { print Carp::longmess; }

sub call_with_args { my ($arg_hash, $func) = @_; $func->(@{$arg_hash->{'args'}}); }

my $h = {}; # Deleting the undef makes it all work again! my $arg_hash = {'args' => [undef]}; call_with_args($arg_hash, sub { $arg_hash->{'args'} = []; do_carp(sub { $h; }); });

Thanks for this bug report. The error has been seen before, but not with this concise a test case. I can reduce it down to this:

$ cat C.pm package C; sub longmess_real { package DB; () = caller(2);

use Devel::Peek; Dump \@DB::args;

foreach(@DB::args) { my $a = $_; } }

1; __END__ $ cat 52610 sub longmess { require C; goto &C::longmess_real; }

sub do_carp { longmess; }

sub call_with_args { my ($arg_hash, $func) = @_; $func->(@{$arg_hash->{'args'}}); }

my $h = {}; # Deleting the undef makes it all work again! my $arg_hash = {'args' => [undef]}; call_with_args($arg_hash, sub { $arg_hash->{'args'} = []; do_carp(sub { $h; }); }); __END__ $ ./perl -Ilib 52610 SV = IV(0x10081d9a0) at 0x10081d9a8 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x10081dbd0 SV = PVAV(0x1008059e8) at 0x10081dbd0 REFCNT = 2 FLAGS = () ARRAY = 0x10050b538 FILL = 0 MAX = 3 ARYLEN = 0x0 FLAGS = () Elt No. 0 SV = PVAV(0x100805808) at 0x10081d738 REFCNT = 1 FLAGS = () ARRAY = 0x10050b4c8 FILL = 1 MAX = 3 ARYLEN = 0x0 FLAGS = (REAL) Elt No. 0 Elt No. 1 SV = PVNV(0x100802f18) at 0x10081d828 REFCNT = 2 FLAGS = (POK,FAKE,pPOK) IV = 0 NV = 1.97626258336499e-323 PV = 0x10050d2f8 "$h"\0 CUR = 2 LEN = 8 Bizarre copy of ARRAY in sassign at C.pm line 9.

[the line with Devel::Peek is optional]

It looks like the address of something on Perl's stack ends up being re-used as something (else) that points into a PAD. I'm not entirely sure why, and it's something "special" with how caller and package DB interact.