@@ -44,11 +44,11 @@ struct JsonbParseState
44
44
struct JsonbIterator
45
45
{
46
46
/* Container being iterated */
47
- JsonbContainer * container ;
47
+ const JsonbContainer * container ;
48
48
uint32 nElems ;/* Number of elements in children array (will
49
49
* be nPairs for objects) */
50
50
bool isScalar ;/* Pseudo-array scalar value? */
51
- JEntry * children ;/* JEntrys for child nodes */
51
+ const JEntry * children ;/* JEntrys for child nodes */
52
52
/* Data proper. This points to the beginning of the variable-length data */
53
53
char * dataProper ;
54
54
@@ -71,16 +71,16 @@ struct JsonbIterator
71
71
struct JsonbIterator * parent ;
72
72
};
73
73
74
- static void fillJsonbValue (JsonbContainer * container ,int index ,
74
+ static void fillJsonbValue (const JsonbContainer * container ,int index ,
75
75
char * base_addr ,uint32 offset ,
76
76
JsonbValue * 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 );
84
84
85
85
static int reserveFromBuffer (StringInfo buffer ,int len );
86
86
static void appendToBuffer (StringInfo buffer ,const char * data ,int len );
@@ -90,17 +90,17 @@ static short padBufferToInt(StringInfo buffer);
90
90
static JsonbIterator * iteratorFromContainer (JsonbContainer * container ,JsonbIterator * parent );
91
91
static JsonbIterator * freeAndGetParent (JsonbIterator * it );
92
92
static 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 );
96
96
static int lengthCompareJsonbStringValue (const void * a ,const void * b );
97
97
static int lengthCompareJsonbPair (const void * a ,const void * b ,void * arg );
98
98
static 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 );
102
102
static JsonbValue * pushSingleScalarJsonbValue (JsonbParseState * * pstate ,
103
- JsonbValue * jbval );
103
+ const JsonbValue * jbval );
104
104
105
105
/*
106
106
* Turn an in-memory JsonbValue into a Jsonb for on-disk storage.
@@ -483,7 +483,7 @@ getIthJsonbValueFromContainer(JsonbContainer *container, uint32 i)
483
483
* expanded.
484
484
*/
485
485
static void
486
- fillJsonbValue (JsonbContainer * container ,int index ,
486
+ fillJsonbValue (const JsonbContainer * container ,int index ,
487
487
char * base_addr ,uint32 offset ,
488
488
JsonbValue * result )
489
489
{
@@ -571,7 +571,7 @@ JsonbParseStateClone(JsonbParseState *state)
571
571
*/
572
572
JsonbValue *
573
573
pushJsonbValue (JsonbParseState * * pstate ,JsonbIteratorToken seq ,
574
- JsonbValue * jbval )
574
+ const JsonbValue * jbval )
575
575
{
576
576
JsonbIterator * it ;
577
577
JsonbValue * res = NULL ;
@@ -600,7 +600,7 @@ pushJsonbValue(JsonbParseState **pstate, JsonbIteratorToken seq,
600
600
*/
601
601
static JsonbValue *
602
602
pushJsonbValueScalar (JsonbParseState * * pstate ,JsonbIteratorToken seq ,
603
- JsonbValue * scalarVal )
603
+ const JsonbValue * scalarVal )
604
604
{
605
605
JsonbValue * result = NULL ;
606
606
@@ -685,7 +685,7 @@ pushJsonbValueScalar(JsonbParseState **pstate, JsonbIteratorToken seq,
685
685
}
686
686
687
687
static JsonbValue *
688
- pushSingleScalarJsonbValue (JsonbParseState * * pstate ,JsonbValue * jbval )
688
+ pushSingleScalarJsonbValue (JsonbParseState * * pstate ,const JsonbValue * jbval )
689
689
{
690
690
/* single root scalar */
691
691
JsonbValue va ;
@@ -700,8 +700,8 @@ pushSingleScalarJsonbValue(JsonbParseState **pstate, JsonbValue *jbval)
700
700
}
701
701
702
702
static JsonbValue *
703
- pushNestedScalarJsonbValue (JsonbParseState * * pstate ,JsonbValue * jbval ,
704
- bool isKey )
703
+ pushNestedScalarJsonbValue (JsonbParseState * * pstate ,const JsonbValue * jbval ,
704
+ bool isKey )
705
705
{
706
706
switch ((* pstate )-> contVal .type )
707
707
{
@@ -716,7 +716,8 @@ pushNestedScalarJsonbValue(JsonbParseState **pstate, JsonbValue *jbval,
716
716
}
717
717
718
718
JsonbValue *
719
- pushScalarJsonbValue (JsonbParseState * * pstate ,JsonbValue * jbval ,bool isKey )
719
+ pushScalarJsonbValue (JsonbParseState * * pstate ,const JsonbValue * jbval ,
720
+ bool isKey )
720
721
{
721
722
return * pstate == NULL
722
723
?pushSingleScalarJsonbValue (pstate ,jbval )
@@ -740,7 +741,7 @@ pushState(JsonbParseState **pstate)
740
741
* pushJsonbValue() worker: Append a pair key to state when generating a Jsonb
741
742
*/
742
743
static void
743
- appendKey (JsonbParseState * pstate ,JsonbValue * string )
744
+ appendKey (JsonbParseState * pstate ,const JsonbValue * string )
744
745
{
745
746
JsonbValue * object = & pstate -> contVal ;
746
747
@@ -769,7 +770,7 @@ appendKey(JsonbParseState *pstate, JsonbValue *string)
769
770
* Jsonb
770
771
*/
771
772
static void
772
- appendValue (JsonbParseState * pstate ,JsonbValue * scalarVal )
773
+ appendValue (JsonbParseState * pstate ,const JsonbValue * scalarVal )
773
774
{
774
775
JsonbValue * object = & pstate -> contVal ;
775
776
@@ -782,7 +783,7 @@ appendValue(JsonbParseState *pstate, JsonbValue *scalarVal)
782
783
* pushJsonbValue() worker: Append an element to state when generating a Jsonb
783
784
*/
784
785
static void
785
- appendElement (JsonbParseState * pstate ,JsonbValue * scalarVal )
786
+ appendElement (JsonbParseState * pstate ,const JsonbValue * scalarVal )
786
787
{
787
788
JsonbValue * array = & pstate -> contVal ;
788
789
@@ -1349,7 +1350,7 @@ JsonbHashScalarValue(const JsonbValue *scalarVal, uint32 *hash)
1349
1350
* Are two scalar JsonbValues of the same type a and b equal?
1350
1351
*/
1351
1352
static bool
1352
- equalsJsonbScalarValue (JsonbValue * aScalar ,JsonbValue * bScalar )
1353
+ equalsJsonbScalarValue (const JsonbValue * aScalar ,const JsonbValue * bScalar )
1353
1354
{
1354
1355
if (aScalar -> type == bScalar -> type )
1355
1356
{
@@ -1381,7 +1382,7 @@ equalsJsonbScalarValue(JsonbValue *aScalar, JsonbValue *bScalar)
1381
1382
* operators, where a lexical sort order is generally expected.
1382
1383
*/
1383
1384
static int
1384
- compareJsonbScalarValue (JsonbValue * aScalar ,JsonbValue * bScalar )
1385
+ compareJsonbScalarValue (const JsonbValue * aScalar ,const JsonbValue * bScalar )
1385
1386
{
1386
1387
if (aScalar -> type == bScalar -> type )
1387
1388
{
@@ -1496,7 +1497,7 @@ padBufferToInt(StringInfo buffer)
1496
1497
* Given a JsonbValue, convert to Jsonb. The result is palloc'd.
1497
1498
*/
1498
1499
static Jsonb *
1499
- convertToJsonb (JsonbValue * val )
1500
+ convertToJsonb (const JsonbValue * val )
1500
1501
{
1501
1502
StringInfoData buffer ;
1502
1503
JEntry jentry ;
@@ -1538,7 +1539,7 @@ convertToJsonb(JsonbValue *val)
1538
1539
* for debugging purposes.
1539
1540
*/
1540
1541
static void
1541
- convertJsonbValue (StringInfo buffer ,JEntry * header ,JsonbValue * val ,int level )
1542
+ convertJsonbValue (StringInfo buffer ,JEntry * header ,const JsonbValue * val ,int level )
1542
1543
{
1543
1544
check_stack_depth ();
1544
1545
@@ -1563,7 +1564,7 @@ convertJsonbValue(StringInfo buffer, JEntry *header, JsonbValue *val, int level)
1563
1564
}
1564
1565
1565
1566
static void
1566
- convertJsonbArray (StringInfo buffer ,JEntry * pheader ,JsonbValue * val ,int level )
1567
+ convertJsonbArray (StringInfo buffer ,JEntry * pheader ,const JsonbValue * val ,int level )
1567
1568
{
1568
1569
int base_offset ;
1569
1570
int jentry_offset ;
@@ -1647,7 +1648,7 @@ convertJsonbArray(StringInfo buffer, JEntry *pheader, JsonbValue *val, int level
1647
1648
}
1648
1649
1649
1650
static void
1650
- convertJsonbObject (StringInfo buffer ,JEntry * pheader ,JsonbValue * val ,int level )
1651
+ convertJsonbObject (StringInfo buffer ,JEntry * pheader ,const JsonbValue * val ,int level )
1651
1652
{
1652
1653
int base_offset ;
1653
1654
int jentry_offset ;
@@ -1763,7 +1764,7 @@ convertJsonbObject(StringInfo buffer, JEntry *pheader, JsonbValue *val, int leve
1763
1764
}
1764
1765
1765
1766
static void
1766
- convertJsonbScalar (StringInfo buffer ,JEntry * jentry ,JsonbValue * scalarVal )
1767
+ convertJsonbScalar (StringInfo buffer ,JEntry * jentry ,const JsonbValue * scalarVal )
1767
1768
{
1768
1769
int numlen ;
1769
1770
short padlen ;