Skip to content

Commit 7619b18

Browse files
author
Nikita Glukhov
committed
Add const qualifiers for JsonbValue * parameters
1 parent e3a5760 commit 7619b18

File tree

2 files changed

+41
-39
lines changed

2 files changed

+41
-39
lines changed

src/backend/utils/adt/jsonb_util.c

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ struct JsonbParseState
4848
struct JsonbIterator
4949
{
5050
/* Container being iterated */
51-
JsonbContainer *container;
51+
const JsonbContainer *container;
5252
uint32 nElems; /* Number of elements in children array (will
5353
* be nPairs for objects) */
5454
bool isScalar; /* Pseudo-array scalar value? */
55-
JEntry *children; /* JEntrys for child nodes */
55+
const JEntry *children; /* JEntrys for child nodes */
5656
/* Data proper. This points to the beginning of the variable-length data */
5757
char *dataProper;
5858

@@ -75,16 +75,16 @@ struct JsonbIterator
7575
struct JsonbIterator *parent;
7676
};
7777

78-
static void fillJsonbValue(JsonbContainer *container, int index,
78+
static void fillJsonbValue(const JsonbContainer *container, int index,
7979
char *base_addr, uint32 offset,
8080
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);
8888

8989
static int reserveFromBuffer(StringInfo buffer, int len);
9090
static void appendToBuffer(StringInfo buffer, const char *data, int len);
@@ -94,19 +94,19 @@ static short padBufferToInt(StringInfo buffer);
9494
static JsonbIterator *iteratorFromContainer(JsonbContainer *container, JsonbIterator *parent);
9595
static JsonbIterator *freeAndGetParent(JsonbIterator *it);
9696
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);
100100
static int lengthCompareJsonbStringValue(const void *a, const void *b);
101101
static int lengthCompareJsonbString(const char *val1, int len1,
102102
const char *val2, int len2);
103103
static int lengthCompareJsonbPair(const void *a, const void *b, void *arg);
104104
static void uniqueifyJsonbObject(JsonbValue *object);
105105
static JsonbValue *pushJsonbValueScalar(JsonbParseState **pstate,
106106
JsonbIteratorToken seq,
107-
JsonbValue *scalarVal);
107+
const JsonbValue *scalarVal);
108108
static JsonbValue *pushSingleScalarJsonbValue(JsonbParseState **pstate,
109-
JsonbValue *jbval);
109+
const JsonbValue *jbval);
110110

