Storable

 view release on metacpan or  search on metacpan

stacksize  view on Meta::CPAN

}

unless ($ENV{STORABLE_NOISY}) {
    # suppress Segmentation fault messages
    open STDERR, ">", File::Spec->devnull;
}

while (!$found) {
    my $cmd = array_cmd($n);
    #print "$cmd\n" unless $QUIET;
    if (`$cmd` =~ /\bok\b/) {
        $n = good($n);
    } else {
        $n = bad($n);
    }
}
print "# MAX_DEPTH = $n\n" unless QUIET;
my $max_depth = $n;

($n, $good, $bad, $found) =
  (int($n/2), 50, $n, undef);
# pack j only since 5.8
my $max = ($] > 5.007 and length(pack "j", 0) < 8)
  ? ($^O eq 'MSWin32' ? 3000 : 8000)
  : $max_depth;
$n = $max if $n > $max;
$bad = $max if $bad > $max;
while (!$found) {
    my $cmd = cmd($n, '$t={1=>$t}', 'recursion_limit_hash');
    #print "$cmd\n" unless $QUIET;
    if (`$cmd` =~ /\bok\b/) {
        $n = good($n);
    } else {
        $n = bad($n);
    }
}
if ($max_depth == $bad1-1
    and $n == $bad2-1)
{
    # more likely the shell. travis docker ubuntu, mingw e.g.
    print "# Apparently your system(SHELLSTRING) cannot catch stack overflows\n"
      unless QUIET;
    $max_depth = 512;
    $n = 256;
    print "MAX_DEPTH = $max_depth\n" unless QUIET;
}
print "# MAX_DEPTH_HASH = $n\n" unless QUIET;
my $max_depth_hash = $n;

# Previously this calculation was done in the macro, calculate it here
# instead so a user setting of either variable more closely matches
# the limits the use sees.

# be fairly aggressive in trimming this, smoke testing showed
# several apparently random failures here, eg. working in one
# configuration, but not in a very similar configuration.
$max_depth = int(0.6 * $max_depth);
$max_depth_hash = int(0.6 * $max_depth_hash);

my $stack_reserve = $^O eq "MSWin32" ? 32 : 16;
if ($] ge "5.016" && !($^O eq "cygwin" && $ptrsize == 8)) {
    $max_depth -= $stack_reserve;
    $max_depth_hash -= $stack_reserve;
}
else {
    # within the exception we need another stack depth to recursively
    # cleanup the hash
    $max_depth = ($max_depth >> 1) - $stack_reserve;
    $max_depth_hash = ($max_depth_hash >> 1) - $stack_reserve * 2;
}

write_limits($max_depth, $max_depth_hash);

sub write_limits {
    my ($max_depth, $max_depth_hash) = @_;
    print <<EOS;
# bisected by stacksize
\$Storable::recursion_limit = $max_depth
  unless defined \$Storable::recursion_limit;
\$Storable::recursion_limit_hash = $max_depth_hash
  unless defined \$Storable::recursion_limit_hash;
EOS
}



( run in 2.265 seconds using v1.01-cache-2.11-cpan-364913b4093 )