Closed p5pRT closed 16 years ago
It seems that Safe::reval does something wrong when the semicolon is omitted after the last statement of a block:
use Carp; use Safe;
my $safe = new Safe; my $number = $safe->reval("do { rand }"); carp "rand was trapped" if $@;
This produces:
syntax error at /usr/share/perl/5.6.0/Carp/Heavy.pm line 1\, near "package Carp" Compilation failed in require at /usr/share/perl/5.6.0/Carp.pm line 109.
This is fixed by adding the semicolon after "rand". (Notice how the semicolon for "do" can be omitted w/o problems.)
Same thing happens for eval\, sub\, if\, or anything that takes a block. The problem doesn't show up for a single statement. Tentative test seem to indicate that only the innermost block is affected\, but I can't say for sure.
Bug 20000712.002 suggests that the impact of this breakage is not limited to Carp.
(This is rather easy to circumvent\, once you know how. Unfortunately\, there's lots of head-scratching between the error message and the source.)
When I try this on Perl5.7.0 (patch 8585) on VMS 6.2\, the result is:
rand was trapped at - line 4
Which I suspect is closer to what one expects should happen. There were some patches applied to Safe:: and Opcode:: stuff between 5.6.0 and the current development version.
rbaecker@www-devel-rbaecker ~/perl510/bugs $ perl 6783.pl rand was trapped at 6783.pl line 8 rbaecker@www-devel-rbaecker ~/perl510/bugs $ cd ../perl-5.10.0/ rbaecker@www-devel-rbaecker ~/perl510/perl-5.10.0 $ ./perl -Ilib ../bugs/6783.pl rand was trapped at ../bugs/6783.pl line 8
--
Renée Bäcker renee.baecker@smart-websolutions.de
XING: http://www.xing.com/profile/Renee_Baecker Foo-Magazin: http://foo-magazin.de
@rgs - Status changed from 'open' to 'resolved'
This was fixed with Change 7098.
----Output of ...l/pmVPH4L/perl-5.7.0@7097/bin/perl---- not ok
----EOF ($?='0')---- ----Output of ...l/pbHYVRt/perl-5.7.0@7098/bin/perl---- ok
----EOF ($?='0')----
http://public.activestate.com/cgi-bin/perlbrowse/p/7098 Change 7098 by nick@camel-linux on 2000/09/30 12:48:00
Subject: Re: Trapping by opmask sets strange parser state [PATCH] From: Gisle Aas \gisle@​ActiveState\.com Date: 15 Sep 2000 16:23:41 +0200 Message-Id: \m3aed9ybrm\.fsf@​eik\.g\.aas\.no
Migrated from rt.perl.org#6783 (status was 'resolved')
Searchable as RT6783$