From: Artur Bergman Date: Tue, 14 May 2002 15:21:39 +0000 (+0000) Subject: Turn the sort RealCmp for stable quicksorts into a X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=147f47de4cf0d8224e5bba0fda69d1a6523548a2;p=p5sagit%2Fp5-mst-13.2.git Turn the sort RealCmp for stable quicksorts into a threadsafe per interpreter values. p4raw-id: //depot/perl@16592 --- diff --git a/intrpvar.h b/intrpvar.h index e940163..f98e348 100644 --- a/intrpvar.h +++ b/intrpvar.h @@ -520,6 +520,8 @@ PERLVAR(Iwantutf8, bool) /* want utf8 as the default discipline */ PERLVAR(Iutf8_idstart, SV *) PERLVAR(Iutf8_idcont, SV *) +PERLVAR(Isort_RealCmp, SVCOMPARE_t) + /* New variables must be added to the very end for binary compatibility. * XSUB.h provides wrapper functions via perlapi.h that make this * irrelevant, but not all code may be expected to #include XSUB.h. */ diff --git a/pp_sort.c b/pp_sort.c index 0a50ed5..d2d4bde 100644 --- a/pp_sort.c +++ b/pp_sort.c @@ -1286,7 +1286,6 @@ S_qsortsvu(pTHX_ SV ** array, size_t num_elts, SVCOMPARE_t compare) * dictated by the indirect array. */ -static SVCOMPARE_t RealCmp; static I32 cmpindir(pTHX_ gptr a, gptr b) @@ -1295,7 +1294,7 @@ cmpindir(pTHX_ gptr a, gptr b) gptr *ap = (gptr *)a; gptr *bp = (gptr *)b; - if ((sense = RealCmp(aTHX_ *ap, *bp)) == 0) + if ((sense = PL_sort_RealCmp(aTHX_ *ap, *bp)) == 0) sense = (ap > bp) ? 1 : ((ap < bp) ? -1 : 0); return sense; } @@ -1319,8 +1318,8 @@ S_qsortsv(pTHX_ gptr *list1, size_t nmemb, SVCOMPARE_t cmp) /* Copy pointers to original array elements into indirect array */ for (n = nmemb, pp = indir, q = list1; n--; ) *pp++ = q++; - savecmp = RealCmp; /* Save current comparison routine, if any */ - RealCmp = cmp; /* Put comparison routine where cmpindir can find it */ + savecmp = PL_sort_RealCmp; /* Save current comparison routine, if any */ + PL_sort_RealCmp = cmp; /* Put comparison routine where cmpindir can find it */ /* sort, with indirection */ S_qsortsvu(aTHX_ (gptr *)indir, nmemb, cmpindir); @@ -1365,7 +1364,7 @@ S_qsortsv(pTHX_ gptr *list1, size_t nmemb, SVCOMPARE_t cmp) /* free iff allocated */ if (indir != small) { Safefree(indir); } /* restore prevailing comparison routine */ - RealCmp = savecmp; + PL_sort_RealCmp = savecmp; } else { S_qsortsvu(aTHX_ list1, nmemb, cmp); }