Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0b06bf9

Browse filesBrowse files
committed
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
1 parent 7a089f6 commit 0b06bf9
Copy full SHA for 0b06bf9

File tree

Expand file treeCollapse file tree

4 files changed

+18
-18
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+18
-18
lines changed

‎src/common/jsonapi.c

Copy file name to clipboardExpand all lines: src/common/jsonapi.c
+12-12Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ struct JsonParserStack
8585
{
8686
int stack_size;
8787
char *prediction;
88-
int pred_index;
88+
size_t pred_index;
8989
/* these two are indexed by lex_level */
9090
char **fnames;
9191
bool *fnull;
@@ -212,7 +212,7 @@ static char JSON_PROD_GOAL[] = {JSON_TOKEN_END, JSON_NT_JSON, 0};
212212

213213
static inline JsonParseErrorType json_lex_string(JsonLexContext *lex);
214214
static inline JsonParseErrorType json_lex_number(JsonLexContext *lex, char *s,
215-
bool *num_err, int *total_len);
215+
bool *num_err, size_t *total_len);
216216
static inline JsonParseErrorType parse_scalar(JsonLexContext *lex, JsonSemAction *sem);
217217
static JsonParseErrorType parse_object_field(JsonLexContext *lex, JsonSemAction *sem);
218218
static JsonParseErrorType parse_object(JsonLexContext *lex, JsonSemAction *sem);
@@ -269,10 +269,10 @@ lex_expect(JsonParseContext ctx, JsonLexContext *lex, JsonTokenType token)
269269
* str is of length len, and need not be null-terminated.
270270
*/
271271
bool
272-
IsValidJsonNumber(const char *str, int len)
272+
IsValidJsonNumber(const char *str, size_t len)
273273
{
274274
bool numeric_error;
275-
int total_len;
275+
size_t total_len;
276276
JsonLexContext dummy_lex;
277277

278278
if (len <= 0)
@@ -324,7 +324,7 @@ IsValidJsonNumber(const char *str, int len)
324324
*/
325325
JsonLexContext *
326326
makeJsonLexContextCstringLen(JsonLexContext *lex, char *json,
327-
int len, int encoding, bool need_escapes)
327+
size_t len, int encoding, bool need_escapes)
328328
{
329329
if (lex == NULL)
330330
{
@@ -650,7 +650,7 @@ JsonParseErrorType
650650
pg_parse_json_incremental(JsonLexContext *lex,
651651
JsonSemAction *sem,
652652
char *json,
653-
int len,
653+
size_t len,
654654
bool is_last)
655655
{
656656
JsonTokenType tok;
@@ -888,7 +888,7 @@ pg_parse_json_incremental(JsonLexContext *lex,
888888
}
889889
else
890890
{
891-
int tlen = (lex->token_terminator - lex->token_start);
891+
ptrdiff_t tlen = (lex->token_terminator - lex->token_start);
892892

893893
pstack->scalar_val = palloc(tlen + 1);
894894
memcpy(pstack->scalar_val, lex->token_start, tlen);
@@ -1332,7 +1332,7 @@ json_lex(JsonLexContext *lex)
13321332
* recursive call
13331333
*/
13341334
StringInfo ptok = &(lex->inc_state->partial_token);
1335-
int added = 0;
1335+
size_t added = 0;
13361336
bool tok_done = false;
13371337
JsonLexContext dummy_lex;
13381338
JsonParseErrorType partial_result;
@@ -1354,7 +1354,7 @@ json_lex(JsonLexContext *lex)
13541354
break;
13551355
}
13561356

1357-
for (int i = 0; i < lex->input_length; i++)
1357+
for (size_t i = 0; i < lex->input_length; i++)
13581358
{
13591359
char c = lex->input[i];
13601360

@@ -1382,7 +1382,7 @@ json_lex(JsonLexContext *lex)
13821382

13831383
bool numend = false;
13841384

1385-
for (int i = 0; i < lex->input_length && !numend; i++)
1385+
for (size_t i = 0; i < lex->input_length && !numend; i++)
13861386
{
13871387
char cc = lex->input[i];
13881388

@@ -1418,7 +1418,7 @@ json_lex(JsonLexContext *lex)
14181418
* {null, false, true} literals as well as any trailing
14191419
* alphanumeric junk on non-string tokens.
14201420
*/
1421-
for (int i = added; i < lex->input_length; i++)
1421+
for (size_t i = added; i < lex->input_length; i++)
14221422
{
14231423
char cc = lex->input[i];
14241424

@@ -1941,7 +1941,7 @@ json_lex_string(JsonLexContext *lex)
19411941
*/
19421942
static inline JsonParseErrorType
19431943
json_lex_number(JsonLexContext *lex, char *s,
1944-
bool *num_err, int *total_len)
1944+
bool *num_err, size_t *total_len)
19451945
{
19461946
bool error = false;
19471947
int len = s - lex->input;

‎src/common/parse_manifest.c

Copy file name to clipboardExpand all lines: src/common/parse_manifest.c
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ json_parse_manifest_incremental_shutdown(JsonManifestParseIncrementalState *incs
183183

184184
void
185185
json_parse_manifest_incremental_chunk(
186-
JsonManifestParseIncrementalState *incstate, char *chunk, int size,
186+
JsonManifestParseIncrementalState *incstate, char *chunk, size_t size,
187187
bool is_last)
188188
{
189189
JsonParseErrorType res,

‎src/include/common/jsonapi.h

Copy file name to clipboardExpand all lines: src/include/common/jsonapi.h
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ typedef struct JsonIncrementalState JsonIncrementalState;
8989
typedef struct JsonLexContext
9090
{
9191
char *input;
92-
int input_length;
92+
size_t input_length;
9393
int input_encoding;
9494
char *token_start;
9595
char *token_terminator;
@@ -158,7 +158,7 @@ extern JsonParseErrorType pg_parse_json(JsonLexContext *lex,
158158
extern JsonParseErrorType pg_parse_json_incremental(JsonLexContext *lex,
159159
JsonSemAction *sem,
160160
char *json,
161-
int len,
161+
size_t len,
162162
bool is_last);
163163

164164
/* the null action object used for pure validation */
@@ -193,7 +193,7 @@ extern JsonParseErrorType json_count_array_elements(JsonLexContext *lex,
193193
*/
194194
extern JsonLexContext *makeJsonLexContextCstringLen(JsonLexContext *lex,
195195
char *json,
196-
int len,
196+
size_t len,
197197
int encoding,
198198
bool need_escapes);
199199

@@ -219,6 +219,6 @@ extern char *json_errdetail(JsonParseErrorType error, JsonLexContext *lex);
219219
*
220220
* str argument does not need to be nul-terminated.
221221
*/
222-
extern bool IsValidJsonNumber(const char *str, int len);
222+
extern bool IsValidJsonNumber(const char *str, size_t len);
223223

224224
#endif /* JSONAPI_H */

‎src/include/common/parse_manifest.h

Copy file name to clipboardExpand all lines: src/include/common/parse_manifest.h
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ extern void json_parse_manifest(JsonManifestParseContext *context,
5151
char *buffer, size_t size);
5252
extern JsonManifestParseIncrementalState *json_parse_manifest_incremental_init(JsonManifestParseContext *context);
5353
extern void json_parse_manifest_incremental_chunk(
54-
JsonManifestParseIncrementalState *incstate, char *chunk, int size,
54+
JsonManifestParseIncrementalState *incstate, char *chunk, size_t size,
5555
bool is_last);
5656
extern void json_parse_manifest_incremental_shutdown(JsonManifestParseIncrementalState *incstate);
5757

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.