Better findJsonbValueFromSuperHeader* assertions
authorPeter Geoghegan <[email protected]>
Sun, 16 Mar 2014 03:25:54 +0000 (20:25 -0700)
committerPeter Geoghegan <[email protected]>
Sun, 16 Mar 2014 03:25:54 +0000 (20:25 -0700)
src/backend/utils/adt/jsonb_util.c
src/backend/utils/adt/jsonfuncs.c

index 629c0c0e40fc15ae307464dd0d64fe2df45bd1e6..79aef81034c8f73e76d62d4d12c723fb613cab27 100644 (file)
@@ -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;
index 244022bbc91614c982f0bf8706932cb57adf33ff..004630c3ba00ab6bc082cb8f58aed7c80d0765ed 100644 (file)
@@ -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),