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

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

Thread Previous | Thread Next
From:
hv
Date:
February 25, 2003 18:11
Subject:
Re: [perl #21347] segfault in UNIVERSAL::AUTOLOAD
Message ID:
200302260214.h1Q2E5L16316@crypt.compulink.co.uk
Rafael Garcia-Suarez <rgarciasuarez@free.fr> wrote:
:Enache Adrian wrote:
:> 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.
:
:Thanks for that explanation.
:
:> 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.
:
:You can try this to see what breaks. From what I can see, some
:adjustements may be needed in Data::Dumper. However I think this is a
:cleaner solution than :
:
:> 2) Put a dummy DESTROY method in the 'Regexp' stash.

Hmm, I'd have thought the "cleaner" argument applies the other way
round: surely it is cleaner to let it be an object than to hack the
pretence of it?

It seems like it might be helpful at some point to be able to add
other Regexp:: methods - for introspection, for example, or even
as a window to enable or disable particular types of optimisation.

I'd even be tempted to document it, though that may be too radical
a step.

Hugo

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