develooper Front page | perl.perl5.porters | Postings from February 2003

Re: odd (or not so odd?) segmentation fault in 5.8.0

Thread Previous | Thread Next
From:
Enache Adrian
Date:
February 16, 2003 10:19
Subject:
Re: odd (or not so odd?) segmentation fault in 5.8.0
Message ID:
20030216181823.GB795@ratsnest.hole
On Sun, Feb 16, 2003 at 11:38:41AM -0500, Mark Mielke wrote:
> On Sun, Feb 16, 2003 at 03:33:47PM +0200, Enache Adrian wrote:
> > On Thu, Feb 13, 2003 at 12:38:59AM -0500, Mark Mielke wrote:
> > > I haven't seen this reported yet. I'll try to track it down tomorrow,
> > > but in case anybody in the know can point out the problem immediately:
> > > $ perl -e 'sub TIESCALAR {bless[]} sub FETCH {*a=\1;1}
> > > > tie($a,__PACKAGE__); print $a'
> > You seem to assume that when you pointed the *a glob to 1, you
> > wipe all tie magic from the $a variable. This doesn't happen.
> 
> Actually I'm not assuming anything. The code above is a simplified

What were actually expecting from *a=\1 ?

> IMO, unless a system call is invoked, or XS code is invoked, straight
> Perl should _never_ core dump.

Right.

> It is an indication that something is wrong. It may have an extremely
> low possibility of occurring, but it is evidence that something is being
> referenced when it shouldn't be.

I was tracking down _why_ it dumps core. I wasn't justifying it.

> > Better try to rewrite your code to something like this ?
> > perl -e 'sub TIESCALAR {bless[]} \
> > 	 sub FETCH {my $a = tied $_[0]; untie $$a; $$a=1} \
> > 	 tie($a,__PACKAGE__);print $a'
> 
> This doesn't actually achieve the desired behaviour. See:
> 
>   $ perl -e 'sub TIESCALAR {bless[]}
>   sub FETCH {print "HELLO\n"; my $a = tied $_[0]; untie $$a; $$a=1}
>   tie($a,__PACKAGE__);print $a, $a, $a, "\n";'
>   HELLO
>   1HELLO
>   1HELLO
>   1
>   $
> 
> Notice that "HELLO" is being printed each time.

That really becomes interesting.

$ perl5.8.0 -e 'sub TIESCALAR { bless[] } sub FETCH { untie $a; print $a; "FETCH\n" }; tie $a, __PACKAGE__; print $a, $a, $a'
FETCH
FETCH
FETCH
FETCH
FETCH
$ perl5.6.1 -e 'sub TIESCALAR { bless[] } sub FETCH { untie $a; print $a; "FETCH\n" }; tie $a, __PACKAGE__; print $a, $a, $a'
FETCH
FETCH
FETCH

Adi

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