mirror of
https://github.com/reactos/reactos.git
synced 2025-07-29 21:12:32 +00:00
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 svn path=/trunk/; revision=34396
This commit is contained in:
parent
5a9807ee6c
commit
0461306bc8
4 changed files with 48 additions and 47 deletions
|
@ -267,6 +267,7 @@
|
||||||
<file>mbstowcs.c</file>
|
<file>mbstowcs.c</file>
|
||||||
<file>obsol.c</file>
|
<file>obsol.c</file>
|
||||||
<file>putenv.c</file>
|
<file>putenv.c</file>
|
||||||
|
<file>qsort.c</file>
|
||||||
<file>rot.c</file>
|
<file>rot.c</file>
|
||||||
<file>senv.c</file>
|
<file>senv.c</file>
|
||||||
<file>swab.c</file>
|
<file>swab.c</file>
|
||||||
|
|
|
@ -27,12 +27,6 @@ typedef struct _ThreadData
|
||||||
|
|
||||||
int fpecode; /* fp exception code */
|
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 */
|
EXCEPTION_RECORD *exc_record; /* Head of exception record list */
|
||||||
|
|
||||||
} THREADDATA, *PTHREADDATA;
|
} THREADDATA, *PTHREADDATA;
|
||||||
|
|
|
@ -54,6 +54,7 @@
|
||||||
</directory>
|
</directory>
|
||||||
</if>
|
</if>
|
||||||
<file>abs.c</file>
|
<file>abs.c</file>
|
||||||
|
<file>div.c</file>
|
||||||
<file>labs.c</file>
|
<file>labs.c</file>
|
||||||
<file>rand_nt.c</file>
|
<file>rand_nt.c</file>
|
||||||
</directory>
|
</directory>
|
||||||
|
@ -83,6 +84,10 @@
|
||||||
<file>lfind.c</file>
|
<file>lfind.c</file>
|
||||||
</directory>
|
</directory>
|
||||||
|
|
||||||
|
<directory name="stdlib">
|
||||||
|
<file>qsort.c</file>
|
||||||
|
</directory>
|
||||||
|
|
||||||
<directory name="string">
|
<directory name="string">
|
||||||
<if property="ARCH" value="i386">
|
<if property="ARCH" value="i386">
|
||||||
<directory name="i386">
|
<directory name="i386">
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <search.h>
|
#include <search.h>
|
||||||
#include <internal/tls.h>
|
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1980, 1983 The Regents of the University of California.
|
* Copyright (c) 1980, 1983 The Regents of the University of California.
|
||||||
|
@ -51,12 +50,17 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void
|
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;
|
char c, *i, *j, *jj;
|
||||||
int ii;
|
int ii;
|
||||||
char *mid, *tmp;
|
char *mid, *tmp;
|
||||||
int lo, hi;
|
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
|
* At the top here, lo is the number of characters of elements in the
|
||||||
|
@ -69,20 +73,20 @@ qst(PTHREADDATA pThreadData, char *base, char *max)
|
||||||
*/
|
*/
|
||||||
lo = max - base; /* number of elements as chars */
|
lo = max - base; /* number of elements as chars */
|
||||||
do {
|
do {
|
||||||
mid = i = base + pThreadData->qsz * ((lo / pThreadData->qsz) >> 1);
|
mid = i = base + size * ((lo / size) >> 1);
|
||||||
if (lo >= pThreadData->mthresh)
|
if (lo >= mthresh)
|
||||||
{
|
{
|
||||||
j = (pThreadData->qcmp((jj = base), i) > 0 ? jj : i);
|
j = (compar((jj = base), i) > 0 ? jj : i);
|
||||||
if (pThreadData->qcmp(j, (tmp = max - pThreadData->qsz)) > 0)
|
if (compar(j, (tmp = max - size)) > 0)
|
||||||
{
|
{
|
||||||
/* switch to first loser */
|
/* switch to first loser */
|
||||||
j = (j == jj ? i : jj);
|
j = (j == jj ? i : jj);
|
||||||
if (pThreadData->qcmp(j, tmp) < 0)
|
if (compar(j, tmp) < 0)
|
||||||
j = tmp;
|
j = tmp;
|
||||||
}
|
}
|
||||||
if (j != i)
|
if (j != i)
|
||||||
{
|
{
|
||||||
ii = pThreadData->qsz;
|
ii = size;
|
||||||
do {
|
do {
|
||||||
c = *i;
|
c = *i;
|
||||||
*i++ = *j;
|
*i++ = *j;
|
||||||
|
@ -93,18 +97,18 @@ qst(PTHREADDATA pThreadData, char *base, char *max)
|
||||||
/*
|
/*
|
||||||
* Semi-standard quicksort partitioning/swapping
|
* Semi-standard quicksort partitioning/swapping
|
||||||
*/
|
*/
|
||||||
for (i = base, j = max - pThreadData->qsz; ; )
|
for (i = base, j = max - size; ; )
|
||||||
{
|
{
|
||||||
while (i < mid && pThreadData->qcmp(i, mid) <= 0)
|
while (i < mid && compar(i, mid) <= 0)
|
||||||
i += pThreadData->qsz;
|
i += size;
|
||||||
while (j > mid)
|
while (j > mid)
|
||||||
{
|
{
|
||||||
if (pThreadData->qcmp(mid, j) <= 0)
|
if (compar(mid, j) <= 0)
|
||||||
{
|
{
|
||||||
j -= pThreadData->qsz;
|
j -= size;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
tmp = i + pThreadData->qsz; /* value of i after swap */
|
tmp = i + size; /* value of i after swap */
|
||||||
if (i == mid)
|
if (i == mid)
|
||||||
{
|
{
|
||||||
/* j <-> mid, new mid is j */
|
/* j <-> mid, new mid is j */
|
||||||
|
@ -114,7 +118,7 @@ qst(PTHREADDATA pThreadData, char *base, char *max)
|
||||||
{
|
{
|
||||||
/* i <-> j */
|
/* i <-> j */
|
||||||
jj = j;
|
jj = j;
|
||||||
j -= pThreadData->qsz;
|
j -= size;
|
||||||
}
|
}
|
||||||
goto swap;
|
goto swap;
|
||||||
}
|
}
|
||||||
|
@ -127,10 +131,10 @@ qst(PTHREADDATA pThreadData, char *base, char *max)
|
||||||
/* i <-> mid, new mid is i */
|
/* i <-> mid, new mid is i */
|
||||||
jj = mid;
|
jj = mid;
|
||||||
tmp = mid = i; /* value of i after swap */
|
tmp = mid = i; /* value of i after swap */
|
||||||
j -= pThreadData->qsz;
|
j -= size;
|
||||||
}
|
}
|
||||||
swap:
|
swap:
|
||||||
ii = pThreadData->qsz;
|
ii = size;
|
||||||
do {
|
do {
|
||||||
c = *i;
|
c = *i;
|
||||||
*i++ = *jj;
|
*i++ = *jj;
|
||||||
|
@ -146,21 +150,21 @@ qst(PTHREADDATA pThreadData, char *base, char *max)
|
||||||
* (recursively or by branching) if the partition is
|
* (recursively or by branching) if the partition is
|
||||||
* of at least size THRESH.
|
* of at least size THRESH.
|
||||||
*/
|
*/
|
||||||
i = (j = mid) + pThreadData->qsz;
|
i = (j = mid) + size;
|
||||||
if ((lo = j - base) <= (hi = max - i))
|
if ((lo = j - base) <= (hi = max - i))
|
||||||
{
|
{
|
||||||
if (lo >= pThreadData->thresh)
|
if (lo >= thresh)
|
||||||
qst(pThreadData, base, j);
|
qst(size, compar, base, j);
|
||||||
base = i;
|
base = i;
|
||||||
lo = hi;
|
lo = hi;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (hi >= pThreadData->thresh)
|
if (hi >= thresh)
|
||||||
qst(pThreadData, i, max);
|
qst(size, compar, i, max);
|
||||||
max = j;
|
max = j;
|
||||||
}
|
}
|
||||||
} while (lo >= pThreadData->thresh);
|
} while (lo >= thresh);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -174,25 +178,22 @@ qst(PTHREADDATA pThreadData, char *base, char *max)
|
||||||
void
|
void
|
||||||
qsort(void *base0, size_t n, size_t size, int (*compar)(const void*, const void*))
|
qsort(void *base0, size_t n, size_t size, int (*compar)(const void*, const void*))
|
||||||
{
|
{
|
||||||
PTHREADDATA pThreadData;
|
|
||||||
char *base = (char *)base0;
|
char *base = (char *)base0;
|
||||||
char c, *i, *j, *lo, *hi;
|
char c, *i, *j, *lo, *hi;
|
||||||
char *min, *max;
|
char *min, *max;
|
||||||
|
size_t thresh;
|
||||||
|
|
||||||
if (n <= 1)
|
if (n <= 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
pThreadData = GetThreadData();
|
size = size;
|
||||||
|
compar = compar;
|
||||||
pThreadData->qsz = size;
|
thresh = size * THRESH;
|
||||||
pThreadData->qcmp = compar;
|
max = base + n * size;
|
||||||
pThreadData->thresh = pThreadData->qsz * THRESH;
|
|
||||||
pThreadData->mthresh = pThreadData->qsz * MTHRESH;
|
|
||||||
max = base + n * pThreadData->qsz;
|
|
||||||
if (n >= THRESH)
|
if (n >= THRESH)
|
||||||
{
|
{
|
||||||
qst(pThreadData, base, max);
|
qst(size, compar, base, max);
|
||||||
hi = base + pThreadData->thresh;
|
hi = base + thresh;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -204,13 +205,13 @@ qsort(void *base0, size_t n, size_t size, int (*compar)(const void*, const void*
|
||||||
* the first THRESH elements (or the first n if n < THRESH), finding
|
* the first THRESH elements (or the first n if n < THRESH), finding
|
||||||
* the min, and swapping it into the first position.
|
* the min, and swapping it into the first position.
|
||||||
*/
|
*/
|
||||||
for (j = lo = base; (lo += pThreadData->qsz) < hi; )
|
for (j = lo = base; (lo += size) < hi; )
|
||||||
if (pThreadData->qcmp(j, lo) > 0)
|
if (compar(j, lo) > 0)
|
||||||
j = lo;
|
j = lo;
|
||||||
if (j != base)
|
if (j != base)
|
||||||
{
|
{
|
||||||
/* swap j into place */
|
/* swap j into place */
|
||||||
for (i = base, hi = base + pThreadData->qsz; i < hi; )
|
for (i = base, hi = base + size; i < hi; )
|
||||||
{
|
{
|
||||||
c = *j;
|
c = *j;
|
||||||
*j++ = *i;
|
*j++ = *i;
|
||||||
|
@ -224,15 +225,15 @@ qsort(void *base0, size_t n, size_t size, int (*compar)(const void*, const void*
|
||||||
* Then, do the standard insertion sort shift on a character at a time
|
* Then, do the standard insertion sort shift on a character at a time
|
||||||
* basis for each element in the frob.
|
* basis for each element in the frob.
|
||||||
*/
|
*/
|
||||||
for (min = base; (hi = min += pThreadData->qsz) < max; )
|
for (min = base; (hi = min += size) < max; )
|
||||||
{
|
{
|
||||||
while (pThreadData->qcmp(hi -= pThreadData->qsz, min) > 0)
|
while (compar(hi -= size, min) > 0)
|
||||||
/* void */;
|
/* void */;
|
||||||
if ((hi += pThreadData->qsz) != min) {
|
if ((hi += size) != min) {
|
||||||
for (lo = min + pThreadData->qsz; --lo >= min; )
|
for (lo = min + size; --lo >= min; )
|
||||||
{
|
{
|
||||||
c = *lo;
|
c = *lo;
|
||||||
for (i = j = lo; (j -= pThreadData->qsz) >= hi; i = j)
|
for (i = j = lo; (j -= size) >= hi; i = j)
|
||||||
*i = *j;
|
*i = *j;
|
||||||
*i = c;
|
*i = c;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue