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:
Dave Mitchell
Date:
February 17, 2003 11:38
Subject:
Re: odd (or not so odd?) segmentation fault in 5.8.0
Message ID:
20030217193510.B14740@fdgroup.com
On Mon, Feb 17, 2003 at 11:07:51AM -0500, Mark Mielke wrote:
> I'm certain that it must be related, however, it isn't obvious to me why
> the following code has the same effect:
> 
>     sub TIESCALAR { bless [] }
>     sub FETCH     { *b = *a; *a = \ 1 }
>     tie($a, __PACKAGE__);
>     print $a;
> 
> Shouldn't the additional reference count from $b keep $a from being freed,
> and if so, why does mg_get() fail? (Or is a different piece of code dumping
> core in this case?)

No, what you have is a stash with 2 entries 'a'  and 'b', both of which
refer to the same GV. The sv entry of that GV used to point to the tied
SV, and now points to \1.

If instead you take a reference to $a, it works:

    sub DESTROY { print "DESTROY called\n" }
    sub TIESCALAR { bless [] }
    sub FETCH     { print "FETCH called (@_)\n"; $b = \$a; *a = \1, 55 }
    tie($a, __PACKAGE__);
    $x = $a;
    print "x=[$x]\n";

    $x = $a;
    print "x=[$x]\n";

    $b = 0;

    $x = $a;
    print "x=[$x]\n";

outputs:

    FETCH called (main=ARRAY(0x81739d4))
    x=[55]
    x=[1]
    DESTROY called
    x=[1]


> It would be nice to be able to set up demand-loadable scalars just as
> it is possible to set up demand-loadable subroutines, however, if it
> looks like this will just be too much trouble, I'll stop asking
> embarassing questions. :-)

I must confess that I can't currently thing of a way of doing this :-(

-- 
Technology is dominated by two types of people: those who understand what
they do not manage, and those who manage what they do not understand. 

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