Re: Minor refactorings to eliminate some static buffers
Heikki Linnakangas <hlinnaka@iki.fi>
From: Heikki Linnakangas <hlinnaka@iki.fi>
To: Andres Freund <andres@anarazel.de>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2024-08-06T20:12:12Z
Lists: pgsql-hackers
On 06/08/2024 18:52, Andres Freund wrote:
> On 2024-08-06 18:13:56 +0300, Heikki Linnakangas wrote:
>> diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c
>> index 702a6c3a0b..2732d6bfc9 100644
>> --- a/src/backend/tcop/utility.c
>> +++ b/src/backend/tcop/utility.c
>> @@ -1155,7 +1155,7 @@ ProcessUtilitySlow(ParseState *pstate,
>> {
>> CreateStmt *cstmt = (CreateStmt *) stmt;
>> Datum toast_options;
>> - static char *validnsps[] = HEAP_RELOPT_NAMESPACES;
>> + const char *validnsps[] = HEAP_RELOPT_NAMESPACES;
>>
>> /* Remember transformed RangeVar for LIKE */
>> table_rv = cstmt->relation;
>
> In the other places you used "const char * const", here just "const char *" - it
> doesn't look like that's a required difference?
Just an oversight.
I went back and forth on whether to use plain "char *validnps[]", "const
char *validnsps[]" or "const char *const validnsps[]". The first form
doesn't convey the fact it's read-only, like the "static" used to. The
second form hints that, but only for the strings, not for the pointers
in the array. The last form is what we want, but it's a bit verbose and
ugly. I chose the last form in the end, but missed this one.
Fixed that and pushed. Thanks!
--
Heikki Linnakangas
Neon (https://neon.tech)
Commits
-
Use psprintf to simplify gtsvectorout()
- 3ab2668d4847 18.0 landed
-
Constify fields and parameters in spell.c
- d5f139cb6814 18.0 landed
-
Mark misc static global variables as const
- fe8dd65bf28d 18.0 landed
-
Make nullSemAction const, add 'const' decorators to related functions
- 85829c973cb3 18.0 landed
-
Turn a few 'validnsps' static variables into locals
- 1e35951e71d3 18.0 landed
-
Refactor getWeights to write to caller-supplied buffer
- f822be39629c 18.0 landed
-
Replace static buf with a stack-allocated one in 'seg' extension
- 01e51ed78070 18.0 landed
-
Replace static buf with a stack-allocated one in ReadControlFile
- da8a587e2e22 18.0 landed
-
Replace static buf with palloc in str_time()
- 6151cb787613 18.0 landed
-
Replace static bufs with a StringInfo in cash_words()
- 5bf948d564e3 18.0 landed