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

Re: [perl #21347] segfault in UNIVERSAL::AUTOLOAD

Thread Previous | Thread Next
Enache Adrian
February 24, 2003 08:28
Re: [perl #21347] segfault in UNIVERSAL::AUTOLOAD
Message ID:
On Sun, Feb 23, 2003 at 10:20:51PM -0000, Stas Bekman wrote:
> % perl-blead -lwe 'sub UNIVERSAL::AUTOLOAD {qr//}; A->v()'
> Segmentation fault (core dumped)
> The segfault happens with blead, 5.6.x, 5.005, but not with 5.8
> % perl-5.8.0 -lwe 'sub UNIVERSAL::AUTOLOAD {qr//}; A->v()'
> Can't locate object method "v" via package "A" (perhaps you forgot to load
> "A"?) at -e line 1.

Perl blesses the reference qr// returns into a hypothetical
"Regexp" package (see pp_qr() - pp_hot.c:1140) . It seems that the
only use for this trick is that
	$a = qr/ ... /;
	ref $a
returns 'Regexp'. This is used by a lot a Perl modules/scripts.

When the time comes for the qr// to be freed, the code inside
sv_clear() tries to call its DESTROY method - since it is an
object. (sv.c:5261)
DESTROY doesn't exist in the 'Regexp' stash: if the user defined
a UNIVERSAL::AUTOLOAD sub, that will be called instead.
If that AUTOLOAD uses qr//'s, the recursion happens.

I have 2 ideas to fix that:

1) Completely drop the 'Regexp' stash trick. Let $a = qr/../ be
a simple reference. Hack sv_reftype to return "Regexp" if the SV
its argument points to is a 'r'-magical variable.

2) Put a dummy DESTROY method in the 'Regexp' stash.

The 1) has the net advantage of speed & simplicity. It may,
however, break a lot of things.

Any other suggestions/opinions ?



Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About