Skip to content

Commit 4178d8b

Browse files
committed
Beautify initialization of JsonValueList and JsonLikeRegexContext
Instead of tricky assignment to {0} introduce special macros, which explicitly initialize every field.
1 parent aa1b7f3 commit 4178d8b

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

src/backend/utils/adt/jsonpath_exec.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ typedef struct JsonLikeRegexContext
126126
int cflags;
127127
} JsonLikeRegexContext;
128128

129+
#define EmptyJsonLikeRegexContext {NULL, 0}
130+
129131
/* Result of jsonpath predicate evaluation */
130132
typedef enum JsonPathBool
131133
{
@@ -153,6 +155,8 @@ typedef struct JsonValueList
153155
List *list;
154156
} JsonValueList;
155157

158+
#define EmptyJsonValueList {NULL, NIL}
159+
156160
typedef struct JsonValueListIterator
157161
{
158162
JsonbValue *value;
@@ -321,7 +325,7 @@ jsonb_path_match(PG_FUNCTION_ARGS)
321325
Jsonb *jb = PG_GETARG_JSONB_P(0);
322326
JsonPath *jp = PG_GETARG_JSONPATH_P(1);
323327
JsonbValue *jbv;
324-
JsonValueList found = {0};
328+
JsonValueList found = EmptyJsonValueList;
325329
Jsonb *vars = NULL;
326330
bool silent = true;
327331

@@ -379,7 +383,7 @@ jsonb_path_query(PG_FUNCTION_ARGS)
379383
MemoryContext oldcontext;
380384
Jsonb *vars;
381385
bool silent;
382-
JsonValueList found = {0};
386+
JsonValueList found = EmptyJsonValueList;
383387

384388
funcctx = SRF_FIRSTCALL_INIT();
385389
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
@@ -420,7 +424,7 @@ jsonb_path_query_array(FunctionCallInfo fcinfo)
420424
{
421425
Jsonb *jb = PG_GETARG_JSONB_P(0);
422426
JsonPath *jp = PG_GETARG_JSONPATH_P(1);
423-
JsonValueList found = {0};
427+
JsonValueList found = EmptyJsonValueList;
424428
Jsonb *vars = PG_GETARG_JSONB_P(2);
425429
bool silent = PG_GETARG_BOOL(3);
426430

@@ -439,7 +443,7 @@ jsonb_path_query_first(FunctionCallInfo fcinfo)
439443
{
440444
Jsonb *jb = PG_GETARG_JSONB_P(0);
441445
JsonPath *jp = PG_GETARG_JSONPATH_P(1);
442-
JsonValueList found = {0};
446+
JsonValueList found = EmptyJsonValueList;
443447
Jsonb *vars = PG_GETARG_JSONB_P(2);
444448
bool silent = PG_GETARG_BOOL(3);
445449

@@ -510,7 +514,7 @@ executeJsonPath(JsonPath *path, Jsonb *vars, Jsonb *json, bool throwErrors,
510514
* In strict mode we must get a complete list of values to check that
511515
* there are no errors at all.
512516
*/
513-
JsonValueList vals = {0};
517+
JsonValueList vals = EmptyJsonValueList;
514518

515519
res = executeItem(&cxt, &jsp, &jbv, &vals);
516520

@@ -1134,7 +1138,7 @@ executeItemOptUnwrapResult(JsonPathExecContext *cxt, JsonPathItem *jsp,
11341138
{
11351139
if (unwrap && jspAutoUnwrap(cxt))
11361140
{
1137-
JsonValueList seq = {0};
1141+
JsonValueList seq = EmptyJsonValueList;
11381142
JsonValueListIterator it;
11391143
JsonPathExecResult res = executeItem(cxt, jsp, jb, &seq);
11401144
JsonbValue *item;
@@ -1262,7 +1266,7 @@ executeBoolItem(JsonPathExecContext *cxt, JsonPathItem *jsp,
12621266
* regexes, but we use Postgres regexes here. 'flags' is a
12631267
* string literal converted to integer flags at compile-time.
12641268
*/
1265-
JsonLikeRegexContext lrcxt = {0};
1269+
JsonLikeRegexContext lrcxt = EmptyJsonLikeRegexContext;
12661270

12671271
jspInitByBuffer(&larg, jsp->base,
12681272
jsp->content.like_regex.expr);
@@ -1280,7 +1284,7 @@ executeBoolItem(JsonPathExecContext *cxt, JsonPathItem *jsp,
12801284
* In strict mode we must get a complete list of values to
12811285
* check that there are no errors at all.
12821286
*/
1283-
JsonValueList vals = {0};
1287+
JsonValueList vals = EmptyJsonValueList;
12841288
JsonPathExecResult res =
12851289
executeItemOptUnwrapResultNoThrow(cxt, &larg, jb,
12861290
false, &vals);
@@ -1432,8 +1436,8 @@ executePredicate(JsonPathExecContext *cxt, JsonPathItem *pred,
14321436
{
14331437
JsonPathExecResult res;
14341438
JsonValueListIterator lseqit;
1435-
JsonValueList lseq = {0};
1436-
JsonValueList rseq = {0};
1439+
JsonValueList lseq = EmptyJsonValueList;
1440+
JsonValueList rseq = EmptyJsonValueList;
14371441
JsonbValue *lval;
14381442
bool error = false;
14391443
bool found = false;
@@ -1511,8 +1515,8 @@ executeBinaryArithmExpr(JsonPathExecContext *cxt, JsonPathItem *jsp,
15111515
{
15121516
JsonPathExecResult jper;
15131517
JsonPathItem elem;
1514-
JsonValueList lseq = {0};
1515-
JsonValueList rseq = {0};
1518+
JsonValueList lseq = EmptyJsonValueList;
1519+
JsonValueList rseq = EmptyJsonValueList;
15161520
JsonbValue *lval;
15171521
JsonbValue *rval;
15181522
Numeric res;
@@ -1586,7 +1590,7 @@ executeUnaryArithmExpr(JsonPathExecContext *cxt, JsonPathItem *jsp,
15861590
JsonPathExecResult jper;
15871591
JsonPathExecResult jper2;
15881592
JsonPathItem elem;
1589-
JsonValueList seq = {0};
1593+
JsonValueList seq = EmptyJsonValueList;
15901594
JsonValueListIterator it;
15911595
JsonbValue *val;
15921596
bool hasNext;
@@ -2124,7 +2128,7 @@ getArrayIndex(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonbValue *jb,
21242128
int32 *index)
21252129
{
21262130
JsonbValue *jbv;
2127-
JsonValueList found = {0};
2131+
JsonValueList found = EmptyJsonValueList;
21282132
JsonPathExecResult res = executeItem(cxt, jsp, jb, &found);
21292133
Datum numeric_index;
21302134
bool have_error = false;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy