mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
Make use of qsort_arg in several places that were formerly using klugy
static variables. This avoids any risk of potential non-reentrancy, and in particular offers a much cleaner workaround for the Intel compiler bug that was affecting ginutil.c.
This commit is contained in:
@ -122,14 +122,14 @@ find_wordentry(tsvector * t, QUERYTYPE * q, ITEM * item)
|
||||
}
|
||||
|
||||
|
||||
static char *SortAndUniqOperand = NULL;
|
||||
|
||||
static int
|
||||
compareITEM(const void *a, const void *b)
|
||||
compareITEM(const void *a, const void *b, void *arg)
|
||||
{
|
||||
char *operand = (char *) arg;
|
||||
|
||||
if ((*(ITEM **) a)->length == (*(ITEM **) b)->length)
|
||||
return strncmp(SortAndUniqOperand + (*(ITEM **) a)->distance,
|
||||
SortAndUniqOperand + (*(ITEM **) b)->distance,
|
||||
return strncmp(operand + (*(ITEM **) a)->distance,
|
||||
operand + (*(ITEM **) b)->distance,
|
||||
(*(ITEM **) b)->length);
|
||||
|
||||
return ((*(ITEM **) a)->length > (*(ITEM **) b)->length) ? 1 : -1;
|
||||
@ -158,15 +158,14 @@ SortAndUniqItems(char *operand, ITEM * item, int *size)
|
||||
if (*size < 2)
|
||||
return res;
|
||||
|
||||
SortAndUniqOperand = operand;
|
||||
qsort(res, *size, sizeof(ITEM **), compareITEM);
|
||||
qsort_arg(res, *size, sizeof(ITEM **), compareITEM, (void *) operand);
|
||||
|
||||
ptr = res + 1;
|
||||
prevptr = res;
|
||||
|
||||
while (ptr - res < *size)
|
||||
{
|
||||
if (compareITEM((void *) ptr, (void *) prevptr) != 0)
|
||||
if (compareITEM((void *) ptr, (void *) prevptr, (void *) operand) != 0)
|
||||
{
|
||||
prevptr++;
|
||||
*prevptr = *ptr;
|
||||
@ -551,10 +550,11 @@ get_docrep(tsvector * txt, QUERYTYPE * query, int *doclen)
|
||||
int len = query->size * 4,
|
||||
cur = 0;
|
||||
DocRepresentation *doc;
|
||||
char *operand;
|
||||
|
||||
*(uint16 *) POSNULL = lengthof(POSNULL) - 1;
|
||||
doc = (DocRepresentation *) palloc(sizeof(DocRepresentation) * len);
|
||||
SortAndUniqOperand = GETOPERAND(query);
|
||||
operand = GETOPERAND(query);
|
||||
reset_istrue_flag(query);
|
||||
|
||||
for (i = 0; i < query->size; i++)
|
||||
@ -598,7 +598,9 @@ get_docrep(tsvector * txt, QUERYTYPE * query, int *doclen)
|
||||
for (k = 0; k < query->size; k++)
|
||||
{
|
||||
kptr = item + k;
|
||||
if (k == i || (item[k].type == VAL && compareITEM(&kptr, &iptr) == 0))
|
||||
if (k == i ||
|
||||
(item[k].type == VAL &&
|
||||
compareITEM(&kptr, &iptr, operand) == 0))
|
||||
{
|
||||
doc[cur].item[doc[cur].nitem] = item + k;
|
||||
doc[cur].nitem++;
|
||||
|
@ -85,14 +85,14 @@ uniquePos(WordEntryPos * a, int4 l)
|
||||
return res + 1 - a;
|
||||
}
|
||||
|
||||
static char *BufferStr;
|
||||
static int
|
||||
compareentry(const void *a, const void *b)
|
||||
compareentry(const void *a, const void *b, void *arg)
|
||||
{
|
||||
char *BufferStr = (char *) arg;
|
||||
|
||||
if (((WordEntryIN *) a)->entry.len == ((WordEntryIN *) b)->entry.len)
|
||||
{
|
||||
return strncmp(
|
||||
&BufferStr[((WordEntryIN *) a)->entry.pos],
|
||||
return strncmp(&BufferStr[((WordEntryIN *) a)->entry.pos],
|
||||
&BufferStr[((WordEntryIN *) b)->entry.pos],
|
||||
((WordEntryIN *) a)->entry.len);
|
||||
}
|
||||
@ -117,8 +117,7 @@ uniqueentry(WordEntryIN * a, int4 l, char *buf, int4 *outbuflen)
|
||||
}
|
||||
|
||||
ptr = a + 1;
|
||||
BufferStr = buf;
|
||||
qsort((void *) a, l, sizeof(WordEntryIN), compareentry);
|
||||
qsort_arg((void *) a, l, sizeof(WordEntryIN), compareentry, (void *) buf);
|
||||
|
||||
while (ptr - a < l)
|
||||
{
|
||||
|
Reference in New Issue
Block a user