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

Re: mission impossible for the day

Thread Previous
David Mitchell
March 8, 2001 05:23
Re: mission impossible for the day
Message ID:
> 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
> 1..293
> ok 1
> ok 2
> ok 3
> ok 4
> Deep recursion on anonymous subroutine at ../lib/Carp/ line 53.
> Deep recursion on subroutine "Carp::croak" at line 438.
> Deep recursion on subroutine "Carp::shortmess_heavy" at ../lib/ line 
> Deep recursion on subroutine "Carp::ret_summary" at ../lib/Carp/ line 
> Deep recursion on subroutine "Carp::caller_info" at ../lib/Carp/ line 
> Deep recursion on subroutine "Carp::format_arg" at ../lib/Carp/ line 
> [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 (or to put it another way, its fixable
in, possibly by adding a stringify operator).

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

"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/

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 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 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.
* Tel: +44 114 281 6113.                The usual disclaimers....
* Standards (n). Battle insignia or tribal totems

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