In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/8e7d0c4b4f9a32461518a61c3643c060cadc7b52?hp=65efc2f779afe1f849b3400dfd17c33f7f829604>
- Log ----------------------------------------------------------------- commit 8e7d0c4b4f9a32461518a61c3643c060cadc7b52 Author: Father Chrysostomos <[email protected]> Date: Mon Sep 20 10:23:35 2010 +0200 [perl #77930] cx_stack reallocation during sort Reset cx in pp_sort before POPSUB, as the pointer may no longer be valid. ----------------------------------------------------------------------- Summary of changes: pp_sort.c | 3 +++ t/op/sort.t | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletions(-) diff --git a/pp_sort.c b/pp_sort.c index f1ec82a..f96d568 100644 --- a/pp_sort.c +++ b/pp_sort.c @@ -1679,6 +1679,9 @@ PP(pp_sort) if (!(flags & OPf_SPECIAL)) { SV *sv; + /* Reset cx, in case the context stack has been + reallocated. */ + cx = &cxstack[cxstack_ix]; POPSUB(cx, sv); LEAVESUB(sv); } diff --git a/t/op/sort.t b/t/op/sort.t index f92cc95..59b8321 100644 --- a/t/op/sort.t +++ b/t/op/sort.t @@ -6,7 +6,7 @@ BEGIN { require 'test.pl'; } use warnings; -plan( tests => 159 ); +plan( tests => 160 ); # these shouldn't hang { @@ -890,3 +890,21 @@ fresh_perl_is('sub w ($$) {my ($l, my $r) = @_; my $v = \...@_; undef @_; @_ = 0..2 is($count, 0, 'all gone'); } + +# [perl #77930] The context stack may be reallocated during a sort, as a +# result of deeply-nested (or not-so-deeply-nested) calls +# from a custom sort subroutine. +fresh_perl_is + ' + $sub = sub { + local $count = $count+1; + ()->$sub if $count < 1000; + $a cmp $b + }; + () = sort $sub qw<a b c d e f g>; + print "ok" + ', + 'ok', + {}, + '[perl #_____] cx_stack reallocation during sort' +; -- Perl5 Master Repository
