mirror of
https://github.com/postgres/postgres.git
synced 2025-11-19 13:42:17 +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:
@@ -66,7 +66,7 @@ typedef struct spell_struct
|
||||
* flag is filled in by NIImportDictionary(). After
|
||||
* NISortDictionary(), d is used instead of flag.
|
||||
*/
|
||||
char *flag;
|
||||
const char *flag;
|
||||
/* d is used in mkSPNode() */
|
||||
struct
|
||||
{
|
||||
@@ -86,15 +86,15 @@ typedef struct spell_struct
|
||||
*/
|
||||
typedef struct aff_struct
|
||||
{
|
||||
char *flag;
|
||||
const char *flag;
|
||||
/* FF_SUFFIX or FF_PREFIX */
|
||||
uint32 type:1,
|
||||
flagflags:7,
|
||||
issimple:1,
|
||||
isregis:1,
|
||||
replen:14;
|
||||
char *find;
|
||||
char *repl;
|
||||
const char *find;
|
||||
const char *repl;
|
||||
union
|
||||
{
|
||||
/*
|
||||
@@ -146,7 +146,7 @@ typedef struct AffixNode
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char *affix;
|
||||
const char *affix;
|
||||
int len;
|
||||
bool issuffix;
|
||||
} CMPDAffix;
|
||||
@@ -170,7 +170,7 @@ typedef struct CompoundAffixFlag
|
||||
union
|
||||
{
|
||||
/* Flag name if flagMode is FM_CHAR or FM_LONG */
|
||||
char *s;
|
||||
const char *s;
|
||||
/* Flag name if flagMode is FM_NUM */
|
||||
uint32 i;
|
||||
} flag;
|
||||
@@ -192,7 +192,7 @@ typedef struct
|
||||
|
||||
SPNode *Dictionary;
|
||||
/* Array of sets of affixes */
|
||||
char **AffixData;
|
||||
const char **AffixData;
|
||||
int lenAffixData;
|
||||
int nAffixData;
|
||||
bool useFlagAliases;
|
||||
@@ -229,7 +229,7 @@ typedef struct
|
||||
size_t avail; /* free space remaining at firstfree */
|
||||
} IspellDict;
|
||||
|
||||
extern TSLexeme *NINormalizeWord(IspellDict *Conf, char *word);
|
||||
extern TSLexeme *NINormalizeWord(IspellDict *Conf, const char *word);
|
||||
|
||||
extern void NIStartBuild(IspellDict *Conf);
|
||||
extern void NIImportAffixes(IspellDict *Conf, const char *filename);
|
||||
|
||||
Reference in New Issue
Block a user