-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
aha -- I think this is the solution. key parts:
- (a) use die() to break out of the match
- (b) use POSIX::sigaction on perl 5.8.x to guarantee get "unsafe"
signal handling behaviour
I've appended the new test script, which DTRTs on both 5.6.1 and 5.8.4
here.
- --j.
#!/usr/bin/perl -w
use strict; trap_sigalrm (\&got_alrm); alarm 2;
my $start = time; print "entering re match\n";
my $text = (("o" x 9999) . "x") x 999;
eval { $text =~ /o*xo*y/; };
if ($@) { warn "eval caught: $@"; }
alarm 0;
my $end = time; print "done re match in ".($end - $start)." secs\n"; exit;
sub got_alrm { die "got sigalrm successfully\n"; }
sub trap_sigalrm {
my ($handler) = @_;
if ($^V lt v5.8.0) {
print "using SIG\n";
$SIG{ALRM} = $handler;
} else {
print "using sigaction\n";
use POSIX qw();
POSIX::sigaction POSIX::SIGALRM(), new POSIX::SigAction $handler;
}
}
__END__
to test:
/usr/local/perl561/bin/perl ~/ftp/bench/demo-evil-regexp
perl5.8.4 ~/ftp/bench/demo-evil-regexp
PERL_SIGNALS=unsafe perl5.8.4 ~/ftp/bench/demo-evil-regexp
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Exmh CVS
iD8DBQFBtmKmMJF5cimLx9ARAnygAJoCpXIP2NiF7Farynj2KdT3DXtSowCfdyGa
YK27HzGhwX49bf3jHDoNnmI=
=S7KJ
-----END PGP SIGNATURE-----