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:
Mark Mielke
Date:
February 16, 2003 10:36
Subject:
Re: odd (or not so odd?) segmentation fault in 5.8.0
Message ID:
20030216184413.GA24725@mark.mielke.cc
On Sun, Feb 16, 2003 at 08:18:23PM +0200, Enache Adrian wrote:
> 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 ?

I was expecting the scalar part of the glob 'main::a' to refer to a
new scalar. It was irrelevant to me exactly when or if %a became
untied. I was trying different things. First I tried untie(). Third I
tried overwriting the glob. *Anything* to get the behaviour I
wanted. :-) Right now, I'm stuck with leaving the scalar tied, with an
"if (defined value) { value } else { value = ... }" FETCH method.

> > 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.

I was justifying my claim, not accusing you. :-) Thanks for working on this.

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

Something is definately up, although I guess the answer is, tie's are
complicated, and because they are complicated, the implementation of
tie's has not been fully analyzed even after a few stabs at making
them work better have been completed.

Is this worth trying to get fixed?

mark

-- 
mark@mielke.cc/markm@ncf.ca/markm@nortelnetworks.com __________________________
.  .  _  ._  . .   .__    .  . ._. .__ .   . . .__  | Neighbourhood Coder
|\/| |_| |_| |/    |_     |\/|  |  |_  |   |/  |_   | 
|  | | | | \ | \   |__ .  |  | .|. |__ |__ | \ |__  | Ottawa, Ontario, Canada

  One ring to rule them all, one ring to find them, one ring to bring them all
                       and in the darkness bind them...

                           http://mark.mielke.cc/


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