From 0f629f4a2e1191ddf94f9351363909d63b68351d Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Mon, 22 Sep 2025 14:47:48 +0200 Subject: [PATCH 13/23] C11 anonymous unions [tsearch spell] --- src/backend/tsearch/spell.c | 70 +++++++++++++++---------------- src/include/tsearch/dicts/spell.h | 10 ++--- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/backend/tsearch/spell.c b/src/backend/tsearch/spell.c index 146801885d7..ddad17796e4 100644 --- a/src/backend/tsearch/spell.c +++ b/src/backend/tsearch/spell.c @@ -203,8 +203,8 @@ cmpspell(const void *s1, const void *s2) static int cmpspellaffix(const void *s1, const void *s2) { - return strcmp((*(SPELL *const *) s1)->p.flag, - (*(SPELL *const *) s2)->p.flag); + return strcmp((*(SPELL *const *) s1)->flag, + (*(SPELL *const *) s2)->flag); } static int @@ -217,13 +217,13 @@ cmpcmdflag(const void *f1, const void *f2) if (fv1->flagMode == FM_NUM) { - if (fv1->flag.i == fv2->flag.i) + if (fv1->flagNum == fv2->flagNum) return 0; - return (fv1->flag.i > fv2->flag.i) ? 1 : -1; + return (fv1->flagNum > fv2->flagNum) ? 1 : -1; } - return strcmp(fv1->flag.s, fv2->flag.s); + return strcmp(fv1->flagName, fv2->flagName); } static char * @@ -502,7 +502,7 @@ NIAddSpell(IspellDict *Conf, const char *word, const char *flag) } Conf->Spell[Conf->nspell] = (SPELL *) tmpalloc(SPELLHDRSZ + strlen(word) + 1); strcpy(Conf->Spell[Conf->nspell]->word, word); - Conf->Spell[Conf->nspell]->p.flag = (*flag != '\0') + Conf->Spell[Conf->nspell]->flag = (*flag != '\0') ? cpstrdup(Conf, flag) : VoidString; Conf->nspell++; } @@ -708,7 +708,7 @@ NIAddAffix(IspellDict *Conf, const char *flag, char flagflags, const char *mask, { Affix->issimple = 0; Affix->isregis = 1; - RS_compile(&(Affix->reg.regis), (type == FF_SUFFIX), + RS_compile(&(Affix->regis), (type == FF_SUFFIX), *mask ? mask : VoidString); } /* This affix rule will use regex_t to search word ending */ @@ -737,15 +737,15 @@ NIAddAffix(IspellDict *Conf, const char *flag, char flagflags, const char *mask, * allocated in the dictionary's memory context, and will be freed * automatically when it is destroyed. */ - Affix->reg.pregex = palloc(sizeof(regex_t)); - err = pg_regcomp(Affix->reg.pregex, wmask, wmasklen, + Affix->pregex = palloc(sizeof(regex_t)); + err = pg_regcomp(Affix->pregex, wmask, wmasklen, REG_ADVANCED | REG_NOSUB, DEFAULT_COLLATION_OID); if (err) { char errstr[100]; - pg_regerror(err, Affix->reg.pregex, errstr, sizeof(errstr)); + pg_regerror(err, Affix->pregex, errstr, sizeof(errstr)); ereport(ERROR, (errcode(ERRCODE_INVALID_REGULAR_EXPRESSION), errmsg("invalid regular expression: %s", errstr))); @@ -1049,10 +1049,10 @@ setCompoundAffixFlagValue(IspellDict *Conf, CompoundAffixFlag *entry, (errcode(ERRCODE_CONFIG_FILE_ERROR), errmsg("affix flag \"%s\" is out of range", s))); - entry->flag.i = i; + entry->flagNum = i; } else - entry->flag.s = cpstrdup(Conf, s); + entry->flagName = cpstrdup(Conf, s); entry->flagMode = Conf->flagMode; entry->value = val; @@ -1651,7 +1651,7 @@ mkSPNode(IspellDict *Conf, int low, int high, int level) int lownew = low; for (i = low; i < high; i++) - if (Conf->Spell[i]->p.d.len > level && lastchar != Conf->Spell[i]->word[level]) + if (Conf->Spell[i]->d.len > level && lastchar != Conf->Spell[i]->word[level]) { nchar++; lastchar = Conf->Spell[i]->word[level]; @@ -1666,7 +1666,7 @@ mkSPNode(IspellDict *Conf, int low, int high, int level) lastchar = '\0'; for (i = low; i < high; i++) - if (Conf->Spell[i]->p.d.len > level) + if (Conf->Spell[i]->d.len > level) { if (lastchar != Conf->Spell[i]->word[level]) { @@ -1680,11 +1680,11 @@ mkSPNode(IspellDict *Conf, int low, int high, int level) lastchar = Conf->Spell[i]->word[level]; } data->val = ((uint8 *) (Conf->Spell[i]->word))[level]; - if (Conf->Spell[i]->p.d.len == level + 1) + if (Conf->Spell[i]->d.len == level + 1) { bool clearCompoundOnly = false; - if (data->isword && data->affix != Conf->Spell[i]->p.d.affix) + if (data->isword && data->affix != Conf->Spell[i]->d.affix) { /* * MergeAffix called a few times. If one of word is @@ -1693,12 +1693,12 @@ mkSPNode(IspellDict *Conf, int low, int high, int level) */ clearCompoundOnly = (FF_COMPOUNDONLY & data->compoundflag - & makeCompoundFlags(Conf, Conf->Spell[i]->p.d.affix)) + & makeCompoundFlags(Conf, Conf->Spell[i]->d.affix)) ? false : true; - data->affix = MergeAffix(Conf, data->affix, Conf->Spell[i]->p.d.affix); + data->affix = MergeAffix(Conf, data->affix, Conf->Spell[i]->d.affix); } else - data->affix = Conf->Spell[i]->p.d.affix; + data->affix = Conf->Spell[i]->d.affix; data->isword = 1; data->compoundflag = makeCompoundFlags(Conf, data->affix); @@ -1741,37 +1741,37 @@ NISortDictionary(IspellDict *Conf) { char *end; - if (*Conf->Spell[i]->p.flag != '\0') + if (*Conf->Spell[i]->flag != '\0') { errno = 0; - curaffix = strtol(Conf->Spell[i]->p.flag, &end, 10); - if (Conf->Spell[i]->p.flag == end || errno == ERANGE) + curaffix = strtol(Conf->Spell[i]->flag, &end, 10); + if (Conf->Spell[i]->flag == end || errno == ERANGE) ereport(ERROR, (errcode(ERRCODE_CONFIG_FILE_ERROR), errmsg("invalid affix alias \"%s\"", - Conf->Spell[i]->p.flag))); + Conf->Spell[i]->flag))); if (curaffix < 0 || curaffix >= Conf->nAffixData) ereport(ERROR, (errcode(ERRCODE_CONFIG_FILE_ERROR), errmsg("invalid affix alias \"%s\"", - Conf->Spell[i]->p.flag))); + Conf->Spell[i]->flag))); if (*end != '\0' && !isdigit((unsigned char) *end) && !isspace((unsigned char) *end)) ereport(ERROR, (errcode(ERRCODE_CONFIG_FILE_ERROR), errmsg("invalid affix alias \"%s\"", - Conf->Spell[i]->p.flag))); + Conf->Spell[i]->flag))); } else { /* - * If Conf->Spell[i]->p.flag is empty, then get empty value of + * If Conf->Spell[i]->flag is empty, then get empty value of * Conf->AffixData (0 index). */ curaffix = 0; } - Conf->Spell[i]->p.d.affix = curaffix; - Conf->Spell[i]->p.d.len = strlen(Conf->Spell[i]->word); + Conf->Spell[i]->d.affix = curaffix; + Conf->Spell[i]->d.len = strlen(Conf->Spell[i]->word); } } /* Otherwise fill Conf->AffixData here */ @@ -1785,7 +1785,7 @@ NISortDictionary(IspellDict *Conf) for (i = 0; i < Conf->nspell; i++) { if (i == 0 || - strcmp(Conf->Spell[i]->p.flag, Conf->Spell[i - 1]->p.flag) != 0) + strcmp(Conf->Spell[i]->flag, Conf->Spell[i - 1]->flag) != 0) naffix++; } @@ -1800,16 +1800,16 @@ NISortDictionary(IspellDict *Conf) for (i = 0; i < Conf->nspell; i++) { if (i == 0 || - strcmp(Conf->Spell[i]->p.flag, Conf->AffixData[curaffix]) != 0) + strcmp(Conf->Spell[i]->flag, Conf->AffixData[curaffix]) != 0) { curaffix++; Assert(curaffix < naffix); Conf->AffixData[curaffix] = cpstrdup(Conf, - Conf->Spell[i]->p.flag); + Conf->Spell[i]->flag); } - Conf->Spell[i]->p.d.affix = curaffix; - Conf->Spell[i]->p.d.len = strlen(Conf->Spell[i]->word); + Conf->Spell[i]->d.affix = curaffix; + Conf->Spell[i]->d.len = strlen(Conf->Spell[i]->word); } Conf->lenAffixData = Conf->nAffixData = naffix; @@ -2136,7 +2136,7 @@ CheckAffix(const char *word, size_t len, AFFIX *Affix, int flagflags, char *neww return newword; else if (Affix->isregis) { - if (RS_execute(&(Affix->reg.regis), newword)) + if (RS_execute(&(Affix->regis), newword)) return newword; } else @@ -2150,7 +2150,7 @@ CheckAffix(const char *word, size_t len, AFFIX *Affix, int flagflags, char *neww data = (pg_wchar *) palloc((newword_len + 1) * sizeof(pg_wchar)); data_len = pg_mb2wchar_with_len(newword, data, newword_len); - if (pg_regexec(Affix->reg.pregex, data, data_len, + if (pg_regexec(Affix->pregex, data, data_len, 0, NULL, 0, NULL, 0) == REG_OKAY) { pfree(data); diff --git a/src/include/tsearch/dicts/spell.h b/src/include/tsearch/dicts/spell.h index 919b7df6370..7ce7086e6df 100644 --- a/src/include/tsearch/dicts/spell.h +++ b/src/include/tsearch/dicts/spell.h @@ -75,7 +75,7 @@ typedef struct spell_struct /* Length of the word */ int len; } d; - } p; + }; char word[FLEXIBLE_ARRAY_MEMBER]; } SPELL; @@ -104,7 +104,7 @@ typedef struct aff_struct */ regex_t *pregex; Regis regis; - } reg; + }; } AFFIX; /* @@ -170,10 +170,10 @@ typedef struct CompoundAffixFlag union { /* Flag name if flagMode is FM_CHAR or FM_LONG */ - const char *s; + const char *flagName; /* Flag name if flagMode is FM_NUM */ - uint32 i; - } flag; + uint32 flagNum; + }; /* we don't have a bsearch_arg version, so, copy FlagMode */ FlagMode flagMode; uint32 value; -- 2.51.0