Change 27689 by [EMAIL PROTECTED] on 2006/04/02 21:13:16

        Subject: [PATCH] Prevent "use sort 'stable'" from reversing the order
        From: Robin Houston <[EMAIL PROTECTED]>
        Date: Sun, 2 Apr 2006 17:20:24 +0100
        Message-ID: <[EMAIL PROTECTED]>

Affected files ...

... //depot/perl/lib/sort.t#10 edit
... //depot/perl/pp_sort.c#69 edit

Differences ...

==== //depot/perl/lib/sort.t#10 (text) ====
Index: perl/lib/sort.t
--- perl/lib/sort.t#9~26402~    2005-12-19 10:17:19.000000000 -0800
+++ perl/lib/sort.t     2006-04-02 14:13:16.000000000 -0700
@@ -26,7 +26,7 @@
 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 @@
     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);
 }

==== //depot/perl/pp_sort.c#69 (text) ====
Index: perl/pp_sort.c
--- perl/pp_sort.c#68~27641~    2006-03-31 04:30:31.000000000 -0800
+++ perl/pp_sort.c      2006-04-02 14:13:16.000000000 -0700
@@ -363,7 +363,7 @@
 
     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;
End of Patch.

Reply via email to