From 74775675fc51ac2ea4559a57b45341b158e6e444 Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Sun, 12 May 2013 10:30:38 +0900 Subject: [PATCH] Fixing sort on vectors for comparators other than <. Also applying the dups fix analog to 0d36042bb1c6 for non-< comparators. --- lib/srfi/95/qsort.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/srfi/95/qsort.c b/lib/srfi/95/qsort.c index df8f0fc4..799fa105 100644 --- a/lib/srfi/95/qsort.c +++ b/lib/srfi/95/qsort.c @@ -147,8 +147,6 @@ static void sexp_qsort (sexp ctx, sexp *vec, sexp_sint_t lo, sexp_sint_t hi) { if (diff <= 0) { swap(tmp2, vec[i], vec[j]); j++; - } else if (diff == 0) { - j++; } } swap(tmp, vec[j], vec[hi]); @@ -190,12 +188,12 @@ static sexp sexp_qsort_less (sexp ctx, sexp *vec, } else { a = vec[i]; } - sexp_car(args2) = a; - sexp_car(args1) = b; + sexp_car(args2) = b; + sexp_car(args1) = a; res = sexp_apply(ctx, less, args2); if (sexp_exceptionp(res)) { goto done; - } else if (sexp_truep(res)) { + } else if (sexp_not(res)) { swap(res, vec[i], vec[j]), j++; } else { sexp_car(args2) = b; @@ -247,6 +245,7 @@ static sexp sexp_sort_x (sexp ctx, sexp self, sexp_sint_t n, sexp seq, res = sexp_type_exception(ctx, self, SEXP_PROCEDURE, key); } else { res = sexp_qsort_less(ctx, data, 0, len-1, less, key); + if (!sexp_exceptionp(res)) res = vec; } }