Skip to content

Commit bbca0fe

Browse files
author
Nikita Glukhov
committed
Add const qualifiers for JsonbValue * parameters
1 parent 4617946 commit bbca0fe

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: 34 additions & 33 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
/*
112112
* Turn an in-memory JsonbValue into a Jsonb for on-disk storage.
@@ -418,7 +418,7 @@ findJsonbValueFromContainer(JsonbContainer *container, uint32 flags,
418418
* 'res' can be passed in as NULL, in which case it's newly palloc'ed here.
419419
*/
420420
JsonbValue *
421-
getKeyJsonValueFromContainer(JsonbContainer *container,
421+
getKeyJsonValueFromContainer(const JsonbContainer *container,
422422
const char *keyVal, int keyLen, JsonbValue *res)
423423
{
424424
JEntry *children = container->children;
@@ -525,7 +525,7 @@ getIthJsonbValueFromContainer(JsonbContainer *container, uint32 i)
525525
* expanded.
526526
*/
527527
static void
528-
fillJsonbValue(JsonbContainer *container, int index,
528+
fillJsonbValue(const JsonbContainer *container, int index,
529529
char *base_addr, uint32 offset,
530530
JsonbValue *result)
531531
{
@@ -613,7 +613,7 @@ JsonbParseStateClone(JsonbParseState *state)
613613
*/
614614
JsonbValue *
615615
pushJsonbValue(JsonbParseState **pstate, JsonbIteratorToken seq,
616-
JsonbValue *jbval)
616+
const JsonbValue *jbval)
617617
{
618618
JsonbIterator *it;
619619
JsonbValue *res = NULL;
@@ -642,7 +642,7 @@ pushJsonbValue(JsonbParseState **pstate, JsonbIteratorToken seq,
642642
*/
643643
static JsonbValue *
644644
pushJsonbValueScalar(JsonbParseState **pstate, JsonbIteratorToken seq,
645-
JsonbValue *scalarVal)
645+
const JsonbValue *scalarVal)
646646
{
647647
JsonbValue *result = NULL;
648648

@@ -727,7 +727,7 @@ pushJsonbValueScalar(JsonbParseState **pstate, JsonbIteratorToken seq,
727727
}
728728

729729
static JsonbValue *
730-
pushSingleScalarJsonbValue(JsonbParseState **pstate, JsonbValue *jbval)
730+
pushSingleScalarJsonbValue(JsonbParseState **pstate, const JsonbValue *jbval)
731731
{
732732
/* single root scalar */
733733
JsonbValue va;
@@ -742,8 +742,8 @@ pushSingleScalarJsonbValue(JsonbParseState **pstate, JsonbValue *jbval)
742742
}
743743

744744
static JsonbValue *
745-
pushNestedScalarJsonbValue(JsonbParseState **pstate, JsonbValue *jbval,
746-
bool isKey)
745+
pushNestedScalarJsonbValue(JsonbParseState **pstate, const JsonbValue *jbval,
746+
bool isKey)
747747
{
748748
switch ((*pstate)->contVal.type)
749749
{
@@ -758,7 +758,8 @@ pushNestedScalarJsonbValue(JsonbParseState **pstate, JsonbValue *jbval,
758758
}
759759

760760
JsonbValue *
761-
pushScalarJsonbValue(JsonbParseState **pstate, JsonbValue *jbval, bool isKey)
761+
pushScalarJsonbValue(JsonbParseState **pstate, const JsonbValue *jbval,
762+
bool isKey)
762763
{
763764
return *pstate == NULL
764765
? pushSingleScalarJsonbValue(pstate, jbval)
@@ -782,7 +783,7 @@ pushState(JsonbParseState **pstate)
782783
* pushJsonbValue() worker: Append a pair key to state when generating a Jsonb
783784
*/
784785
static void
785-
appendKey(JsonbParseState *pstate, JsonbValue *string)
786+
appendKey(JsonbParseState *pstate, const JsonbValue *string)
786787
{
787788
JsonbValue *object = &pstate->contVal;
788789

@@ -811,7 +812,7 @@ appendKey(JsonbParseState *pstate, JsonbValue *string)
811812
* Jsonb
812813
*/
813814
static void
814-
appendValue(JsonbParseState *pstate, JsonbValue *scalarVal)
815+
appendValue(JsonbParseState *pstate, const JsonbValue *scalarVal)
815816
{
816817
JsonbValue *object = &pstate->contVal;
817818

@@ -824,7 +825,7 @@ appendValue(JsonbParseState *pstate, JsonbValue *scalarVal)
824825
* pushJsonbValue() worker: Append an element to state when generating a Jsonb
825826
*/
826827
static void
827-
appendElement(JsonbParseState *pstate, JsonbValue *scalarVal)
828+
appendElement(JsonbParseState *pstate, const JsonbValue *scalarVal)
828829
{
829830
JsonbValue *array = &pstate->contVal;
830831

@@ -1437,7 +1438,7 @@ JsonbHashScalarValueExtended(const JsonbValue *scalarVal, uint64 *hash,
14371438
* Are two scalar JsonbValues of the same type a and b equal?
14381439
*/
14391440
static bool
1440-
equalsJsonbScalarValue(JsonbValue *aScalar, JsonbValue *bScalar)
1441+
equalsJsonbScalarValue(const JsonbValue *aScalar, const JsonbValue *bScalar)
14411442
{
14421443
if (aScalar->type == bScalar->type)
14431444
{
@@ -1469,7 +1470,7 @@ equalsJsonbScalarValue(JsonbValue *aScalar, JsonbValue *bScalar)
14691470
* operators, where a lexical sort order is generally expected.
14701471
*/
14711472
static int
1472-
compareJsonbScalarValue(JsonbValue *aScalar, JsonbValue *bScalar)
1473+
compareJsonbScalarValue(const JsonbValue *aScalar, const JsonbValue *bScalar)
14731474
{
14741475
if (aScalar->type == bScalar->type)
14751476
{
@@ -1584,7 +1585,7 @@ padBufferToInt(StringInfo buffer)
15841585
* Given a JsonbValue, convert to Jsonb. The result is palloc'd.
15851586
*/
15861587
static Jsonb *
1587-
convertToJsonb(JsonbValue *val)
1588+
convertToJsonb(const JsonbValue *val)
15881589
{
15891590
StringInfoData buffer;
15901591
JEntry jentry;
@@ -1626,7 +1627,7 @@ convertToJsonb(JsonbValue *val)
16261627
* for debugging purposes.
16271628
*/
16281629
static void
1629-
convertJsonbValue(StringInfo buffer, JEntry *header, JsonbValue *val, int level)
1630+
convertJsonbValue(StringInfo buffer, JEntry *header, const JsonbValue *val, int level)
16301631
{
16311632
check_stack_depth();
16321633

@@ -1651,7 +1652,7 @@ convertJsonbValue(StringInfo buffer, JEntry *header, JsonbValue *val, int level)
16511652
}
16521653

16531654
static void
1654-
convertJsonbArray(StringInfo buffer, JEntry *pheader, JsonbValue *val, int level)
1655+
convertJsonbArray(StringInfo buffer, JEntry *pheader, const JsonbValue *val, int level)
16551656
{
16561657
int base_offset;
16571658
int jentry_offset;
@@ -1735,7 +1736,7 @@ convertJsonbArray(StringInfo buffer, JEntry *pheader, JsonbValue *val, int level
17351736
}
17361737

17371738
static void
1738-
convertJsonbObject(StringInfo buffer, JEntry *pheader, JsonbValue *val, int level)
1739+
convertJsonbObject(StringInfo buffer, JEntry *pheader, const JsonbValue *val, int level)
17391740
{
17401741
int base_offset;
17411742
int jentry_offset;
@@ -1851,7 +1852,7 @@ convertJsonbObject(StringInfo buffer, JEntry *pheader, JsonbValue *val, int leve
18511852
}
18521853

18531854
static void
1854-
convertJsonbScalar(StringInfo buffer, JEntry *jentry, JsonbValue *scalarVal)
1855+
convertJsonbScalar(StringInfo buffer, JEntry *jentry, const JsonbValue *scalarVal)
18551856
{
18561857
int numlen;
18571858
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