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 08:30
Subject:
Re: odd (or not so odd?) segmentation fault in 5.8.0
Message ID:
20030216163841.GA21306@mark.mielke.cc
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
version of the third attempt or so that I made. The first attempt,
was of course, to untie the variable within FETCH. The fourth attempt
was to do:

    *b = *a; *a = \1;

If I remember, this also generated a core dump.

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

> When you say print $a, Perl try to call the 1's svt_get()
> magic callback :-( - since $a still is a tied, magic variable.

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.

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

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