Skip to content

Commit 85829c9

Browse files
committed
Make nullSemAction const, add 'const' decorators to related functions
To make it more clear that these should never be modified. Reviewed-by: Andres Freund Discussion: https://www.postgresql.org/message-id/54c29fb0-edf2-48ea-9814-44e918bbd6e8@iki.fi
1 parent 1e35951 commit 85829c9

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

src/backend/utils/adt/jsonfuncs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ static JsonParseErrorType transform_string_values_scalar(void *state, char *toke
514514
* returned when escontext is an ErrorSaveContext).
515515
*/
516516
bool
517-
pg_parse_json_or_errsave(JsonLexContext *lex, JsonSemAction *sem,
517+
pg_parse_json_or_errsave(JsonLexContext *lex, const JsonSemAction *sem,
518518
Node *escontext)
519519
{
520520
JsonParseErrorType result;

src/common/jsonapi.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,15 @@ static char JSON_PROD_GOAL[] = {JSON_TOKEN_END, JSON_NT_JSON, 0};
213213
static inline JsonParseErrorType json_lex_string(JsonLexContext *lex);
214214
static inline JsonParseErrorType json_lex_number(JsonLexContext *lex, const char *s,
215215
bool *num_err, size_t *total_len);
216-
static inline JsonParseErrorType parse_scalar(JsonLexContext *lex, JsonSemAction *sem);
217-
static JsonParseErrorType parse_object_field(JsonLexContext *lex, JsonSemAction *sem);
218-
static JsonParseErrorType parse_object(JsonLexContext *lex, JsonSemAction *sem);
219-
static JsonParseErrorType parse_array_element(JsonLexContext *lex, JsonSemAction *sem);
220-
static JsonParseErrorType parse_array(JsonLexContext *lex, JsonSemAction *sem);
216+
static inline JsonParseErrorType parse_scalar(JsonLexContext *lex, const JsonSemAction *sem);
217+
static JsonParseErrorType parse_object_field(JsonLexContext *lex, const JsonSemAction *sem);
218+
static JsonParseErrorType parse_object(JsonLexContext *lex, const JsonSemAction *sem);
219+
static JsonParseErrorType parse_array_element(JsonLexContext *lex, const JsonSemAction *sem);
220+
static JsonParseErrorType parse_array(JsonLexContext *lex, const JsonSemAction *sem);
221221
static JsonParseErrorType report_parse_error(JsonParseContext ctx, JsonLexContext *lex);
222222

223223
/* the null action object used for pure validation */
224-
JsonSemAction nullSemAction =
224+
const JsonSemAction nullSemAction =
225225
{
226226
NULL, NULL, NULL, NULL, NULL,
227227
NULL, NULL, NULL, NULL, NULL
@@ -519,7 +519,7 @@ freeJsonLexContext(JsonLexContext *lex)
519519
* other differences.
520520
*/
521521
JsonParseErrorType
522-
pg_parse_json(JsonLexContext *lex, JsonSemAction *sem)
522+
pg_parse_json(JsonLexContext *lex, const JsonSemAction *sem)
523523
{
524524
#ifdef FORCE_JSON_PSTACK
525525

@@ -648,7 +648,7 @@ json_count_array_elements(JsonLexContext *lex, int *elements)
648648
*/
649649
JsonParseErrorType
650650
pg_parse_json_incremental(JsonLexContext *lex,
651-
JsonSemAction *sem,
651+
const JsonSemAction *sem,
652652
const char *json,
653653
size_t len,
654654
bool is_last)
@@ -1005,7 +1005,7 @@ pg_parse_json_incremental(JsonLexContext *lex,
10051005
* - object field
10061006
*/
10071007
static inline JsonParseErrorType
1008-
parse_scalar(JsonLexContext *lex, JsonSemAction *sem)
1008+
parse_scalar(JsonLexContext *lex, const JsonSemAction *sem)
10091009
{
10101010
char *val = NULL;
10111011
json_scalar_action sfunc = sem->scalar;
@@ -1049,7 +1049,7 @@ parse_scalar(JsonLexContext *lex, JsonSemAction *sem)
10491049
}
10501050

10511051
static JsonParseErrorType
1052-
parse_object_field(JsonLexContext *lex, JsonSemAction *sem)
1052+
parse_object_field(JsonLexContext *lex, const JsonSemAction *sem)
10531053
{
10541054
/*
10551055
* An object field is "fieldname" : value where value can be a scalar,
@@ -1111,7 +1111,7 @@ parse_object_field(JsonLexContext *lex, JsonSemAction *sem)
11111111
}
11121112

11131113
static JsonParseErrorType
1114-
parse_object(JsonLexContext *lex, JsonSemAction *sem)
1114+
parse_object(JsonLexContext *lex, const JsonSemAction *sem)
11151115
{
11161116
/*
11171117
* an object is a possibly empty sequence of object fields, separated by
@@ -1185,7 +1185,7 @@ parse_object(JsonLexContext *lex, JsonSemAction *sem)
11851185
}
11861186

11871187
static JsonParseErrorType
1188-
parse_array_element(JsonLexContext *lex, JsonSemAction *sem)
1188+
parse_array_element(JsonLexContext *lex, const JsonSemAction *sem)
11891189
{
11901190
json_aelem_action astart = sem->array_element_start;
11911191
json_aelem_action aend = sem->array_element_end;
@@ -1229,7 +1229,7 @@ parse_array_element(JsonLexContext *lex, JsonSemAction *sem)
12291229
}
12301230

12311231
static JsonParseErrorType
1232-
parse_array(JsonLexContext *lex, JsonSemAction *sem)
1232+
parse_array(JsonLexContext *lex, const JsonSemAction *sem)
12331233
{
12341234
/*
12351235
* an array is a possibly empty sequence of array elements, separated by

src/include/common/jsonapi.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,16 @@ typedef struct JsonSemAction
153153
* does nothing and just continues.
154154
*/
155155
extern JsonParseErrorType pg_parse_json(JsonLexContext *lex,
156-
JsonSemAction *sem);
156+
const JsonSemAction *sem);
157157

158158
extern JsonParseErrorType pg_parse_json_incremental(JsonLexContext *lex,
159-
JsonSemAction *sem,
159+
const JsonSemAction *sem,
160160
const char *json,
161161
size_t len,
162162
bool is_last);
163163

164164
/* the null action object used for pure validation */
165-
extern PGDLLIMPORT JsonSemAction nullSemAction;
165+
extern PGDLLIMPORT const JsonSemAction nullSemAction;
166166

167167
/*
168168
* json_count_array_elements performs a fast secondary parse to determine the

src/include/utils/jsonfuncs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ typedef text *(*JsonTransformStringValuesAction) (void *state, char *elem_value,
4141
extern JsonLexContext *makeJsonLexContext(JsonLexContext *lex, text *json, bool need_escapes);
4242

4343
/* try to parse json, and errsave(escontext) on failure */
44-
extern bool pg_parse_json_or_errsave(JsonLexContext *lex, JsonSemAction *sem,
44+
extern bool pg_parse_json_or_errsave(JsonLexContext *lex, const JsonSemAction *sem,
4545
struct Node *escontext);
4646

4747
#define pg_parse_json_or_ereport(lex, sem) \

src/test/modules/test_json_parser/test_json_parser_incremental.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ main(int argc, char **argv)
8484
size_t chunk_size = DEFAULT_CHUNK_SIZE;
8585
struct stat statbuf;
8686
off_t bytes_left;
87-
JsonSemAction *testsem = &nullSemAction;
87+
const JsonSemAction *testsem = &nullSemAction;
8888
char *testfile;
8989
int c;
9090
bool need_strings = false;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy