develooper Front page | perl.perl5.porters | Postings from March 2001

Re: mission impossible for the day

Thread Previous | Thread Next
From:
David Mitchell
Date:
March 8, 2001 05:23
Subject:
Re: mission impossible for the day
Message ID:
200103081323.NAA06417@tiree.fdgroup.co.uk
> Your task, should you choose to accept it, is to search and utterly
> destroy the reason why Switch 2.01 (requires Text::Balanced) doesn't
> like bleadperl.  This is what we know:
> 
> ../perl -I. -Ilib -I../lib test.pl
> 1..293
> ok 1
> ok 2
> ok 3
> ok 4
> Deep recursion on anonymous subroutine at ../lib/Carp/Heavy.pm line 53.
> Deep recursion on subroutine "Carp::croak" at Switch.pm line 438.
> Deep recursion on subroutine "Carp::shortmess_heavy" at ../lib/Carp.pm line 
114.
> Deep recursion on subroutine "Carp::ret_summary" at ../lib/Carp/Heavy.pm line 
195.
> Deep recursion on subroutine "Carp::caller_info" at ../lib/Carp/Heavy.pm line 
169.
> Deep recursion on subroutine "Carp::format_arg" at ../lib/Carp/Heavy.pm line 
32.
> [wait and ye shall be delivered either a segfault, or a core dump,
>  or a moral equivalent]
> 
> Should you fail in your mission, the pumpkin will disavow any
> knowledge of your actions.

It's a bug in Switch.pm (or to put it another way, its fixable
in Switch.pm, possibly by adding a stringify operator).

The nub of the problem is infinite mutual recursion, caused by the
following overloaded operator in Switch.pm:

"bool"  =>      sub { croak "Can't use && or || in expression containing __" },

When this is invoked,  croak() ends up calling caller_info() and
thus eventually format_arg() in Carp/Heavy.pm.

the relevant lines from format_arg() look like this:

my $arg = shift;
$arg .= ''; # Make it a string;
$arg =~ s/'/\\'/g;

Due the the fact that $arg is a reference to an overloaded Switch object,
and due to the fact that Switch.pm hasnt got a stringify operator,
$arg .= '' doesnt convert $arg into a string - instead, it remains an
object ref. Then,

$arg =~ s/'/\\'/g;

causes the Switch's bool overloaded operator to be invoked (this is because
there isnt a stringify operator, so bool gets called instead).
Bool then calls croak, which calls format_arg, which....

I guess adding a stringify operator to Switch will make the problem
go away, but since overloading and the internals of Switch.pm arent
my strong points, I'll hand the baton on to wiser folk for the fix ....

I presume it's only shown up recently in beadperl due to some change
in Carp. NB: why *is* croak attempting to display the caller args?


* Dave Mitchell, Senior Technical Consultant
* Fretwell-Downing Informatics Ltd, UK.  Dave.Mitchell@fdgroup.com
* Tel: +44 114 281 6113.                The usual disclaimers....
*
* Standards (n). Battle insignia or tribal totems



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