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;

View file

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

View file

@ -89,7 +89,7 @@ typedef struct JsonIncrementalState JsonIncrementalState;
typedef struct JsonLexContext
{
char *input;
int input_length;
size_t input_length;
int input_encoding;
char *token_start;
char *token_terminator;
@ -158,7 +158,7 @@ extern JsonParseErrorType pg_parse_json(JsonLexContext *lex,
extern JsonParseErrorType pg_parse_json_incremental(JsonLexContext *lex,
JsonSemAction *sem,
char *json,
int len,
size_t len,
bool is_last);
/* 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,
char *json,
int len,
size_t len,
int encoding,
bool need_escapes);
@ -219,6 +219,6 @@ extern char *json_errdetail(JsonParseErrorType error, JsonLexContext *lex);
*
* 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 */

View file

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