From: Robin Houston Date: Sun, 2 Apr 2006 17:20:24 +0000 (+0100) Subject: Prevent "use sort 'stable'" from reversing the order X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f4f44d658c5179458c57c4af43429aac25bf8546;p=p5sagit%2Fp5-mst-13.2.git Prevent "use sort 'stable'" from reversing the order Message-ID: <20060402162024.GA3854@rpc142.cs.man.ac.uk> p4raw-id: //depot/perl@27689 --- diff --git a/lib/sort.t b/lib/sort.t index 62c5529..ca809b0 100644 --- a/lib/sort.t +++ b/lib/sort.t @@ -26,7 +26,7 @@ use strict; use warnings; use Test::More tests => @TestSizes * 2 # sort() tests - * 4 # number of pragmas to test + * 6 # number of pragmas to test + 1 # extra test for qsort instability + 3 # tests for sort::current + 3; # tests for "defaults" and "no sort" @@ -163,16 +163,19 @@ main(sub { sort {&{$_[0]}} @{$_[1]} }, 0); no sort qw(_qsort); my $sort_current; BEGIN { $sort_current = sort::current(); } is($sort_current, 'stable', 'sort::current after no _qsort'); + main(sub { sort {&{$_[0]}} @{$_[1]} }, 0); } { use sort qw(defaults _qsort); my $sort_current; BEGIN { $sort_current = sort::current(); } is($sort_current, 'quicksort', 'sort::current after defaults _qsort'); + # Not expected to be stable, so don't test for stability here } { use sort qw(defaults stable); my $sort_current; BEGIN { $sort_current = sort::current(); } is($sort_current, 'stable', 'sort::current after defaults stable'); + main(sub { sort {&{$_[0]}} @{$_[1]} }, 0); } diff --git a/pp_sort.c b/pp_sort.c index 6e03d0e..aa1fe80 100644 --- a/pp_sort.c +++ b/pp_sort.c @@ -363,7 +363,7 @@ S_mergesortsv(pTHX_ gptr *base, size_t nmemb, SVCOMPARE_t cmp, U32 flags) if (nmemb <= 1) return; /* sorted trivially */ - if (flags) { + if ((flags & SORTf_DESC) != 0) { savecmp = PL_sort_RealCmp; /* Save current comparison routine, if any */ PL_sort_RealCmp = cmp; /* Put comparison routine where cmp_desc can find it */ cmp = cmp_desc;