diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2024-06-21 07:50:02 +0200 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2024-06-21 07:53:30 +0200 |
commit | 15cd9a3881b030a1a4bddc809f038f86ec27e66d (patch) | |
tree | e10c45f64fcdc6ce49c92150bf854f9089cec98e /src/common/jsonapi.c | |
parent | 0b06bf9fa972e2964401622f1bb4c611dbe92bd5 (diff) | |
download | postgresql-15cd9a3881b030a1a4bddc809f038f86ec27e66d.tar.gz postgresql-15cd9a3881b030a1a4bddc809f038f86ec27e66d.zip |
jsonapi: Use const char *
Apply const qualifiers to char * arguments and fields throughout the
jsonapi. This allows the top-level APIs such as
pg_parse_json_incremental() to declare their input argument as const.
It also reduces the number of unconstify() calls.
Reviewed-by: Andrew Dunstan <andrew@dunslane.net>
Discussion: https://www.postgresql.org/message-id/flat/f732b014-f614-4600-a437-dba5a2c3738b%40eisentraut.org
Diffstat (limited to 'src/common/jsonapi.c')
-rw-r--r-- | src/common/jsonapi.c | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/src/common/jsonapi.c b/src/common/jsonapi.c index f71c1c54b2a..0c6374b0fc2 100644 --- a/src/common/jsonapi.c +++ b/src/common/jsonapi.c @@ -211,7 +211,7 @@ static td_entry td_parser_table[JSON_NUM_NONTERMINALS][JSON_NUM_TERMINALS] = static char JSON_PROD_GOAL[] = {JSON_TOKEN_END, JSON_NT_JSON, 0}; static inline JsonParseErrorType json_lex_string(JsonLexContext *lex); -static inline JsonParseErrorType json_lex_number(JsonLexContext *lex, char *s, +static inline JsonParseErrorType json_lex_number(JsonLexContext *lex, const char *s, bool *num_err, size_t *total_len); static inline JsonParseErrorType parse_scalar(JsonLexContext *lex, JsonSemAction *sem); static JsonParseErrorType parse_object_field(JsonLexContext *lex, JsonSemAction *sem); @@ -290,12 +290,12 @@ IsValidJsonNumber(const char *str, size_t len) */ if (*str == '-') { - dummy_lex.input = unconstify(char *, str) + 1; + dummy_lex.input = str + 1; dummy_lex.input_length = len - 1; } else { - dummy_lex.input = unconstify(char *, str); + dummy_lex.input = str; dummy_lex.input_length = len; } @@ -323,7 +323,7 @@ IsValidJsonNumber(const char *str, size_t len) * cleanup. */ JsonLexContext * -makeJsonLexContextCstringLen(JsonLexContext *lex, char *json, +makeJsonLexContextCstringLen(JsonLexContext *lex, const char *json, size_t len, int encoding, bool need_escapes) { if (lex == NULL) @@ -649,7 +649,7 @@ json_count_array_elements(JsonLexContext *lex, int *elements) JsonParseErrorType pg_parse_json_incremental(JsonLexContext *lex, JsonSemAction *sem, - char *json, + const char *json, size_t len, bool is_last) { @@ -1308,8 +1308,8 @@ parse_array(JsonLexContext *lex, JsonSemAction *sem) JsonParseErrorType json_lex(JsonLexContext *lex) { - char *s; - char *const end = lex->input + lex->input_length; + const char *s; + const char *const end = lex->input + lex->input_length; JsonParseErrorType result; if (lex->incremental && lex->inc_state->partial_completed) @@ -1593,7 +1593,7 @@ json_lex(JsonLexContext *lex) break; default: { - char *p; + const char *p; /* * We're not dealing with a string, number, legal @@ -1671,8 +1671,8 @@ json_lex(JsonLexContext *lex) static inline JsonParseErrorType json_lex_string(JsonLexContext *lex) { - char *s; - char *const end = lex->input + lex->input_length; + const char *s; + const char *const end = lex->input + lex->input_length; int hi_surrogate = -1; /* Convenience macros for error exits */ @@ -1689,7 +1689,7 @@ json_lex_string(JsonLexContext *lex) } while (0) #define FAIL_AT_CHAR_END(code) \ do { \ - char *term = s + pg_encoding_mblen(lex->input_encoding, s); \ + const char *term = s + pg_encoding_mblen(lex->input_encoding, s); \ lex->token_terminator = (term <= end) ? term : end; \ return code; \ } while (0) @@ -1854,7 +1854,7 @@ json_lex_string(JsonLexContext *lex) } else { - char *p = s; + const char *p = s; if (hi_surrogate != -1) FAIL_AT_CHAR_END(JSON_UNICODE_LOW_SURROGATE); @@ -1940,7 +1940,7 @@ json_lex_string(JsonLexContext *lex) * the distance from lex->input to the token end+1 is returned to *total_len. */ static inline JsonParseErrorType -json_lex_number(JsonLexContext *lex, char *s, +json_lex_number(JsonLexContext *lex, const char *s, bool *num_err, size_t *total_len) { bool error = false; |