From: Peter Geoghegan Date: Sun, 16 Mar 2014 03:25:54 +0000 (-0700) Subject: Better findJsonbValueFromSuperHeader* assertions X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=895b60111f256b42c797cc725f56c107a3d57204;p=users%2Fandresfreund%2Fpostgres.git Better findJsonbValueFromSuperHeader* assertions --- diff --git a/src/backend/utils/adt/jsonb_util.c b/src/backend/utils/adt/jsonb_util.c index 629c0c0e40..79aef81034 100644 --- a/src/backend/utils/adt/jsonb_util.c +++ b/src/backend/utils/adt/jsonb_util.c @@ -290,7 +290,8 @@ findJsonbValueFromSuperHeaderLen(JsonbSuperHeader sheader, uint32 flags, * appropriate flag, as well as having the pointed-to Jsonb superheader be of * that same container type at the top level. If both of those conditions * don't hold, immediately fall through and return NULL. Otherwise, return - * palloc()'d copy of value. + * palloc()'d copy of value. "flags" allows caller to specify which container + * types are of interest. */ JsonbValue * findJsonbValueFromSuperHeader(JsonbSuperHeader sheader, uint32 flags, @@ -301,9 +302,7 @@ findJsonbValueFromSuperHeader(JsonbSuperHeader sheader, uint32 flags, JsonbValue *r = palloc(sizeof(JsonbValue)); int count = (superheader & JB_CMASK); - /* No contradictory requests */ - Assert((superheader & (JB_FARRAY | JB_FOBJECT)) != - (JB_FARRAY | JB_FOBJECT)); + Assert((flags & ~(JB_FARRAY | JB_FOBJECT)) == 0); if (flags & JB_FARRAY & superheader) { @@ -467,7 +466,8 @@ findJsonbValueFromSuperHeader(JsonbSuperHeader sheader, uint32 flags, /* * Get i-th value of array or object. * - * Returns palloc()'d copy of value, or NULL if it cannot be found. + * Returns palloc()'d copy of value, or NULL if it cannot be found. "flags" + * allows caller to specify which container types are of interest. */ JsonbValue * getIthJsonbValueFromSuperHeader(JsonbSuperHeader sheader, uint32 flags, @@ -479,11 +479,9 @@ getIthJsonbValueFromSuperHeader(JsonbSuperHeader sheader, uint32 flags, *e; char *data; - r = palloc(sizeof(JsonbValue)); + Assert((flags & ~(JB_FARRAY | JB_FOBJECT)) == 0); - /* No contradictory requests */ - Assert((superheader & (JB_FARRAY | JB_FOBJECT)) != - (JB_FARRAY | JB_FOBJECT)); + r = palloc(sizeof(JsonbValue)); if (i >= (superheader & JB_CMASK)) return NULL; diff --git a/src/backend/utils/adt/jsonfuncs.c b/src/backend/utils/adt/jsonfuncs.c index 244022bbc9..004630c3ba 100644 --- a/src/backend/utils/adt/jsonfuncs.c +++ b/src/backend/utils/adt/jsonfuncs.c @@ -1169,7 +1169,6 @@ get_jsonb_path_all(FunctionCallInfo fcinfo, bool as_text) JsonbValue *jbvp; JsonbValue tv; - if (array_contains_nulls(path)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),