mirror of
https://github.com/postgres/postgres.git
synced 2025-10-22 14:32:25 +03:00
Constify fields and parameters in spell.c
I started by marking VoidString as const, and fixing the fallout by marking more fields and function arguments as const. It proliferated quite a lot, but all within spell.c and spell.h. A more narrow patch to get rid of the static VoidString buffer would be to replace it with '#define VoidString ""', as C99 allows assigning "" to a non-const pointer, even though you're not allowed to modify it. But it seems like good hygiene to mark all these as const. In the structs, the pointers can point to the constant VoidString, or a buffer allocated with palloc(), or with compact_palloc(), so you should not modify them. Reviewed-by: Andres Freund Discussion: https://www.postgresql.org/message-id/54c29fb0-edf2-48ea-9814-44e918bbd6e8@iki.fi
This commit is contained in:
@@ -191,7 +191,7 @@ lowerstr_ctx(IspellDict *Conf, const char *src)
|
||||
#define GETWCHAR(W,L,N,T) ( ((const uint8*)(W))[ ((T)==FF_PREFIX) ? (N) : ( (L) - 1 - (N) ) ] )
|
||||
#define GETCHAR(A,N,T) GETWCHAR( (A)->repl, (A)->replen, N, T )
|
||||
|
||||
static char *VoidString = "";
|
||||
static const char *VoidString = "";
|
||||
|
||||
static int
|
||||
cmpspell(const void *s1, const void *s2)
|
||||
@@ -346,11 +346,11 @@ cmpaffix(const void *s1, const void *s2)
|
||||
* sflag: returns an affix flag from sflagset.
|
||||
*/
|
||||
static void
|
||||
getNextFlagFromString(IspellDict *Conf, char **sflagset, char *sflag)
|
||||
getNextFlagFromString(IspellDict *Conf, const char **sflagset, char *sflag)
|
||||
{
|
||||
int32 s;
|
||||
char *next,
|
||||
*sbuf = *sflagset;
|
||||
char *next;
|
||||
const char *sbuf = *sflagset;
|
||||
int maxstep;
|
||||
bool stop = false;
|
||||
bool met_comma = false;
|
||||
@@ -453,7 +453,7 @@ getNextFlagFromString(IspellDict *Conf, char **sflagset, char *sflag)
|
||||
static bool
|
||||
IsAffixFlagInUse(IspellDict *Conf, int affix, const char *affixflag)
|
||||
{
|
||||
char *flagcur;
|
||||
const char *flagcur;
|
||||
char flag[BUFSIZ];
|
||||
|
||||
if (*affixflag == 0)
|
||||
@@ -1120,13 +1120,13 @@ addCompoundAffixFlagValue(IspellDict *Conf, char *s, uint32 val)
|
||||
* flags s.
|
||||
*/
|
||||
static int
|
||||
getCompoundAffixFlagValue(IspellDict *Conf, char *s)
|
||||
getCompoundAffixFlagValue(IspellDict *Conf, const char *s)
|
||||
{
|
||||
uint32 flag = 0;
|
||||
CompoundAffixFlag *found,
|
||||
key;
|
||||
char sflag[BUFSIZ];
|
||||
char *flagcur;
|
||||
const char *flagcur;
|
||||
|
||||
if (Conf->nCompoundAffixFlag == 0)
|
||||
return 0;
|
||||
@@ -1155,7 +1155,7 @@ getCompoundAffixFlagValue(IspellDict *Conf, char *s)
|
||||
* Conf->AffixData array and function returns its entry.
|
||||
* Else function returns the s parameter.
|
||||
*/
|
||||
static char *
|
||||
static const char *
|
||||
getAffixFlagSet(IspellDict *Conf, char *s)
|
||||
{
|
||||
if (Conf->useFlagAliases && *s != '\0')
|
||||
@@ -1323,7 +1323,7 @@ NIImportOOAffixes(IspellDict *Conf, const char *filename)
|
||||
/* Also reserve place for empty flag set */
|
||||
naffix++;
|
||||
|
||||
Conf->AffixData = (char **) palloc0(naffix * sizeof(char *));
|
||||
Conf->AffixData = (const char **) palloc0(naffix * sizeof(char *));
|
||||
Conf->lenAffixData = Conf->nAffixData = naffix;
|
||||
|
||||
/* Add empty flag set into AffixData */
|
||||
@@ -1571,7 +1571,7 @@ isnewformat:
|
||||
static int
|
||||
MergeAffix(IspellDict *Conf, int a1, int a2)
|
||||
{
|
||||
char **ptr;
|
||||
const char **ptr;
|
||||
|
||||
Assert(a1 < Conf->nAffixData && a2 < Conf->nAffixData);
|
||||
|
||||
@@ -1585,24 +1585,28 @@ MergeAffix(IspellDict *Conf, int a1, int a2)
|
||||
if (Conf->nAffixData + 1 >= Conf->lenAffixData)
|
||||
{
|
||||
Conf->lenAffixData *= 2;
|
||||
Conf->AffixData = (char **) repalloc(Conf->AffixData,
|
||||
sizeof(char *) * Conf->lenAffixData);
|
||||
Conf->AffixData = (const char **) repalloc(Conf->AffixData,
|
||||
sizeof(char *) * Conf->lenAffixData);
|
||||
}
|
||||
|
||||
ptr = Conf->AffixData + Conf->nAffixData;
|
||||
if (Conf->flagMode == FM_NUM)
|
||||
{
|
||||
*ptr = cpalloc(strlen(Conf->AffixData[a1]) +
|
||||
strlen(Conf->AffixData[a2]) +
|
||||
1 /* comma */ + 1 /* \0 */ );
|
||||
sprintf(*ptr, "%s,%s", Conf->AffixData[a1], Conf->AffixData[a2]);
|
||||
char *p = cpalloc(strlen(Conf->AffixData[a1]) +
|
||||
strlen(Conf->AffixData[a2]) +
|
||||
1 /* comma */ + 1 /* \0 */ );
|
||||
|
||||
sprintf(p, "%s,%s", Conf->AffixData[a1], Conf->AffixData[a2]);
|
||||
*ptr = p;
|
||||
}
|
||||
else
|
||||
{
|
||||
*ptr = cpalloc(strlen(Conf->AffixData[a1]) +
|
||||
strlen(Conf->AffixData[a2]) +
|
||||
1 /* \0 */ );
|
||||
sprintf(*ptr, "%s%s", Conf->AffixData[a1], Conf->AffixData[a2]);
|
||||
char *p = cpalloc(strlen(Conf->AffixData[a1]) +
|
||||
strlen(Conf->AffixData[a2]) +
|
||||
1 /* \0 */ );
|
||||
|
||||
sprintf(p, "%s%s", Conf->AffixData[a1], Conf->AffixData[a2]);
|
||||
*ptr = p;
|
||||
}
|
||||
ptr++;
|
||||
*ptr = NULL;
|
||||
@@ -1785,7 +1789,7 @@ NISortDictionary(IspellDict *Conf)
|
||||
* dictionary. Replace textual flag-field of Conf->Spell entries with
|
||||
* indexes into Conf->AffixData array.
|
||||
*/
|
||||
Conf->AffixData = (char **) palloc0(naffix * sizeof(char *));
|
||||
Conf->AffixData = (const char **) palloc0(naffix * sizeof(const char *));
|
||||
|
||||
curaffix = -1;
|
||||
for (i = 0; i < Conf->nspell; i++)
|
||||
@@ -1954,7 +1958,7 @@ mkVoidAffix(IspellDict *Conf, bool issuffix, int startsuffix)
|
||||
* returns false.
|
||||
*/
|
||||
static bool
|
||||
isAffixInUse(IspellDict *Conf, char *affixflag)
|
||||
isAffixInUse(IspellDict *Conf, const char *affixflag)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -2169,7 +2173,7 @@ addToResult(char **forms, char **cur, char *word)
|
||||
}
|
||||
|
||||
static char **
|
||||
NormalizeSubWord(IspellDict *Conf, char *word, int flag)
|
||||
NormalizeSubWord(IspellDict *Conf, const char *word, int flag)
|
||||
{
|
||||
AffixNodeData *suffix = NULL,
|
||||
*prefix = NULL;
|
||||
@@ -2255,7 +2259,7 @@ NormalizeSubWord(IspellDict *Conf, char *word, int flag)
|
||||
if (CheckAffix(newword, swrdlen, prefix->aff[j], flag, pnewword, &baselen))
|
||||
{
|
||||
/* prefix success */
|
||||
char *ff = (prefix->aff[j]->flagflags & suffix->aff[i]->flagflags & FF_CROSSPRODUCT) ?
|
||||
const char *ff = (prefix->aff[j]->flagflags & suffix->aff[i]->flagflags & FF_CROSSPRODUCT) ?
|
||||
VoidString : prefix->aff[j]->flag;
|
||||
|
||||
if (FindWord(Conf, pnewword, ff, flag))
|
||||
@@ -2287,7 +2291,7 @@ typedef struct SplitVar
|
||||
} SplitVar;
|
||||
|
||||
static int
|
||||
CheckCompoundAffixes(CMPDAffix **ptr, char *word, int len, bool CheckInPlace)
|
||||
CheckCompoundAffixes(CMPDAffix **ptr, const char *word, int len, bool CheckInPlace)
|
||||
{
|
||||
bool issuffix;
|
||||
|
||||
@@ -2367,7 +2371,7 @@ AddStem(SplitVar *v, char *word)
|
||||
}
|
||||
|
||||
static SplitVar *
|
||||
SplitToVariants(IspellDict *Conf, SPNode *snode, SplitVar *orig, char *word, int wordlen, int startpos, int minpos)
|
||||
SplitToVariants(IspellDict *Conf, SPNode *snode, SplitVar *orig, const char *word, int wordlen, int startpos, int minpos)
|
||||
{
|
||||
SplitVar *var = NULL;
|
||||
SPNodeData *StopLow,
|
||||
@@ -2533,7 +2537,7 @@ addNorm(TSLexeme **lres, TSLexeme **lcur, char *word, int flags, uint16 NVariant
|
||||
}
|
||||
|
||||
TSLexeme *
|
||||
NINormalizeWord(IspellDict *Conf, char *word)
|
||||
NINormalizeWord(IspellDict *Conf, const char *word)
|
||||
{
|
||||
char **res;
|
||||
TSLexeme *lcur = NULL,
|
||||
|
Reference in New Issue
Block a user