mirror of
https://github.com/postgres/postgres.git
synced 2025-04-25 21:42:33 +03:00
Beautify initialization of JsonValueList and JsonLikeRegexContext
Instead of tricky assignment to {0} introduce special macros, which explicitly initialize every field.
This commit is contained in:
parent
aa1b7f3866
commit
4178d8b91c
@ -126,6 +126,8 @@ typedef struct JsonLikeRegexContext
|
|||||||
int cflags;
|
int cflags;
|
||||||
} JsonLikeRegexContext;
|
} JsonLikeRegexContext;
|
||||||
|
|
||||||
|
#define EmptyJsonLikeRegexContext {NULL, 0}
|
||||||
|
|
||||||
/* Result of jsonpath predicate evaluation */
|
/* Result of jsonpath predicate evaluation */
|
||||||
typedef enum JsonPathBool
|
typedef enum JsonPathBool
|
||||||
{
|
{
|
||||||
@ -153,6 +155,8 @@ typedef struct JsonValueList
|
|||||||
List *list;
|
List *list;
|
||||||
} JsonValueList;
|
} JsonValueList;
|
||||||
|
|
||||||
|
#define EmptyJsonValueList {NULL, NIL}
|
||||||
|
|
||||||
typedef struct JsonValueListIterator
|
typedef struct JsonValueListIterator
|
||||||
{
|
{
|
||||||
JsonbValue *value;
|
JsonbValue *value;
|
||||||
@ -321,7 +325,7 @@ jsonb_path_match(PG_FUNCTION_ARGS)
|
|||||||
Jsonb *jb = PG_GETARG_JSONB_P(0);
|
Jsonb *jb = PG_GETARG_JSONB_P(0);
|
||||||
JsonPath *jp = PG_GETARG_JSONPATH_P(1);
|
JsonPath *jp = PG_GETARG_JSONPATH_P(1);
|
||||||
JsonbValue *jbv;
|
JsonbValue *jbv;
|
||||||
JsonValueList found = {0};
|
JsonValueList found = EmptyJsonValueList;
|
||||||
Jsonb *vars = NULL;
|
Jsonb *vars = NULL;
|
||||||
bool silent = true;
|
bool silent = true;
|
||||||
|
|
||||||
@ -379,7 +383,7 @@ jsonb_path_query(PG_FUNCTION_ARGS)
|
|||||||
MemoryContext oldcontext;
|
MemoryContext oldcontext;
|
||||||
Jsonb *vars;
|
Jsonb *vars;
|
||||||
bool silent;
|
bool silent;
|
||||||
JsonValueList found = {0};
|
JsonValueList found = EmptyJsonValueList;
|
||||||
|
|
||||||
funcctx = SRF_FIRSTCALL_INIT();
|
funcctx = SRF_FIRSTCALL_INIT();
|
||||||
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
|
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
|
||||||
@ -420,7 +424,7 @@ jsonb_path_query_array(FunctionCallInfo fcinfo)
|
|||||||
{
|
{
|
||||||
Jsonb *jb = PG_GETARG_JSONB_P(0);
|
Jsonb *jb = PG_GETARG_JSONB_P(0);
|
||||||
JsonPath *jp = PG_GETARG_JSONPATH_P(1);
|
JsonPath *jp = PG_GETARG_JSONPATH_P(1);
|
||||||
JsonValueList found = {0};
|
JsonValueList found = EmptyJsonValueList;
|
||||||
Jsonb *vars = PG_GETARG_JSONB_P(2);
|
Jsonb *vars = PG_GETARG_JSONB_P(2);
|
||||||
bool silent = PG_GETARG_BOOL(3);
|
bool silent = PG_GETARG_BOOL(3);
|
||||||
|
|
||||||
@ -439,7 +443,7 @@ jsonb_path_query_first(FunctionCallInfo fcinfo)
|
|||||||
{
|
{
|
||||||
Jsonb *jb = PG_GETARG_JSONB_P(0);
|
Jsonb *jb = PG_GETARG_JSONB_P(0);
|
||||||
JsonPath *jp = PG_GETARG_JSONPATH_P(1);
|
JsonPath *jp = PG_GETARG_JSONPATH_P(1);
|
||||||
JsonValueList found = {0};
|
JsonValueList found = EmptyJsonValueList;
|
||||||
Jsonb *vars = PG_GETARG_JSONB_P(2);
|
Jsonb *vars = PG_GETARG_JSONB_P(2);
|
||||||
bool silent = PG_GETARG_BOOL(3);
|
bool silent = PG_GETARG_BOOL(3);
|
||||||
|
|
||||||
@ -510,7 +514,7 @@ executeJsonPath(JsonPath *path, Jsonb *vars, Jsonb *json, bool throwErrors,
|
|||||||
* In strict mode we must get a complete list of values to check that
|
* In strict mode we must get a complete list of values to check that
|
||||||
* there are no errors at all.
|
* there are no errors at all.
|
||||||
*/
|
*/
|
||||||
JsonValueList vals = {0};
|
JsonValueList vals = EmptyJsonValueList;
|
||||||
|
|
||||||
res = executeItem(&cxt, &jsp, &jbv, &vals);
|
res = executeItem(&cxt, &jsp, &jbv, &vals);
|
||||||
|
|
||||||
@ -1134,7 +1138,7 @@ executeItemOptUnwrapResult(JsonPathExecContext *cxt, JsonPathItem *jsp,
|
|||||||
{
|
{
|
||||||
if (unwrap && jspAutoUnwrap(cxt))
|
if (unwrap && jspAutoUnwrap(cxt))
|
||||||
{
|
{
|
||||||
JsonValueList seq = {0};
|
JsonValueList seq = EmptyJsonValueList;
|
||||||
JsonValueListIterator it;
|
JsonValueListIterator it;
|
||||||
JsonPathExecResult res = executeItem(cxt, jsp, jb, &seq);
|
JsonPathExecResult res = executeItem(cxt, jsp, jb, &seq);
|
||||||
JsonbValue *item;
|
JsonbValue *item;
|
||||||
@ -1262,7 +1266,7 @@ executeBoolItem(JsonPathExecContext *cxt, JsonPathItem *jsp,
|
|||||||
* regexes, but we use Postgres regexes here. 'flags' is a
|
* regexes, but we use Postgres regexes here. 'flags' is a
|
||||||
* string literal converted to integer flags at compile-time.
|
* string literal converted to integer flags at compile-time.
|
||||||
*/
|
*/
|
||||||
JsonLikeRegexContext lrcxt = {0};
|
JsonLikeRegexContext lrcxt = EmptyJsonLikeRegexContext;
|
||||||
|
|
||||||
jspInitByBuffer(&larg, jsp->base,
|
jspInitByBuffer(&larg, jsp->base,
|
||||||
jsp->content.like_regex.expr);
|
jsp->content.like_regex.expr);
|
||||||
@ -1280,7 +1284,7 @@ executeBoolItem(JsonPathExecContext *cxt, JsonPathItem *jsp,
|
|||||||
* In strict mode we must get a complete list of values to
|
* In strict mode we must get a complete list of values to
|
||||||
* check that there are no errors at all.
|
* check that there are no errors at all.
|
||||||
*/
|
*/
|
||||||
JsonValueList vals = {0};
|
JsonValueList vals = EmptyJsonValueList;
|
||||||
JsonPathExecResult res =
|
JsonPathExecResult res =
|
||||||
executeItemOptUnwrapResultNoThrow(cxt, &larg, jb,
|
executeItemOptUnwrapResultNoThrow(cxt, &larg, jb,
|
||||||
false, &vals);
|
false, &vals);
|
||||||
@ -1432,8 +1436,8 @@ executePredicate(JsonPathExecContext *cxt, JsonPathItem *pred,
|
|||||||
{
|
{
|
||||||
JsonPathExecResult res;
|
JsonPathExecResult res;
|
||||||
JsonValueListIterator lseqit;
|
JsonValueListIterator lseqit;
|
||||||
JsonValueList lseq = {0};
|
JsonValueList lseq = EmptyJsonValueList;
|
||||||
JsonValueList rseq = {0};
|
JsonValueList rseq = EmptyJsonValueList;
|
||||||
JsonbValue *lval;
|
JsonbValue *lval;
|
||||||
bool error = false;
|
bool error = false;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
@ -1511,8 +1515,8 @@ executeBinaryArithmExpr(JsonPathExecContext *cxt, JsonPathItem *jsp,
|
|||||||
{
|
{
|
||||||
JsonPathExecResult jper;
|
JsonPathExecResult jper;
|
||||||
JsonPathItem elem;
|
JsonPathItem elem;
|
||||||
JsonValueList lseq = {0};
|
JsonValueList lseq = EmptyJsonValueList;
|
||||||
JsonValueList rseq = {0};
|
JsonValueList rseq = EmptyJsonValueList;
|
||||||
JsonbValue *lval;
|
JsonbValue *lval;
|
||||||
JsonbValue *rval;
|
JsonbValue *rval;
|
||||||
Numeric res;
|
Numeric res;
|
||||||
@ -1586,7 +1590,7 @@ executeUnaryArithmExpr(JsonPathExecContext *cxt, JsonPathItem *jsp,
|
|||||||
JsonPathExecResult jper;
|
JsonPathExecResult jper;
|
||||||
JsonPathExecResult jper2;
|
JsonPathExecResult jper2;
|
||||||
JsonPathItem elem;
|
JsonPathItem elem;
|
||||||
JsonValueList seq = {0};
|
JsonValueList seq = EmptyJsonValueList;
|
||||||
JsonValueListIterator it;
|
JsonValueListIterator it;
|
||||||
JsonbValue *val;
|
JsonbValue *val;
|
||||||
bool hasNext;
|
bool hasNext;
|
||||||
@ -2124,7 +2128,7 @@ getArrayIndex(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonbValue *jb,
|
|||||||
int32 *index)
|
int32 *index)
|
||||||
{
|
{
|
||||||
JsonbValue *jbv;
|
JsonbValue *jbv;
|
||||||
JsonValueList found = {0};
|
JsonValueList found = EmptyJsonValueList;
|
||||||
JsonPathExecResult res = executeItem(cxt, jsp, jb, &found);
|
JsonPathExecResult res = executeItem(cxt, jsp, jb, &found);
|
||||||
Datum numeric_index;
|
Datum numeric_index;
|
||||||
bool have_error = false;
|
bool have_error = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user