@@ -48,11 +48,11 @@ struct JsonbParseState
48
48
struct JsonbIterator
49
49
{
50
50
/* Container being iterated */
51
- JsonbContainer * container ;
51
+ const JsonbContainer * container ;
52
52
uint32 nElems ;/* Number of elements in children array (will
53
53
* be nPairs for objects) */
54
54
bool isScalar ;/* Pseudo-array scalar value? */
55
- JEntry * children ;/* JEntrys for child nodes */
55
+ const JEntry * children ;/* JEntrys for child nodes */
56
56
/* Data proper. This points to the beginning of the variable-length data */
57
57
char * dataProper ;
58
58
@@ -75,16 +75,16 @@ struct JsonbIterator
75
75
struct JsonbIterator * parent ;
76
76
};
77
77
78
- static void fillJsonbValue (JsonbContainer * container ,int index ,
78
+ static void fillJsonbValue (const JsonbContainer * container ,int index ,
79
79
char * base_addr ,uint32 offset ,
80
80
JsonbValue * result );
81
- static bool equalsJsonbScalarValue (JsonbValue * a ,JsonbValue * b );
82
- static int compareJsonbScalarValue (JsonbValue * a ,JsonbValue * b );
83
- static Jsonb * convertToJsonb (JsonbValue * val );
84
- static void convertJsonbValue (StringInfo buffer ,JEntry * header ,JsonbValue * val ,int level );
85
- static void convertJsonbArray (StringInfo buffer ,JEntry * header ,JsonbValue * val ,int level );
86
- static void convertJsonbObject (StringInfo buffer ,JEntry * header ,JsonbValue * val ,int level );
87
- static void convertJsonbScalar (StringInfo buffer ,JEntry * header ,JsonbValue * scalarVal );
81
+ static bool equalsJsonbScalarValue (const JsonbValue * a ,const JsonbValue * b );
82
+ static int compareJsonbScalarValue (const JsonbValue * a ,const JsonbValue * b );
83
+ static Jsonb * convertToJsonb (const JsonbValue * val );
84
+ static void convertJsonbValue (StringInfo buffer ,JEntry * header ,const JsonbValue * val ,int level );
85
+ static void convertJsonbArray (StringInfo buffer ,JEntry * header ,const JsonbValue * val ,int level );
86
+ static void convertJsonbObject (StringInfo buffer ,JEntry * header ,const JsonbValue * val ,int level );
87
+ static void convertJsonbScalar (StringInfo buffer ,JEntry * header ,const JsonbValue * scalarVal );
88
88
89
89
static int reserveFromBuffer (StringInfo buffer ,int len );
90
90
static void appendToBuffer (StringInfo buffer ,const char * data ,int len );
@@ -94,19 +94,19 @@ static short padBufferToInt(StringInfo buffer);
94
94
static JsonbIterator * iteratorFromContainer (JsonbContainer * container ,JsonbIterator * parent );
95
95
static JsonbIterator * freeAndGetParent (JsonbIterator * it );
96
96
static JsonbParseState * pushState (JsonbParseState * * pstate );
97
- static void appendKey (JsonbParseState * pstate ,JsonbValue * scalarVal );
98
- static void appendValue (JsonbParseState * pstate ,JsonbValue * scalarVal );
99
- static void appendElement (JsonbParseState * pstate ,JsonbValue * scalarVal );
97
+ static void appendKey (JsonbParseState * pstate ,const JsonbValue * scalarVal );
98
+ static void appendValue (JsonbParseState * pstate ,const JsonbValue * scalarVal );
99
+ static void appendElement (JsonbParseState * pstate ,const JsonbValue * scalarVal );
100
100
static int lengthCompareJsonbStringValue (const void * a ,const void * b );
101
101
static int lengthCompareJsonbString (const char * val1 ,int len1 ,
102
102
const char * val2 ,int len2 );
103
103
static int lengthCompareJsonbPair (const void * a ,const void * b ,void * arg );
104
104
static void uniqueifyJsonbObject (JsonbValue * object );
105
105
static JsonbValue * pushJsonbValueScalar (JsonbParseState * * pstate ,
106
106
JsonbIteratorToken seq ,
107
- JsonbValue * scalarVal );
107
+ const JsonbValue * scalarVal );
108
108
static JsonbValue * pushSingleScalarJsonbValue (JsonbParseState * * pstate ,
109
- JsonbValue * jbval );
109
+ const JsonbValue * jbval );
110
110
111
111
void
112
112
JsonbToJsonbValue (Jsonb * jsonb ,JsonbValue * val )
@@ -371,10 +371,10 @@ compareJsonbContainers(JsonbContainer *a, JsonbContainer *b)
371
371
* return NULL. Otherwise, return palloc()'d copy of value.
372
372
*/
373
373
JsonbValue *
374
- findJsonbValueFromContainer (JsonbContainer * container ,uint32 flags ,
374
+ findJsonbValueFromContainer (const JsonbContainer * container ,uint32 flags ,
375
375
JsonbValue * key )
376
376
{
377
- JEntry * children = container -> children ;
377
+ const JEntry * children = container -> children ;
378
378
int count = JsonContainerSize (container );
379
379
380
380
Assert ((flags & ~(JB_FARRAY |JB_FOBJECT ))== 0 );
@@ -425,10 +425,10 @@ findJsonbValueFromContainer(JsonbContainer *container, uint32 flags,
425
425
* 'res' can be passed in as NULL, in which case it's newly palloc'ed here.
426
426
*/
427
427
JsonbValue *
428
- getKeyJsonValueFromContainer (JsonbContainer * container ,
428
+ getKeyJsonValueFromContainer (const JsonbContainer * container ,
429
429
const char * keyVal ,int keyLen ,JsonbValue * res )
430
430
{
431
- JEntry * children = container -> children ;
431
+ const JEntry * children = container -> children ;
432
432
int count = JsonContainerSize (container );
433
433
char * baseAddr ;
434
434
uint32 stopLow ,
@@ -532,7 +532,7 @@ getIthJsonbValueFromContainer(JsonbContainer *container, uint32 i)
532
532
* expanded.
533
533
*/
534
534
static void
535
- fillJsonbValue (JsonbContainer * container ,int index ,
535
+ fillJsonbValue (const JsonbContainer * container ,int index ,
536
536
char * base_addr ,uint32 offset ,
537
537
JsonbValue * result )
538
538
{
@@ -620,7 +620,7 @@ JsonbParseStateClone(JsonbParseState *state)
620
620
*/
621
621
JsonbValue *
622
622
pushJsonbValue (JsonbParseState * * pstate ,JsonbIteratorToken seq ,
623
- JsonbValue * jbval )
623
+ const JsonbValue * jbval )
624
624
{
625
625
JsonbIterator * it ;
626
626
JsonbValue * res = NULL ;
@@ -694,7 +694,7 @@ pushJsonbValue(JsonbParseState **pstate, JsonbIteratorToken seq,
694
694
*/
695
695
static JsonbValue *
696
696
pushJsonbValueScalar (JsonbParseState * * pstate ,JsonbIteratorToken seq ,
697
- JsonbValue * scalarVal )
697
+ const JsonbValue * scalarVal )
698
698
{
699
699
JsonbValue * result = NULL ;
700
700
@@ -779,7 +779,7 @@ pushJsonbValueScalar(JsonbParseState **pstate, JsonbIteratorToken seq,
779
779
}
780
780
781
781
static JsonbValue *
782
- pushSingleScalarJsonbValue (JsonbParseState * * pstate ,JsonbValue * jbval )
782
+ pushSingleScalarJsonbValue (JsonbParseState * * pstate ,const JsonbValue * jbval )
783
783
{
784
784
/* single root scalar */
785
785
JsonbValue va ;
@@ -794,7 +794,7 @@ pushSingleScalarJsonbValue(JsonbParseState **pstate, JsonbValue *jbval)
794
794
}
795
795
796
796
static JsonbValue *
797
- pushNestedScalarJsonbValue (JsonbParseState * * pstate ,JsonbValue * jbval ,
797
+ pushNestedScalarJsonbValue (JsonbParseState * * pstate ,const JsonbValue * jbval ,
798
798
bool isKey )
799
799
{
800
800
switch ((* pstate )-> contVal .type )
@@ -810,7 +810,8 @@ pushNestedScalarJsonbValue(JsonbParseState **pstate, JsonbValue *jbval,
810
810
}
811
811
812
812
JsonbValue *
813
- pushScalarJsonbValue (JsonbParseState * * pstate ,JsonbValue * jbval ,bool isKey )
813
+ pushScalarJsonbValue (JsonbParseState * * pstate ,const JsonbValue * jbval ,
814
+ bool isKey )
814
815
{
815
816
return * pstate == NULL
816
817
?pushSingleScalarJsonbValue (pstate ,jbval )
@@ -834,7 +835,7 @@ pushState(JsonbParseState **pstate)
834
835
* pushJsonbValue() worker: Append a pair key to state when generating a Jsonb
835
836
*/
836
837
static void
837
- appendKey (JsonbParseState * pstate ,JsonbValue * string )
838
+ appendKey (JsonbParseState * pstate ,const JsonbValue * string )
838
839
{
839
840
JsonbValue * object = & pstate -> contVal ;
840
841
@@ -863,7 +864,7 @@ appendKey(JsonbParseState *pstate, JsonbValue *string)
863
864
* Jsonb
864
865
*/
865
866
static void
866
- appendValue (JsonbParseState * pstate ,JsonbValue * scalarVal )
867
+ appendValue (JsonbParseState * pstate ,const JsonbValue * scalarVal )
867
868
{
868
869
JsonbValue * object = & pstate -> contVal ;
869
870
@@ -876,7 +877,7 @@ appendValue(JsonbParseState *pstate, JsonbValue *scalarVal)
876
877
* pushJsonbValue() worker: Append an element to state when generating a Jsonb
877
878
*/
878
879
static void
879
- appendElement (JsonbParseState * pstate ,JsonbValue * scalarVal )
880
+ appendElement (JsonbParseState * pstate ,const JsonbValue * scalarVal )
880
881
{
881
882
JsonbValue * array = & pstate -> contVal ;
882
883
@@ -1489,7 +1490,7 @@ JsonbHashScalarValueExtended(const JsonbValue *scalarVal, uint64 *hash,
1489
1490
* Are two scalar JsonbValues of the same type a and b equal?
1490
1491
*/
1491
1492
static bool
1492
- equalsJsonbScalarValue (JsonbValue * aScalar ,JsonbValue * bScalar )
1493
+ equalsJsonbScalarValue (const JsonbValue * aScalar ,const JsonbValue * bScalar )
1493
1494
{
1494
1495
if (aScalar -> type == bScalar -> type )
1495
1496
{
@@ -1521,7 +1522,7 @@ equalsJsonbScalarValue(JsonbValue *aScalar, JsonbValue *bScalar)
1521
1522
* operators, where a lexical sort order is generally expected.
1522
1523
*/
1523
1524
static int
1524
- compareJsonbScalarValue (JsonbValue * aScalar ,JsonbValue * bScalar )
1525
+ compareJsonbScalarValue (const JsonbValue * aScalar ,const JsonbValue * bScalar )
1525
1526
{
1526
1527
if (aScalar -> type == bScalar -> type )
1527
1528
{
@@ -1636,7 +1637,7 @@ padBufferToInt(StringInfo buffer)
1636
1637
* Given a JsonbValue, convert to Jsonb. The result is palloc'd.
1637
1638
*/
1638
1639
static Jsonb *
1639
- convertToJsonb (JsonbValue * val )
1640
+ convertToJsonb (const JsonbValue * val )
1640
1641
{
1641
1642
StringInfoData buffer ;
1642
1643
JEntry jentry ;
@@ -1678,7 +1679,7 @@ convertToJsonb(JsonbValue *val)
1678
1679
* for debugging purposes.
1679
1680
*/
1680
1681
static void
1681
- convertJsonbValue (StringInfo buffer ,JEntry * header ,JsonbValue * val ,int level )
1682
+ convertJsonbValue (StringInfo buffer ,JEntry * header ,const JsonbValue * val ,int level )
1682
1683
{
1683
1684
check_stack_depth ();
1684
1685
@@ -1703,7 +1704,7 @@ convertJsonbValue(StringInfo buffer, JEntry *header, JsonbValue *val, int level)
1703
1704
}
1704
1705
1705
1706
static void
1706
- convertJsonbArray (StringInfo buffer ,JEntry * pheader ,JsonbValue * val ,int level )
1707
+ convertJsonbArray (StringInfo buffer ,JEntry * pheader ,const JsonbValue * val ,int level )
1707
1708
{
1708
1709
int base_offset ;
1709
1710
int jentry_offset ;
@@ -1787,7 +1788,7 @@ convertJsonbArray(StringInfo buffer, JEntry *pheader, JsonbValue *val, int level
1787
1788
}
1788
1789
1789
1790
static void
1790
- convertJsonbObject (StringInfo buffer ,JEntry * pheader ,JsonbValue * val ,int level )
1791
+ convertJsonbObject (StringInfo buffer ,JEntry * pheader ,const JsonbValue * val ,int level )
1791
1792
{
1792
1793
int base_offset ;
1793
1794
int jentry_offset ;
@@ -1903,7 +1904,7 @@ convertJsonbObject(StringInfo buffer, JEntry *pheader, JsonbValue *val, int leve
1903
1904
}
1904
1905
1905
1906
static void
1906
- convertJsonbScalar (StringInfo buffer ,JEntry * jentry ,JsonbValue * scalarVal )
1907
+ convertJsonbScalar (StringInfo buffer ,JEntry * jentry ,const JsonbValue * scalarVal )
1907
1908
{
1908
1909
int numlen ;
1909
1910
short padlen ;