1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-03 20:02:46 +03:00

jsonapi: Use size_t

Use size_t instead of int for object sizes in the jsonapi.  This makes
the API better self-documenting.

Reviewed-by: Andrew Dunstan <andrew@dunslane.net>
Discussion: https://www.postgresql.org/message-id/flat/f732b014-f614-4600-a437-dba5a2c3738b%40eisentraut.org
This commit is contained in:
Peter Eisentraut
2024-06-21 07:50:02 +02:00
parent 7a089f6e6a
commit 0b06bf9fa9
4 changed files with 18 additions and 18 deletions

View File

@ -85,7 +85,7 @@ struct JsonParserStack
{
int stack_size;
char *prediction;
int pred_index;
size_t pred_index;
/* these two are indexed by lex_level */
char **fnames;
bool *fnull;
@ -212,7 +212,7 @@ 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,
bool *num_err, int *total_len);
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);
static JsonParseErrorType parse_object(JsonLexContext *lex, JsonSemAction *sem);
@ -269,10 +269,10 @@ lex_expect(JsonParseContext ctx, JsonLexContext *lex, JsonTokenType token)
* str is of length len, and need not be null-terminated.
*/
bool
IsValidJsonNumber(const char *str, int len)
IsValidJsonNumber(const char *str, size_t len)
{
bool numeric_error;
int total_len;
size_t total_len;
JsonLexContext dummy_lex;
if (len <= 0)
@ -324,7 +324,7 @@ IsValidJsonNumber(const char *str, int len)
*/
JsonLexContext *
makeJsonLexContextCstringLen(JsonLexContext *lex, char *json,
int len, int encoding, bool need_escapes)
size_t len, int encoding, bool need_escapes)
{
if (lex == NULL)
{
@ -650,7 +650,7 @@ JsonParseErrorType
pg_parse_json_incremental(JsonLexContext *lex,
JsonSemAction *sem,
char *json,
int len,
size_t len,
bool is_last)
{
JsonTokenType tok;
@ -888,7 +888,7 @@ pg_parse_json_incremental(JsonLexContext *lex,
}
else
{
int tlen = (lex->token_terminator - lex->token_start);
ptrdiff_t tlen = (lex->token_terminator - lex->token_start);
pstack->scalar_val = palloc(tlen + 1);
memcpy(pstack->scalar_val, lex->token_start, tlen);
@ -1332,7 +1332,7 @@ json_lex(JsonLexContext *lex)
* recursive call
*/
StringInfo ptok = &(lex->inc_state->partial_token);
int added = 0;
size_t added = 0;
bool tok_done = false;
JsonLexContext dummy_lex;
JsonParseErrorType partial_result;
@ -1354,7 +1354,7 @@ json_lex(JsonLexContext *lex)
break;
}
for (int i = 0; i < lex->input_length; i++)
for (size_t i = 0; i < lex->input_length; i++)
{
char c = lex->input[i];
@ -1382,7 +1382,7 @@ json_lex(JsonLexContext *lex)
bool numend = false;
for (int i = 0; i < lex->input_length && !numend; i++)
for (size_t i = 0; i < lex->input_length && !numend; i++)
{
char cc = lex->input[i];
@ -1418,7 +1418,7 @@ json_lex(JsonLexContext *lex)
* {null, false, true} literals as well as any trailing
* alphanumeric junk on non-string tokens.
*/
for (int i = added; i < lex->input_length; i++)
for (size_t i = added; i < lex->input_length; i++)
{
char cc = lex->input[i];
@ -1941,7 +1941,7 @@ json_lex_string(JsonLexContext *lex)
*/
static inline JsonParseErrorType
json_lex_number(JsonLexContext *lex, char *s,
bool *num_err, int *total_len)
bool *num_err, size_t *total_len)
{
bool error = false;
int len = s - lex->input;