111111
void
112112
JsonbToJsonbValue(Jsonb *jsonb, JsonbValue *val)
@@ -371,10 +371,10 @@ compareJsonbContainers(JsonbContainer *a, JsonbContainer *b)
371371
* return NULL. Otherwise, return palloc()'d copy of value.
372372
*/
373373
JsonbValue *
374-
findJsonbValueFromContainer(JsonbContainer *container, uint32 flags,
374+
findJsonbValueFromContainer(const JsonbContainer *container, uint32 flags,
375375
JsonbValue *key)
376376
{
377-
JEntry *children = container->children;
377+
const JEntry *children = container->children;
378378
int count = JsonContainerSize(container);
379379

380380
Assert((flags & ~(JB_FARRAY | JB_FOBJECT)) == 0);
@@ -425,10 +425,10 @@ findJsonbValueFromContainer(JsonbContainer *container, uint32 flags,
425425
* 'res' can be passed in as NULL, in which case it's newly palloc'ed here.
426426
*/
427427
JsonbValue *
428-
getKeyJsonValueFromContainer(JsonbContainer *container,
428+
getKeyJsonValueFromContainer(const JsonbContainer *container,
429429
const char *keyVal, int keyLen, JsonbValue *res)
430430
{
431-
JEntry *children = container->children;
431+
const JEntry *children = container->children;
432432
int count = JsonContainerSize(container);
433433
char *baseAddr;
434434
uint32 stopLow,
@@ -532,7 +532,7 @@ getIthJsonbValueFromContainer(JsonbContainer *container, uint32 i)
532532
* expanded.
533533
*/
534534
static void
535-
fillJsonbValue(JsonbContainer *container, int index,
535+
fillJsonbValue(const JsonbContainer *container, int index,
536536
char *base_addr, uint32 offset,
537537
JsonbValue *result)
538538
{
@@ -620,7 +620,7 @@ JsonbParseStateClone(JsonbParseState *state)
620620
*/
621621
JsonbValue *
622622
pushJsonbValue(JsonbParseState **pstate, JsonbIteratorToken seq,
623-
JsonbValue *jbval)
623+
const JsonbValue *jbval)
624624
{
625625
JsonbIterator *it;
626626
JsonbValue *res = NULL;
@@ -694,7 +694,7 @@ pushJsonbValue(JsonbParseState **pstate, JsonbIteratorToken seq,
694694
*/
695695
static JsonbValue *
696696
pushJsonbValueScalar(JsonbParseState **pstate, JsonbIteratorToken seq,
697-
JsonbValue *scalarVal)
697+
const JsonbValue *scalarVal)
698698
{
699699
JsonbValue *result = NULL;
700700

@@ -779,7 +779,7 @@ pushJsonbValueScalar(JsonbParseState **pstate, JsonbIteratorToken seq,
779779
}
780780

781781
static JsonbValue *
782-
pushSingleScalarJsonbValue(JsonbParseState **pstate, JsonbValue *jbval)
782+
pushSingleScalarJsonbValue(JsonbParseState **pstate, const JsonbValue *jbval)
783783
{
784784
/* single root scalar */
785785
JsonbValue va;
@@ -794,7 +794,7 @@ pushSingleScalarJsonbValue(JsonbParseState **pstate, JsonbValue *jbval)
794794
}
795795

796796
static JsonbValue *
797-
pushNestedScalarJsonbValue(JsonbParseState **pstate, JsonbValue *jbval,
797+
pushNestedScalarJsonbValue(JsonbParseState **pstate, const JsonbValue *jbval,
798798
bool isKey)
799799
{
800800
switch ((*pstate)->contVal.type)
@@ -810,7 +810,8 @@ pushNestedScalarJsonbValue(JsonbParseState **pstate, JsonbValue *jbval,
810810
}
811811

812812
JsonbValue *
813-
pushScalarJsonbValue(JsonbParseState **pstate, JsonbValue *jbval, bool isKey)
813+
pushScalarJsonbValue(JsonbParseState **pstate, const JsonbValue *jbval,
814+
bool isKey)
814815
{
815816
return *pstate == NULL
816817
? pushSingleScalarJsonbValue(pstate, jbval)
@@ -834,7 +835,7 @@ pushState(JsonbParseState **pstate)
834835
* pushJsonbValue() worker: Append a pair key to state when generating a Jsonb
835836
*/
836837
static void
837-
appendKey(JsonbParseState *pstate, JsonbValue *string)
838+
appendKey(JsonbParseState *pstate, const JsonbValue *string)
838839
{
839840
JsonbValue *object = &pstate->contVal;
840841

@@ -863,7 +864,7 @@ appendKey(JsonbParseState *pstate, JsonbValue *string)
863864
* Jsonb
864865
*/
865866
static void
866-
appendValue(JsonbParseState *pstate, JsonbValue *scalarVal)
867+
appendValue(JsonbParseState *pstate, const JsonbValue *scalarVal)
867868
{
868869
JsonbValue *object = &pstate->contVal;
869870

@@ -876,7 +877,7 @@ appendValue(JsonbParseState *pstate, JsonbValue *scalarVal)
876877
* pushJsonbValue() worker: Append an element to state when generating a Jsonb
877878
*/
878879
static void
879-
appendElement(JsonbParseState *pstate, JsonbValue *scalarVal)
880+
appendElement(JsonbParseState *pstate, const JsonbValue *scalarVal)
880881
{
881882
JsonbValue *array = &pstate->contVal;
882883

@@ -1489,7 +1490,7 @@ JsonbHashScalarValueExtended(const JsonbValue *scalarVal, uint64 *hash,
14891490
* Are two scalar JsonbValues of the same type a and b equal?
14901491
*/
14911492
static bool
1492-
equalsJsonbScalarValue(JsonbValue *aScalar, JsonbValue *bScalar)
1493+
equalsJsonbScalarValue(const JsonbValue *aScalar, const JsonbValue *bScalar)
14931494
{
14941495
if (aScalar->type == bScalar->type)
14951496
{
@@ -1521,7 +1522,7 @@ equalsJsonbScalarValue(JsonbValue *aScalar, JsonbValue *bScalar)
15211522
* operators, where a lexical sort order is generally expected.
15221523
*/
15231524
static int
1524-
compareJsonbScalarValue(JsonbValue *aScalar, JsonbValue *bScalar)
1525+
compareJsonbScalarValue(const JsonbValue *aScalar, const JsonbValue *bScalar)
15251526
{
15261527
if (aScalar->type == bScalar->type)
15271528
{
@@ -1636,7 +1637,7 @@ padBufferToInt(StringInfo buffer)
16361637
* Given a JsonbValue, convert to Jsonb. The result is palloc'd.
16371638
*/
16381639
static Jsonb *
1639-
convertToJsonb(JsonbValue *val)
1640+
convertToJsonb(const JsonbValue *val)
16401641
{
16411642
StringInfoData buffer;
16421643
JEntry jentry;
@@ -1678,7 +1679,7 @@ convertToJsonb(JsonbValue *val)
16781679
* for debugging purposes.
16791680
*/
16801681
static void
1681-
convertJsonbValue(StringInfo buffer, JEntry *header, JsonbValue *val, int level)
1682+
convertJsonbValue(StringInfo buffer, JEntry *header, const JsonbValue *val, int level)
16821683
{
16831684
check_stack_depth();
16841685

@@ -1703,7 +1704,7 @@ convertJsonbValue(StringInfo buffer, JEntry *header, JsonbValue *val, int level)
17031704
}
17041705

17051706
static void
1706-
convertJsonbArray(StringInfo buffer, JEntry *pheader, JsonbValue *val, int level)
1707+
convertJsonbArray(StringInfo buffer, JEntry *pheader, const JsonbValue *val, int level)
17071708
{
17081709
int base_offset;
17091710
int jentry_offset;
@@ -1787,7 +1788,7 @@ convertJsonbArray(StringInfo buffer, JEntry *pheader, JsonbValue *val, int level
17871788
}
17881789

17891790
static void
1790-
convertJsonbObject(StringInfo buffer, JEntry *pheader, JsonbValue *val, int level)
1791+
convertJsonbObject(StringInfo buffer, JEntry *pheader, const JsonbValue *val, int level)
17911792
{
17921793
int base_offset;
17931794
int jentry_offset;
@@ -1903,7 +1904,7 @@ convertJsonbObject(StringInfo buffer, JEntry *pheader, JsonbValue *val, int leve
19031904
}
19041905

19051906
static void
1906-
convertJsonbScalar(StringInfo buffer, JEntry *jentry, JsonbValue *scalarVal)
1907+
convertJsonbScalar(StringInfo buffer, JEntry *jentry, const JsonbValue *scalarVal)
19071908
{
19081909
int numlen;
19091910
short padlen;

src/include/utils/jsonb.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,18 +344,19 @@ typedef struct JsonbIterator JsonbIterator;
344344

345345
/* Support functions */
346346
extern int compareJsonbContainers(JsonbContainer *a, JsonbContainer *b);
347-
extern JsonbValue *findJsonbValueFromContainer(JsonbContainer *sheader,
347+
extern JsonbValue *findJsonbValueFromContainer(const JsonbContainer *sheader,
348348
uint32 flags,
349349
JsonbValue *key);
350-
extern JsonbValue *getKeyJsonValueFromContainer(JsonbContainer *container,
350+
extern JsonbValue *getKeyJsonValueFromContainer(const JsonbContainer *container,
351351
const char *keyVal, int keyLen,
352352
JsonbValue *res);
353353
extern JsonbValue *getIthJsonbValueFromContainer(JsonbContainer *sheader,
354354
uint32 i);
355355
extern JsonbValue *pushJsonbValue(JsonbParseState **pstate,
356-
JsonbIteratorToken seq, JsonbValue *jbval);
356+
JsonbIteratorToken seq,
357+
const JsonbValue *jbval);
357358
extern JsonbValue *pushScalarJsonbValue(JsonbParseState **pstate,
358-
JsonbValue *jbval, bool isKey);
359+
const JsonbValue *jbval, bool isKey);
359360
extern JsonbParseState *JsonbParseStateClone(JsonbParseState *state);
360361
extern JsonbIterator *JsonbIteratorInit(JsonbContainer *container);
361362
extern JsonbIteratorToken JsonbIteratorNext(JsonbIterator **it, JsonbValue *val,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy