Author: hyperion Date: Wed Jul 9 13:44:46 2008 New Revision: 34396
URL: http://svn.reactos.org/svn/reactos?rev=34396&view=rev Log: modified lib/sdk/crt/crt.rbuild modified lib/sdk/crt/libcntpr.rbuild Add qsort and div to crt and libcntpr
modified lib/sdk/crt/include/internal/tls.h modified lib/sdk/crt/stdlib/qsort.c Fixed ineptly-ported DJGPP qsort to not use TLS
Modified: trunk/reactos/lib/sdk/crt/crt.rbuild trunk/reactos/lib/sdk/crt/include/internal/tls.h trunk/reactos/lib/sdk/crt/libcntpr.rbuild trunk/reactos/lib/sdk/crt/stdlib/qsort.c
Modified: trunk/reactos/lib/sdk/crt/crt.rbuild URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/crt.rbuild?rev=... ============================================================================== --- trunk/reactos/lib/sdk/crt/crt.rbuild [iso-8859-1] (original) +++ trunk/reactos/lib/sdk/crt/crt.rbuild [iso-8859-1] Wed Jul 9 13:44:46 2008 @@ -267,6 +267,7 @@ <file>mbstowcs.c</file> <file>obsol.c</file> <file>putenv.c</file> + <file>qsort.c</file> <file>rot.c</file> <file>senv.c</file> <file>swab.c</file>
Modified: trunk/reactos/lib/sdk/crt/include/internal/tls.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/include/interna... ============================================================================== --- trunk/reactos/lib/sdk/crt/include/internal/tls.h [iso-8859-1] (original) +++ trunk/reactos/lib/sdk/crt/include/internal/tls.h [iso-8859-1] Wed Jul 9 13:44:46 2008 @@ -27,12 +27,6 @@
int fpecode; /* fp exception code */
- /* qsort variables */ - int (*qcmp)(const void *, const void *); /* the comparison routine */ - int qsz; /* size of each record */ - int thresh; /* THRESHold in chars */ - int mthresh; /* MTHRESHold in chars */ - EXCEPTION_RECORD *exc_record; /* Head of exception record list */
} THREADDATA, *PTHREADDATA;
Modified: trunk/reactos/lib/sdk/crt/libcntpr.rbuild URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/libcntpr.rbuild... ============================================================================== --- trunk/reactos/lib/sdk/crt/libcntpr.rbuild [iso-8859-1] (original) +++ trunk/reactos/lib/sdk/crt/libcntpr.rbuild [iso-8859-1] Wed Jul 9 13:44:46 2008 @@ -54,6 +54,7 @@ </directory> </if> <file>abs.c</file> + <file>div.c</file> <file>labs.c</file> <file>rand_nt.c</file> </directory> @@ -81,6 +82,10 @@ <directory name="search"> <file>bsearch.c</file> <file>lfind.c</file> + </directory> + + <directory name="stdlib"> + <file>qsort.c</file> </directory>
<directory name="string">
Modified: trunk/reactos/lib/sdk/crt/stdlib/qsort.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/stdlib/qsort.c?... ============================================================================== --- trunk/reactos/lib/sdk/crt/stdlib/qsort.c [iso-8859-1] (original) +++ trunk/reactos/lib/sdk/crt/stdlib/qsort.c [iso-8859-1] Wed Jul 9 13:44:46 2008 @@ -2,7 +2,6 @@
#include <stdlib.h> #include <search.h> -#include <internal/tls.h>
/*- * Copyright (c) 1980, 1983 The Regents of the University of California. @@ -51,12 +50,17 @@ */
static void -qst(PTHREADDATA pThreadData, char *base, char *max) +qst(size_t size, int (*compar)(const void*, const void*), char *base, char *max) { char c, *i, *j, *jj; int ii; char *mid, *tmp; int lo, hi; + size_t thresh; + size_t mthresh; + + thresh = size * THRESH; + mthresh = size * MTHRESH;
/* * At the top here, lo is the number of characters of elements in the @@ -69,20 +73,20 @@ */ lo = max - base; /* number of elements as chars */ do { - mid = i = base + pThreadData->qsz * ((lo / pThreadData->qsz) >> 1); - if (lo >= pThreadData->mthresh) - { - j = (pThreadData->qcmp((jj = base), i) > 0 ? jj : i); - if (pThreadData->qcmp(j, (tmp = max - pThreadData->qsz)) > 0) + mid = i = base + size * ((lo / size) >> 1); + if (lo >= mthresh) + { + j = (compar((jj = base), i) > 0 ? jj : i); + if (compar(j, (tmp = max - size)) > 0) { /* switch to first loser */ j = (j == jj ? i : jj); - if (pThreadData->qcmp(j, tmp) < 0) + if (compar(j, tmp) < 0) j = tmp; } if (j != i) { - ii = pThreadData->qsz; + ii = size; do { c = *i; *i++ = *j; @@ -93,18 +97,18 @@ /* * Semi-standard quicksort partitioning/swapping */ - for (i = base, j = max - pThreadData->qsz; ; ) - { - while (i < mid && pThreadData->qcmp(i, mid) <= 0) - i += pThreadData->qsz; + for (i = base, j = max - size; ; ) + { + while (i < mid && compar(i, mid) <= 0) + i += size; while (j > mid) { - if (pThreadData->qcmp(mid, j) <= 0) + if (compar(mid, j) <= 0) { - j -= pThreadData->qsz; + j -= size; continue; } - tmp = i + pThreadData->qsz; /* value of i after swap */ + tmp = i + size; /* value of i after swap */ if (i == mid) { /* j <-> mid, new mid is j */ @@ -114,7 +118,7 @@ { /* i <-> j */ jj = j; - j -= pThreadData->qsz; + j -= size; } goto swap; } @@ -127,10 +131,10 @@ /* i <-> mid, new mid is i */ jj = mid; tmp = mid = i; /* value of i after swap */ - j -= pThreadData->qsz; + j -= size; } swap: - ii = pThreadData->qsz; + ii = size; do { c = *i; *i++ = *jj; @@ -146,21 +150,21 @@ * (recursively or by branching) if the partition is * of at least size THRESH. */ - i = (j = mid) + pThreadData->qsz; + i = (j = mid) + size; if ((lo = j - base) <= (hi = max - i)) { - if (lo >= pThreadData->thresh) - qst(pThreadData, base, j); + if (lo >= thresh) + qst(size, compar, base, j); base = i; lo = hi; } else { - if (hi >= pThreadData->thresh) - qst(pThreadData, i, max); + if (hi >= thresh) + qst(size, compar, i, max); max = j; } - } while (lo >= pThreadData->thresh); + } while (lo >= thresh); }
/* @@ -174,25 +178,22 @@ void qsort(void *base0, size_t n, size_t size, int (*compar)(const void*, const void*)) { - PTHREADDATA pThreadData; char *base = (char *)base0; char c, *i, *j, *lo, *hi; char *min, *max; + size_t thresh;
if (n <= 1) return;
- pThreadData = GetThreadData(); - - pThreadData->qsz = size; - pThreadData->qcmp = compar; - pThreadData->thresh = pThreadData->qsz * THRESH; - pThreadData->mthresh = pThreadData->qsz * MTHRESH; - max = base + n * pThreadData->qsz; + size = size; + compar = compar; + thresh = size * THRESH; + max = base + n * size; if (n >= THRESH) { - qst(pThreadData, base, max); - hi = base + pThreadData->thresh; + qst(size, compar, base, max); + hi = base + thresh; } else { @@ -204,13 +205,13 @@ * the first THRESH elements (or the first n if n < THRESH), finding * the min, and swapping it into the first position. */ - for (j = lo = base; (lo += pThreadData->qsz) < hi; ) - if (pThreadData->qcmp(j, lo) > 0) + for (j = lo = base; (lo += size) < hi; ) + if (compar(j, lo) > 0) j = lo; if (j != base) { /* swap j into place */ - for (i = base, hi = base + pThreadData->qsz; i < hi; ) + for (i = base, hi = base + size; i < hi; ) { c = *j; *j++ = *i; @@ -224,15 +225,15 @@ * Then, do the standard insertion sort shift on a character at a time * basis for each element in the frob. */ - for (min = base; (hi = min += pThreadData->qsz) < max; ) - { - while (pThreadData->qcmp(hi -= pThreadData->qsz, min) > 0) + for (min = base; (hi = min += size) < max; ) + { + while (compar(hi -= size, min) > 0) /* void */; - if ((hi += pThreadData->qsz) != min) { - for (lo = min + pThreadData->qsz; --lo >= min; ) + if ((hi += size) != min) { + for (lo = min + size; --lo >= min; ) { c = *lo; - for (i = j = lo; (j -= pThreadData->qsz) >= hi; i = j) + for (i = j = lo; (j -= size) >= hi; i = j) *i = *j; *i = c; }