Skip to content

Commit 2bcf6bf

Browse files
author
Nikita Glukhov
committed
Add const qualifiers for JsonbValue * parameters
1 parent c50bcbf commit 2bcf6bf

File tree

2 files changed

+39
-37
lines changed

2 files changed

+39
-37
lines changed

src/backend/utils/adt/jsonb_util.c

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ struct JsonbParseState
4444
struct JsonbIterator
4545
{
4646
/* Container being iterated */
47-
JsonbContainer *container;
47+
const JsonbContainer *container;
4848
uint32 nElems; /* Number of elements in children array (will
4949
* be nPairs for objects) */
5050
bool 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 */
5353
char *dataProper;
5454

@@ -71,16 +71,16 @@ struct JsonbIterator
7171
struct JsonbIterator *parent;
7272
};
7373

74-
static void fillJsonbValue(JsonbContainer *container, int index,
74+
static void fillJsonbValue(const JsonbContainer *container, int index,
7575
char *base_addr, uint32 offset,
7676
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);
8484

8585
static int reserveFromBuffer(StringInfo buffer, int len);
8686
static void appendToBuffer(StringInfo buffer, const char *data, int len);
@@ -90,17 +90,17 @@ static short padBufferToInt(StringInfo buffer);
9090
static JsonbIterator *iteratorFromContainer(JsonbContainer *container, JsonbIterator *parent);
9191
static JsonbIterator *freeAndGetParent(JsonbIterator *it);
9292
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);
9696
static int lengthCompareJsonbStringValue(const void *a, const void *b);
9797
static int lengthCompareJsonbPair(const void *a, const void *b, void *arg);
9898
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);
102102
static 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
*/
485485
static void
486-
fillJsonbValue(JsonbContainer *container, int index,
486+
fillJsonbValue(const JsonbContainer *container, int index,
487487
char *base_addr, uint32 offset,
488488
JsonbValue *result)
489489
{
@@ -571,7 +571,7 @@ JsonbParseStateClone(JsonbParseState *state)
571571
*/
572572
JsonbValue *
573573
pushJsonbValue(JsonbParseState **pstate, JsonbIteratorToken seq,
574-
JsonbValue *jbval)
574+
const JsonbValue *jbval)
575575
{
576576
JsonbIterator *it;
577577
JsonbValue *res = NULL;
@@ -600,7 +600,7 @@ pushJsonbValue(JsonbParseState **pstate, JsonbIteratorToken seq,
600600
*/
601601
static JsonbValue *
602602
pushJsonbValueScalar(JsonbParseState **pstate, JsonbIteratorToken seq,
603-
JsonbValue *scalarVal)
603+
const JsonbValue *scalarVal)
604604
{
605605
JsonbValue *result = NULL;
606606

@@ -685,7 +685,7 @@ pushJsonbValueScalar(JsonbParseState **pstate, JsonbIteratorToken seq,
685685
}
686686

687687
static JsonbValue *
688-
pushSingleScalarJsonbValue(JsonbParseState **pstate, JsonbValue *jbval)
688+
pushSingleScalarJsonbValue(JsonbParseState **pstate, const JsonbValue *jbval)
689689
{
690690
/* single root scalar */
691691
JsonbValue va;
@@ -700,8 +700,8 @@ pushSingleScalarJsonbValue(JsonbParseState **pstate, JsonbValue *jbval)
700700
}
701701

702702
static JsonbValue *
703-
pushNestedScalarJsonbValue(JsonbParseState **pstate, JsonbValue *jbval,
704-
bool isKey)
703+
pushNestedScalarJsonbValue(JsonbParseState **pstate, const JsonbValue *jbval,
704+
bool isKey)
705705
{
706706
switch ((*pstate)->contVal.type)
707707
{
@@ -716,7 +716,8 @@ pushNestedScalarJsonbValue(JsonbParseState **pstate, JsonbValue *jbval,
716716
}
717717

718718
JsonbValue *
719-
pushScalarJsonbValue(JsonbParseState **pstate, JsonbValue *jbval, bool isKey)
719+
pushScalarJsonbValue(JsonbParseState **pstate, const JsonbValue *jbval,
720+
bool isKey)
720721
{
721722
return *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
*/
742743
static void
743-
appendKey(JsonbParseState *pstate, JsonbValue *string)
744+
appendKey(JsonbParseState *pstate, const JsonbValue *string)
744745
{
745746
JsonbValue *object = &pstate->contVal;
746747

@@ -769,7 +770,7 @@ appendKey(JsonbParseState *pstate, JsonbValue *string)
769770
* Jsonb
770771
*/
771772
static void
772-
appendValue(JsonbParseState *pstate, JsonbValue *scalarVal)
773+
appendValue(JsonbParseState *pstate, const JsonbValue *scalarVal)
773774
{
774775
JsonbValue *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
*/
784785
static void
785-
appendElement(JsonbParseState *pstate, JsonbValue *scalarVal)
786+
appendElement(JsonbParseState *pstate, const JsonbValue *scalarVal)
786787
{
787788
JsonbValue *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
*/
13511352
static bool
1352-
equalsJsonbScalarValue(JsonbValue *aScalar, JsonbValue *bScalar)
1353+
equalsJsonbScalarValue(const JsonbValue *aScalar, const JsonbValue *bScalar)
13531354
{
13541355
if (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
*/
13831384
static int
1384-
compareJsonbScalarValue(JsonbValue *aScalar, JsonbValue *bScalar)
1385+
compareJsonbScalarValue(const JsonbValue *aScalar, const JsonbValue *bScalar)
13851386
{
13861387
if (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
*/
14981499
static Jsonb *
1499-
convertToJsonb(JsonbValue *val)
1500+
convertToJsonb(const JsonbValue *val)
15001501
{
15011502
StringInfoData buffer;
15021503
JEntry jentry;
@@ -1538,7 +1539,7 @@ convertToJsonb(JsonbValue *val)
15381539
* for debugging purposes.
15391540
*/
15401541
static void
1541-
convertJsonbValue(StringInfo buffer, JEntry *header, JsonbValue *val, int level)
1542+
convertJsonbValue(StringInfo buffer, JEntry *header, const JsonbValue *val, int level)
15421543
{
15431544
check_stack_depth();
15441545

@@ -1563,7 +1564,7 @@ convertJsonbValue(StringInfo buffer, JEntry *header, JsonbValue *val, int level)
15631564
}
15641565

15651566
static void
1566-
convertJsonbArray(StringInfo buffer, JEntry *pheader, JsonbValue *val, int level)
1567+
convertJsonbArray(StringInfo buffer, JEntry *pheader, const JsonbValue *val, int level)
15671568
{
15681569
int base_offset;
15691570
int jentry_offset;
@@ -1647,7 +1648,7 @@ convertJsonbArray(StringInfo buffer, JEntry *pheader, JsonbValue *val, int level
16471648
}
16481649

16491650
static void
1650-
convertJsonbObject(StringInfo buffer, JEntry *pheader, JsonbValue *val, int level)
1651+
convertJsonbObject(StringInfo buffer, JEntry *pheader, const JsonbValue *val, int level)
16511652
{
16521653
int base_offset;
16531654
int jentry_offset;
@@ -1763,7 +1764,7 @@ convertJsonbObject(StringInfo buffer, JEntry *pheader, JsonbValue *val, int leve
17631764
}
17641765

17651766
static void
1766-
convertJsonbScalar(StringInfo buffer, JEntry *jentry, JsonbValue *scalarVal)
1767+
convertJsonbScalar(StringInfo buffer, JEntry *jentry, const JsonbValue *scalarVal)
17671768
{
17681769
int numlen;
17691770
short padlen;

src/include/utils/jsonb.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,15 +321,16 @@ typedef struct JsonbIterator JsonbIterator;
321321

322322
/* Support functions */
323323
extern int compareJsonbContainers(JsonbContainer *a, JsonbContainer *b);
324-
extern JsonbValue *findJsonbValueFromContainer(JsonbContainer *sheader,
324+
extern JsonbValue *findJsonbValueFromContainer(const JsonbContainer *sheader,
325325
uint32 flags,
326326
JsonbValue *key);
327327
extern JsonbValue *getIthJsonbValueFromContainer(JsonbContainer *sheader,
328328
uint32 i);
329329
extern JsonbValue *pushJsonbValue(JsonbParseState **pstate,
330-
JsonbIteratorToken seq, JsonbValue *jbVal);
330+
JsonbIteratorToken seq,
331+
const JsonbValue *jbVal);
331332
extern JsonbValue *pushScalarJsonbValue(JsonbParseState **pstate,
332-
JsonbValue *jbval, bool isKey);
333+
const JsonbValue *jbval, bool isKey);
333334
extern JsonbParseState *JsonbParseStateClone(JsonbParseState *state);
334335
extern JsonbIterator *JsonbIteratorInit(JsonbContainer *container);
335336
extern JsonbIteratorToken JsonbIteratorNext(JsonbIterator **it, JsonbValue *val,

0 commit comments

Comments
 (0)