summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Eisentraut2024-06-21 05:50:02 +0000
committerPeter Eisentraut2024-06-21 05:53:30 +0000
commit0b06bf9fa972e2964401622f1bb4c611dbe92bd5 (patch)
tree9ad5f17e338e22d13219a5a9e970801ac646c6cc
parent7a089f6e6a14ca3a5dc8822c393c6620279968b9 (diff)
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 <[email protected]> Discussion: https://www.postgresql.org/message-id/flat/f732b014-f614-4600-a437-dba5a2c3738b%40eisentraut.org
-rw-r--r--src/common/jsonapi.c24
-rw-r--r--src/common/parse_manifest.c2
-rw-r--r--src/include/common/jsonapi.h8
-rw-r--r--src/include/common/parse_manifest.h2
4 files changed, 18 insertions, 18 deletions
diff --git a/src/common/jsonapi.c b/src/common/jsonapi.c
index 172310f6f19..f71c1c54b2a 100644
--- a/src/common/jsonapi.c
+++ b/src/common/jsonapi.c
@@ -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;
diff --git a/src/common/parse_manifest.c b/src/common/parse_manifest.c
index 821fba3967a..373a4f6c00f 100644
--- a/src/common/parse_manifest.c
+++ b/src/common/parse_manifest.c
@@ -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,
diff --git a/src/include/common/jsonapi.h b/src/include/common/jsonapi.h
index f1ab17fc9f2..5d3ae4e09b8 100644
--- a/src/include/common/jsonapi.h
+++ b/src/include/common/jsonapi.h
@@ -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 */
diff --git a/src/include/common/parse_manifest.h b/src/include/common/parse_manifest.h
index 0d04239c38d..2777b1e9d22 100644
--- a/src/include/common/parse_manifest.h
+++ b/src/include/common/parse_manifest.h
@@ -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);