From: Gurusamy Sarathy Date: Sun, 19 Mar 2000 05:27:31 +0000 (+0000) Subject: fix sort optimizer to not hang inside loops X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=71a29c3c6e68e84b4c2fa366c4878918712829a9;p=p5sagit%2Fp5-mst-13.2.git fix sort optimizer to not hang inside loops p4raw-id: //depot/perl@5815 --- diff --git a/op.c b/op.c index d162595..97d2e4b 100644 --- a/op.c +++ b/op.c @@ -5999,6 +5999,12 @@ Perl_ck_sort(pTHX_ OP *o) for (k = kLISTOP->op_first->op_next; k; k = k->op_next) { if (k->op_next == kid) k->op_next = 0; + /* don't descend into loops */ + else if (k->op_type == OP_ENTERLOOP + || k->op_type == OP_ENTERITER) + { + k = cLOOPx(k)->op_lastop; + } } } else diff --git a/t/op/sort.t b/t/op/sort.t index 794b1f2..ba0a4c2 100755 --- a/t/op/sort.t +++ b/t/op/sort.t @@ -13,6 +13,15 @@ print "1..49\n"; $ENV{PERL_DESTRUCT_LEVEL} = 0 unless $ENV{PERL_DESTRUCT_LEVEL} > 3; } +# these shouldn't hang +{ + no warnings; + sort { for ($_ = 0;; $_++) {} } @a; + sort { while(1) {} } @a; + sort { while(1) { last; } } @a; + sort { while(0) { last; } } @a; +} + sub Backwards { $a lt $b ? 1 : $a gt $b ? -1 : 0 } sub Backwards_stacked($$) { my($a,$b) = @_; $a lt $b ? 1 : $a gt $b ? -1 : 0 }