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

View File

@ -183,7 +183,7 @@ json_parse_manifest_incremental_shutdown(JsonManifestParseIncrementalState *incs
void void
json_parse_manifest_incremental_chunk( json_parse_manifest_incremental_chunk(
JsonManifestParseIncrementalState *incstate, char *chunk, int size, JsonManifestParseIncrementalState *incstate, char *chunk, size_t size,
bool is_last) bool is_last)
{ {
JsonParseErrorType res, JsonParseErrorType res,

View File

@ -89,7 +89,7 @@ typedef struct JsonIncrementalState JsonIncrementalState;
typedef struct JsonLexContext typedef struct JsonLexContext
{ {
char *input; char *input;
int input_length; size_t input_length;
int input_encoding; int input_encoding;
char *token_start; char *token_start;
char *token_terminator; char *token_terminator;
@ -158,7 +158,7 @@ extern JsonParseErrorType pg_parse_json(JsonLexContext *lex,
extern JsonParseErrorType pg_parse_json_incremental(JsonLexContext *lex, extern JsonParseErrorType pg_parse_json_incremental(JsonLexContext *lex,
JsonSemAction *sem, JsonSemAction *sem,
char *json, char *json,
int len, size_t len,
bool is_last); bool is_last);
/* the null action object used for pure validation */ /* the null action object used for pure validation */
@ -193,7 +193,7 @@ extern JsonParseErrorType json_count_array_elements(JsonLexContext *lex,
*/ */
extern JsonLexContext *makeJsonLexContextCstringLen(JsonLexContext *lex, extern JsonLexContext *makeJsonLexContextCstringLen(JsonLexContext *lex,
char *json, char *json,
int len, size_t len,
int encoding, int encoding,
bool need_escapes); bool need_escapes);
@ -219,6 +219,6 @@ extern char *json_errdetail(JsonParseErrorType error, JsonLexContext *lex);
* *
* str argument does not need to be nul-terminated. * str argument does not need to be nul-terminated.
*/ */
extern bool IsValidJsonNumber(const char *str, int len); extern bool IsValidJsonNumber(const char *str, size_t len);
#endif /* JSONAPI_H */ #endif /* JSONAPI_H */

View File

@ -51,7 +51,7 @@ extern void json_parse_manifest(JsonManifestParseContext *context,
char *buffer, size_t size); char *buffer, size_t size);
extern JsonManifestParseIncrementalState *json_parse_manifest_incremental_init(JsonManifestParseContext *context); extern JsonManifestParseIncrementalState *json_parse_manifest_incremental_init(JsonManifestParseContext *context);
extern void json_parse_manifest_incremental_chunk( extern void json_parse_manifest_incremental_chunk(
JsonManifestParseIncrementalState *incstate, char *chunk, int size, JsonManifestParseIncrementalState *incstate, char *chunk, size_t size,
bool is_last); bool is_last);
extern void json_parse_manifest_incremental_shutdown(JsonManifestParseIncrementalState *incstate); extern void json_parse_manifest_incremental_shutdown(JsonManifestParseIncrementalState *incstate);