develooper Front page | perl.perl5.porters | Postings from October 2005

[perl #36211] local @a inside eval

Thread Previous | Thread Next
From:
Steve Peters via RT
Date:
October 1, 2005 21:41
Subject:
[perl #36211] local @a inside eval
Message ID:
rt-3.0.11-36211-121882.1.44561507886472@perl.org
> [davem@iabyn.com - Wed Jun 22 16:16:28 2005]:
> 
> On Wed, Jun 22, 2005 at 11:10:51PM +0100, Dave Mitchell wrote:
> > On Tue, Jun 14, 2005 at 10:45:17PM +0100, Dave Mitchell wrote:
> > > On Fri, Jun 10, 2005 at 11:04:36AM +0100, Dave Mitchell wrote:
> > > > I'm vaguely assuming that for tieing, during localization you
> would *copy*
> > > > the magic; then at restore time you just ditch any magic on the
> new SV,
> > > > and stick the old SV back into the typeglob with its current
> magic
> > > > intact. ie
> > >
> > > I now have a working patch that does just that
> >
> > and now applied as change #24942
> 
> Two further things related to this.
> 
> 1) I have added an mg_localize() function, which can be viewed as part
> of
> familily of functions that include mg_copy() and mg_dup(). Now, the
> mgvtbl
> structure happens to have been extended to have function pointers
> svt_copy
> and svt_dup which allow a particular magic to override the standard
> mg_copy() and mg_dup(); but to provide bincompat, these functions are
> only
> called if the MGf_COPY or MGf_DUP flags are set. Currently I believe
> threads::shared is the only part of the core to provide these hooks.
> 
> I propose, by analogy, to provide a similar hook for mg_localize();
> although I haven't checked closely; I think my patch currently breaks
> 
>     local $shared_var;
> 
> If I don't hear any complaints, I'll do this in a few days time.
> 
> 
> 2) Nicholas, my patch is specifically supposed to fix all the $#foo
> problems; an earlier email of yours included a test file for this; do
> you
> want me to add it to bleed or leave it to you?
> 
> 

I believe these are the tests...

#!perl -w

use Test;
plan (tests => 15);
use vars '@a';
use strict;

my $outer = \$#a;
ok ($$outer, -1);
ok (scalar @a, 0);

$$outer = 3;
ok ($$outer, 3);
ok (scalar @a, 4);

my $inner;
{
local @a;
$inner = \$#a;

ok ($$inner, -1);
ok (scalar @a, 0);

$$outer = 6;

ok ($$inner, -1);
ok (scalar @a, 0);

$$inner = 42;
}

ok (scalar @a, 7);
ok ($$outer, 6);

ok ($$inner, 0, "This ok emergent behaviour");

ok (scalar @a, 7);
ok ($$outer, 6);

$$inner = 1;

ok (scalar @a, 7);
ok ($$outer, 6);

$$inner = 503; # Bang!
__END__

Any suggestions for an appropriate test script?

Thread Previous | 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