summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pp_sort.c3
-rw-r--r--t/op/sort.t20
2 files changed, 22 insertions, 1 deletions
diff --git a/pp_sort.c b/pp_sort.c
index f1ec82aec2..f96d5682f9 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 f92cc95d9b..59b83214a9 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'
+;