Fix statically allocated struct with FLEXIBLE_ARRAY_MEMBER member.
clang complains about this, not unreasonably, so define another struct that's explicitly for a WordEntryPos with exactly one element. While at it, get rid of pretty dubious use of a static variable for more than one purpose --- if it were being treated as const maybe I'd be okay with this, but it isn't.
This commit is contained in:
parent
33a3b03d63
commit
33b2a2c97f
@ -195,16 +195,12 @@ SortAndUniqItems(TSQuery q, int *size)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* A dummy WordEntryPos array to use when haspos is false */
|
|
||||||
static WordEntryPosVector POSNULL = {
|
|
||||||
1, /* Number of elements that follow */
|
|
||||||
{0}
|
|
||||||
};
|
|
||||||
|
|
||||||
static float
|
static float
|
||||||
calc_rank_and(const float *w, TSVector t, TSQuery q)
|
calc_rank_and(const float *w, TSVector t, TSQuery q)
|
||||||
{
|
{
|
||||||
WordEntryPosVector **pos;
|
WordEntryPosVector **pos;
|
||||||
|
WordEntryPosVector1 posnull;
|
||||||
|
WordEntryPosVector *POSNULL;
|
||||||
int i,
|
int i,
|
||||||
k,
|
k,
|
||||||
l,
|
l,
|
||||||
@ -228,7 +224,12 @@ calc_rank_and(const float *w, TSVector t, TSQuery q)
|
|||||||
return calc_rank_or(w, t, q);
|
return calc_rank_or(w, t, q);
|
||||||
}
|
}
|
||||||
pos = (WordEntryPosVector **) palloc0(sizeof(WordEntryPosVector *) * q->size);
|
pos = (WordEntryPosVector **) palloc0(sizeof(WordEntryPosVector *) * q->size);
|
||||||
WEP_SETPOS(POSNULL.pos[0], MAXENTRYPOS - 1);
|
|
||||||
|
/* A dummy WordEntryPos array to use when haspos is false */
|
||||||
|
posnull.npos = 1;
|
||||||
|
posnull.pos[0] = 0;
|
||||||
|
WEP_SETPOS(posnull.pos[0], MAXENTRYPOS - 1);
|
||||||
|
POSNULL = (WordEntryPosVector *) &posnull;
|
||||||
|
|
||||||
for (i = 0; i < size; i++)
|
for (i = 0; i < size; i++)
|
||||||
{
|
{
|
||||||
@ -241,7 +242,7 @@ calc_rank_and(const float *w, TSVector t, TSQuery q)
|
|||||||
if (entry->haspos)
|
if (entry->haspos)
|
||||||
pos[i] = _POSVECPTR(t, entry);
|
pos[i] = _POSVECPTR(t, entry);
|
||||||
else
|
else
|
||||||
pos[i] = &POSNULL;
|
pos[i] = POSNULL;
|
||||||
|
|
||||||
dimt = pos[i]->npos;
|
dimt = pos[i]->npos;
|
||||||
post = pos[i]->pos;
|
post = pos[i]->pos;
|
||||||
@ -256,7 +257,7 @@ calc_rank_and(const float *w, TSVector t, TSQuery q)
|
|||||||
for (p = 0; p < lenct; p++)
|
for (p = 0; p < lenct; p++)
|
||||||
{
|
{
|
||||||
dist = Abs((int) WEP_GETPOS(post[l]) - (int) WEP_GETPOS(ct[p]));
|
dist = Abs((int) WEP_GETPOS(post[l]) - (int) WEP_GETPOS(ct[p]));
|
||||||
if (dist || (dist == 0 && (pos[i] == &POSNULL || pos[k] == &POSNULL)))
|
if (dist || (dist == 0 && (pos[i] == POSNULL || pos[k] == POSNULL)))
|
||||||
{
|
{
|
||||||
float curw;
|
float curw;
|
||||||
|
|
||||||
@ -282,6 +283,7 @@ calc_rank_or(const float *w, TSVector t, TSQuery q)
|
|||||||
{
|
{
|
||||||
WordEntry *entry,
|
WordEntry *entry,
|
||||||
*firstentry;
|
*firstentry;
|
||||||
|
WordEntryPosVector1 posnull;
|
||||||
WordEntryPos *post;
|
WordEntryPos *post;
|
||||||
int32 dimt,
|
int32 dimt,
|
||||||
j,
|
j,
|
||||||
@ -291,6 +293,10 @@ calc_rank_or(const float *w, TSVector t, TSQuery q)
|
|||||||
QueryOperand **item;
|
QueryOperand **item;
|
||||||
int size = q->size;
|
int size = q->size;
|
||||||
|
|
||||||
|
/* A dummy WordEntryPos array to use when haspos is false */
|
||||||
|
posnull.npos = 1;
|
||||||
|
posnull.pos[0] = 0;
|
||||||
|
|
||||||
item = SortAndUniqItems(q, &size);
|
item = SortAndUniqItems(q, &size);
|
||||||
|
|
||||||
for (i = 0; i < size; i++)
|
for (i = 0; i < size; i++)
|
||||||
@ -312,8 +318,8 @@ calc_rank_or(const float *w, TSVector t, TSQuery q)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dimt = POSNULL.npos;
|
dimt = posnull.npos;
|
||||||
post = POSNULL.pos;
|
post = posnull.pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
resj = 0.0;
|
resj = 0.0;
|
||||||
|
@ -66,6 +66,13 @@ typedef struct
|
|||||||
WordEntryPos pos[FLEXIBLE_ARRAY_MEMBER];
|
WordEntryPos pos[FLEXIBLE_ARRAY_MEMBER];
|
||||||
} WordEntryPosVector;
|
} WordEntryPosVector;
|
||||||
|
|
||||||
|
/* WordEntryPosVector with exactly 1 entry */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint16 npos;
|
||||||
|
WordEntryPos pos[1];
|
||||||
|
} WordEntryPosVector1;
|
||||||
|
|
||||||
|
|
||||||
#define WEP_GETWEIGHT(x) ( (x) >> 14 )
|
#define WEP_GETWEIGHT(x) ( (x) >> 14 )
|
||||||
#define WEP_GETPOS(x) ( (x) & 0x3fff )
|
#define WEP_GETPOS(x) ( (x) & 0x3fff )
|
||||||
|
Loading…
x
Reference in New Issue
Block a user