@@ -44,11 +44,11 @@ struct JsonbParseState
4444struct JsonbIterator
4545{
4646/* Container being iterated */
47- JsonbContainer * container ;
47+ const JsonbContainer * container ;
4848uint32 nElems ;/* Number of elements in children array (will
4949 * be nPairs for objects) */
5050bool isScalar ;/* Pseudo-array scalar value? */
51- JEntry * children ;/* JEntrys for child nodes */
51+ const JEntry * children ;/* JEntrys for child nodes */
5252/* Data proper. This points to the beginning of the variable-length data */
5353char * dataProper ;
5454
@@ -71,16 +71,16 @@ struct JsonbIterator
7171struct JsonbIterator * parent ;
7272};
7373
74- static void fillJsonbValue (JsonbContainer * container ,int index ,
74+ static void fillJsonbValue (const JsonbContainer * container ,int index ,
7575char * base_addr ,uint32 offset ,
7676JsonbValue * result );
77- static bool equalsJsonbScalarValue (JsonbValue * a ,JsonbValue * b );
78- static int compareJsonbScalarValue (JsonbValue * a ,JsonbValue * b );
79- static Jsonb * convertToJsonb (JsonbValue * val );
80- static void convertJsonbValue (StringInfo buffer ,JEntry * header ,JsonbValue * val ,int level );
81- static void convertJsonbArray (StringInfo buffer ,JEntry * header ,JsonbValue * val ,int level );
82- static void convertJsonbObject (StringInfo buffer ,JEntry * header ,JsonbValue * val ,int level );
83- static void convertJsonbScalar (StringInfo buffer ,JEntry * header ,JsonbValue * scalarVal );
77+ static bool equalsJsonbScalarValue (const JsonbValue * a ,const JsonbValue * b );
78+ static int compareJsonbScalarValue (const JsonbValue * a ,const JsonbValue * b );
79+ static Jsonb * convertToJsonb (const JsonbValue * val );
80+ static void convertJsonbValue (StringInfo buffer ,JEntry * header ,const JsonbValue * val ,int level );
81+ static void convertJsonbArray (StringInfo buffer ,JEntry * header ,const JsonbValue * val ,int level );
82+ static void convertJsonbObject (StringInfo buffer ,JEntry * header ,const JsonbValue * val ,int level );
83+ static void convertJsonbScalar (StringInfo buffer ,JEntry * header ,const JsonbValue * scalarVal );
8484
8585static int reserveFromBuffer (StringInfo buffer ,int len );
8686static void appendToBuffer (StringInfo buffer ,const char * data ,int len );
@@ -90,17 +90,17 @@ static short padBufferToInt(StringInfo buffer);
9090static JsonbIterator * iteratorFromContainer (JsonbContainer * container ,JsonbIterator * parent );
9191static JsonbIterator * freeAndGetParent (JsonbIterator * it );
9292static JsonbParseState * pushState (JsonbParseState * * pstate );
93- static void appendKey (JsonbParseState * pstate ,JsonbValue * scalarVal );
94- static void appendValue (JsonbParseState * pstate ,JsonbValue * scalarVal );
95- static void appendElement (JsonbParseState * pstate ,JsonbValue * scalarVal );
93+ static void appendKey (JsonbParseState * pstate ,const JsonbValue * scalarVal );
94+ static void appendValue (JsonbParseState * pstate ,const JsonbValue * scalarVal );
95+ static void appendElement (JsonbParseState * pstate ,const JsonbValue * scalarVal );
9696static int lengthCompareJsonbStringValue (const void * a ,const void * b );
9797static int lengthCompareJsonbPair (const void * a ,const void * b ,void * arg );
9898static void uniqueifyJsonbObject (JsonbValue * object );
99- static JsonbValue * pushJsonbValueScalar (JsonbParseState * * pstate ,
100- JsonbIteratorToken seq ,
101- JsonbValue * scalarVal );
99+ extern JsonbValue * pushJsonbValueScalar (JsonbParseState * * pstate ,
100+ JsonbIteratorToken seq ,
101+ const JsonbValue * scalarVal );
102102static JsonbValue * pushSingleScalarJsonbValue (JsonbParseState * * pstate ,
103- JsonbValue * jbval );
103+ const JsonbValue * jbval );
104104
105105/*
106106 * Turn an in-memory JsonbValue into a Jsonb for on-disk storage.
@@ -483,7 +483,7 @@ getIthJsonbValueFromContainer(JsonbContainer *container, uint32 i)
483483 * expanded.
484484 */
485485static void
486- fillJsonbValue (JsonbContainer * container ,int index ,
486+ fillJsonbValue (const JsonbContainer * container ,int index ,
487487char * base_addr ,uint32 offset ,
488488JsonbValue * result )
489489{
@@ -571,7 +571,7 @@ JsonbParseStateClone(JsonbParseState *state)
571571 */
572572JsonbValue *
573573pushJsonbValue (JsonbParseState * * pstate ,JsonbIteratorToken seq ,
574- JsonbValue * jbval )
574+ const JsonbValue * jbval )
575575{
576576JsonbIterator * it ;
577577JsonbValue * res = NULL ;
@@ -600,7 +600,7 @@ pushJsonbValue(JsonbParseState **pstate, JsonbIteratorToken seq,
600600 */
601601static JsonbValue *
602602pushJsonbValueScalar (JsonbParseState * * pstate ,JsonbIteratorToken seq ,
603- JsonbValue * scalarVal )
603+ const JsonbValue * scalarVal )
604604{
605605JsonbValue * result = NULL ;
606606
@@ -685,7 +685,7 @@ pushJsonbValueScalar(JsonbParseState **pstate, JsonbIteratorToken seq,
685685}
686686
687687static JsonbValue *
688- pushSingleScalarJsonbValue (JsonbParseState * * pstate ,JsonbValue * jbval )
688+ pushSingleScalarJsonbValue (JsonbParseState * * pstate ,const JsonbValue * jbval )
689689{
690690/* single root scalar */
691691JsonbValue va ;
@@ -700,8 +700,8 @@ pushSingleScalarJsonbValue(JsonbParseState **pstate, JsonbValue *jbval)
700700}
701701
702702static JsonbValue *
703- pushNestedScalarJsonbValue (JsonbParseState * * pstate ,JsonbValue * jbval ,
704- bool isKey )
703+ pushNestedScalarJsonbValue (JsonbParseState * * pstate ,const JsonbValue * jbval ,
704+ bool isKey )
705705{
706706switch ((* pstate )-> contVal .type )
707707{
@@ -716,7 +716,8 @@ pushNestedScalarJsonbValue(JsonbParseState **pstate, JsonbValue *jbval,
716716}
717717
718718JsonbValue *
719- pushScalarJsonbValue (JsonbParseState * * pstate ,JsonbValue * jbval ,bool isKey )
719+ pushScalarJsonbValue (JsonbParseState * * pstate ,const JsonbValue * jbval ,
720+ bool isKey )
720721{
721722return * pstate == NULL
722723?pushSingleScalarJsonbValue (pstate ,jbval )
@@ -740,7 +741,7 @@ pushState(JsonbParseState **pstate)
740741 * pushJsonbValue() worker: Append a pair key to state when generating a Jsonb
741742 */
742743static void
743- appendKey (JsonbParseState * pstate ,JsonbValue * string )
744+ appendKey (JsonbParseState * pstate ,const JsonbValue * string )
744745{
745746JsonbValue * object = & pstate -> contVal ;
746747
@@ -769,7 +770,7 @@ appendKey(JsonbParseState *pstate, JsonbValue *string)
769770 * Jsonb
770771 */
771772static void
772- appendValue (JsonbParseState * pstate ,JsonbValue * scalarVal )
773+ appendValue (JsonbParseState * pstate ,const JsonbValue * scalarVal )
773774{
774775JsonbValue * object = & pstate -> contVal ;
775776
@@ -782,7 +783,7 @@ appendValue(JsonbParseState *pstate, JsonbValue *scalarVal)
782783 * pushJsonbValue() worker: Append an element to state when generating a Jsonb
783784 */
784785static void
785- appendElement (JsonbParseState * pstate ,JsonbValue * scalarVal )
786+ appendElement (JsonbParseState * pstate ,const JsonbValue * scalarVal )
786787{
787788JsonbValue * array = & pstate -> contVal ;
788789
@@ -1349,7 +1350,7 @@ JsonbHashScalarValue(const JsonbValue *scalarVal, uint32 *hash)
13491350 * Are two scalar JsonbValues of the same type a and b equal?
13501351 */
13511352static bool
1352- equalsJsonbScalarValue (JsonbValue * aScalar ,JsonbValue * bScalar )
1353+ equalsJsonbScalarValue (const JsonbValue * aScalar ,const JsonbValue * bScalar )
13531354{
13541355if (aScalar -> type == bScalar -> type )
13551356{
@@ -1381,7 +1382,7 @@ equalsJsonbScalarValue(JsonbValue *aScalar, JsonbValue *bScalar)
13811382 * operators, where a lexical sort order is generally expected.
13821383 */
13831384static int
1384- compareJsonbScalarValue (JsonbValue * aScalar ,JsonbValue * bScalar )
1385+ compareJsonbScalarValue (const JsonbValue * aScalar ,const JsonbValue * bScalar )
13851386{
13861387if (aScalar -> type == bScalar -> type )
13871388{
@@ -1496,7 +1497,7 @@ padBufferToInt(StringInfo buffer)
14961497 * Given a JsonbValue, convert to Jsonb. The result is palloc'd.
14971498 */
14981499static Jsonb *
1499- convertToJsonb (JsonbValue * val )
1500+ convertToJsonb (const JsonbValue * val )
15001501{
15011502StringInfoData buffer ;
15021503JEntry jentry ;
@@ -1538,7 +1539,7 @@ convertToJsonb(JsonbValue *val)
15381539 * for debugging purposes.
15391540 */
15401541static void
1541- convertJsonbValue (StringInfo buffer ,JEntry * header ,JsonbValue * val ,int level )
1542+ convertJsonbValue (StringInfo buffer ,JEntry * header ,const JsonbValue * val ,int level )
15421543{
15431544check_stack_depth ();
15441545
@@ -1563,7 +1564,7 @@ convertJsonbValue(StringInfo buffer, JEntry *header, JsonbValue *val, int level)
15631564}
15641565
15651566static void
1566- convertJsonbArray (StringInfo buffer ,JEntry * pheader ,JsonbValue * val ,int level )
1567+ convertJsonbArray (StringInfo buffer ,JEntry * pheader ,const JsonbValue * val ,int level )
15671568{
15681569int base_offset ;
15691570int jentry_offset ;
@@ -1647,7 +1648,7 @@ convertJsonbArray(StringInfo buffer, JEntry *pheader, JsonbValue *val, int level
16471648}
16481649
16491650static void
1650- convertJsonbObject (StringInfo buffer ,JEntry * pheader ,JsonbValue * val ,int level )
1651+ convertJsonbObject (StringInfo buffer ,JEntry * pheader ,const JsonbValue * val ,int level )
16511652{
16521653int base_offset ;
16531654int jentry_offset ;
@@ -1763,7 +1764,7 @@ convertJsonbObject(StringInfo buffer, JEntry *pheader, JsonbValue *val, int leve
17631764}
17641765
17651766static void
1766- convertJsonbScalar (StringInfo buffer ,JEntry * jentry ,JsonbValue * scalarVal )
1767+ convertJsonbScalar (StringInfo buffer ,JEntry * jentry ,const JsonbValue * scalarVal )
17671768{
17681769int numlen ;
17691770short padlen ;