From: Graham Knop Date: Tue, 15 Mar 2016 21:46:31 +0000 (-0400) Subject: use a hash rather than array for finalizers to fix segfault X-Git-Tag: v0.26~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7cdef625acbd0b276c4e3d403d1b88fb01957ea2;p=p5sagit%2FTry-Tiny.git use a hash rather than array for finalizers to fix segfault Localizing an array entry causes segfaults when creating a pseudofork on Win32 perl < 5.20. --- diff --git a/lib/Try/Tiny.pm b/lib/Try/Tiny.pm index d412758..7c09cbd 100644 --- a/lib/Try/Tiny.pm +++ b/lib/Try/Tiny.pm @@ -29,7 +29,7 @@ BEGIN { *_HAS_SUBNAME = ($su || $sn) ? sub(){1} : sub(){0}; } -my @_finally_guards; +my %_finally_guards; # Need to prototype as @ not $$ because of the way Perl evaluates the prototype. # Keeping it at $$ means you only ever get 1 sub because we need to eval in a list @@ -78,7 +78,7 @@ sub try (&;@) { # this should really be a function scope lexical variable instead of # file scope + local but that causes issues with perls < 5.20 due to # perl rt#119311 - local $_finally_guards[0] = [ + local $_finally_guards{guards} = [ map { Try::Tiny::ScopeGuard->_new($_) } @finally ]; @@ -114,7 +114,7 @@ sub try (&;@) { # destructor overwrote $@ as the eval was unwinding. if ( $failed ) { # pass $error to the finally blocks - push @$_, $error for @{$_finally_guards[0]}; + push @$_, $error for @{$_finally_guards{guards}}; # if we got an error, invoke the catch block. if ( $catch ) {