Subject: | reval causes infinite loop |
The following code causes infinite loop. The problem is in the
wrap_code_refs_within feature. I fixed the problem with the attached
patch.
-----
use Safe;
my $safe = new Safe;
print $safe->reval(<<'END');
%a = ();
%b = (a => \%a);
$a{b} = \%b;
END
-----
Subject: | Safe.227.20100910.patch |
*** Safe.pm.org Fri Sep 10 16:28:01 2010
--- Safe.pm Fri Sep 10 18:16:08 2010
***************
*** 2,8 ****
use 5.003_11;
use strict;
! use Scalar::Util qw(reftype);
$Safe::VERSION = "2.27";
--- 2,8 ----
use 5.003_11;
use strict;
! use Scalar::Util qw(reftype refaddr);
$Safe::VERSION = "2.27";
***************
*** 363,371 ****
--- 363,375 ----
}
+ my %OID;
+
sub wrap_code_refs_within {
my $obj = shift;
+ %OID = ();
+
$obj->_find_code_refs('wrap_code_ref', @_);
}
***************
*** 377,382 ****
--- 381,391 ----
for my $item (@_) {
my $reftype = $item && reftype $item
or next;
+
+ # skip at second time
+ my $oid = refaddr $item;
+ next if ++$OID{$oid} > 1;
+
if ($reftype eq 'ARRAY') {
$obj->_find_code_refs($visitor, @$item);
}