Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit33b2a2c

Browse files
committed
Fix statically allocated struct with FLEXIBLE_ARRAY_MEMBER member.
clang complains about this, not unreasonably, so define another structthat's explicitly for a WordEntryPos with exactly one element.While at it, get rid of pretty dubious use of a static variable formore than one purpose --- if it were being treated as const maybeI'd be okay with this, but it isn't.
1 parent33a3b03 commit33b2a2c

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

‎src/backend/utils/adt/tsrank.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -195,16 +195,12 @@ SortAndUniqItems(TSQuery q, int *size)
195195
returnres;
196196
}
197197

198-
/* A dummy WordEntryPos array to use when haspos is false */
199-
staticWordEntryPosVectorPOSNULL= {
200-
1,/* Number of elements that follow */
201-
{0}
202-
};
203-
204198
staticfloat
205199
calc_rank_and(constfloat*w,TSVectort,TSQueryq)
206200
{
207201
WordEntryPosVector**pos;
202+
WordEntryPosVector1posnull;
203+
WordEntryPosVector*POSNULL;
208204
inti,
209205
k,
210206
l,
@@ -228,7 +224,12 @@ calc_rank_and(const float *w, TSVector t, TSQuery q)
228224
returncalc_rank_or(w,t,q);
229225
}
230226
pos= (WordEntryPosVector**)palloc0(sizeof(WordEntryPosVector*)*q->size);
231-
WEP_SETPOS(POSNULL.pos[0],MAXENTRYPOS-1);
227+
228+
/* A dummy WordEntryPos array to use when haspos is false */
229+
posnull.npos=1;
230+
posnull.pos[0]=0;
231+
WEP_SETPOS(posnull.pos[0],MAXENTRYPOS-1);
232+
POSNULL= (WordEntryPosVector*)&posnull;
232233

233234
for (i=0;i<size;i++)
234235
{
@@ -241,7 +242,7 @@ calc_rank_and(const float *w, TSVector t, TSQuery q)
241242
if (entry->haspos)
242243
pos[i]=_POSVECPTR(t,entry);
243244
else
244-
pos[i]=&POSNULL;
245+
pos[i]=POSNULL;
245246

246247
dimt=pos[i]->npos;
247248
post=pos[i]->pos;
@@ -256,7 +257,7 @@ calc_rank_and(const float *w, TSVector t, TSQuery q)
256257
for (p=0;p<lenct;p++)
257258
{
258259
dist=Abs((int)WEP_GETPOS(post[l])- (int)WEP_GETPOS(ct[p]));
259-
if (dist|| (dist==0&& (pos[i]==&POSNULL||pos[k]==&POSNULL)))
260+
if (dist|| (dist==0&& (pos[i]==POSNULL||pos[k]==POSNULL)))
260261
{
261262
floatcurw;
262263

@@ -282,6 +283,7 @@ calc_rank_or(const float *w, TSVector t, TSQuery q)
282283
{
283284
WordEntry*entry,
284285
*firstentry;
286+
WordEntryPosVector1posnull;
285287
WordEntryPos*post;
286288
int32dimt,
287289
j,
@@ -291,6 +293,10 @@ calc_rank_or(const float *w, TSVector t, TSQuery q)
291293
QueryOperand**item;
292294
intsize=q->size;
293295

296+
/* A dummy WordEntryPos array to use when haspos is false */
297+
posnull.npos=1;
298+
posnull.pos[0]=0;
299+
294300
item=SortAndUniqItems(q,&size);
295301

296302
for (i=0;i<size;i++)
@@ -312,8 +318,8 @@ calc_rank_or(const float *w, TSVector t, TSQuery q)
312318
}
313319
else
314320
{
315-
dimt=POSNULL.npos;
316-
post=POSNULL.pos;
321+
dimt=posnull.npos;
322+
post=posnull.pos;
317323
}
318324

319325
resj=0.0;

‎src/include/tsearch/ts_type.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ typedef struct
6666
WordEntryPospos[FLEXIBLE_ARRAY_MEMBER];
6767
}WordEntryPosVector;
6868

69+
/* WordEntryPosVector with exactly 1 entry */
70+
typedefstruct
71+
{
72+
uint16npos;
73+
WordEntryPospos[1];
74+
}WordEntryPosVector1;
75+
6976

7077
#defineWEP_GETWEIGHT(x)( (x) >> 14 )
7178
#defineWEP_GETPOS(x)( (x) & 0x3fff )

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp