@@ -570,7 +570,7 @@ jsonb_object_keys(PG_FUNCTION_ARGS)
570
570
state -> sent_count = 0 ;
571
571
state -> result = palloc (state -> result_size * sizeof (char * ));
572
572
573
- it = JsonbIteratorInit (& jb -> root );
573
+ it = JsonbIteratorInit (JsonbRoot ( jb ) );
574
574
575
575
while ((r = JsonbIteratorNext (& it ,& v ,skipNested ))!= WJB_DONE )
576
576
{
@@ -824,7 +824,7 @@ jsonb_object_field(PG_FUNCTION_ARGS)
824
824
if (!JB_ROOT_IS_OBJECT (jb ))
825
825
PG_RETURN_NULL ();
826
826
827
- v = getKeyJsonValueFromContainer (& jb -> root ,
827
+ v = getKeyJsonValueFromContainer (JsonbRoot ( jb ) ,
828
828
VARDATA_ANY (key ),
829
829
VARSIZE_ANY_EXHDR (key ),
830
830
& vbuf );
@@ -862,7 +862,7 @@ jsonb_object_field_text(PG_FUNCTION_ARGS)
862
862
if (!JB_ROOT_IS_OBJECT (jb ))
863
863
PG_RETURN_NULL ();
864
864
865
- v = getKeyJsonValueFromContainer (& jb -> root ,
865
+ v = getKeyJsonValueFromContainer (JsonbRoot ( jb ) ,
866
866
VARDATA_ANY (key ),
867
867
VARSIZE_ANY_EXHDR (key ),
868
868
& vbuf );
@@ -909,7 +909,7 @@ jsonb_array_element(PG_FUNCTION_ARGS)
909
909
element += nelements ;
910
910
}
911
911
912
- v = getIthJsonbValueFromContainer (& jb -> root ,element );
912
+ v = getIthJsonbValueFromContainer (JsonbRoot ( jb ) ,element );
913
913
if (v != NULL )
914
914
PG_RETURN_JSONB_P (JsonbValueToJsonb (v ));
915
915
@@ -952,7 +952,7 @@ jsonb_array_element_text(PG_FUNCTION_ARGS)
952
952
element += nelements ;
953
953
}
954
954
955
- v = getIthJsonbValueFromContainer (& jb -> root ,element );
955
+ v = getIthJsonbValueFromContainer (JsonbRoot ( jb ) ,element );
956
956
957
957
if (v != NULL && v -> type != jbvNull )
958
958
PG_RETURN_TEXT_P (JsonbValueAsText (v ));
@@ -1468,7 +1468,7 @@ get_jsonb_path_all(FunctionCallInfo fcinfo, bool as_text)
1468
1468
Datum
1469
1469
jsonb_get_element (Jsonb * jb ,Datum * path ,int npath ,bool * isnull ,bool as_text )
1470
1470
{
1471
- JsonbContainer * container = & jb -> root ;
1471
+ JsonbContainer * container = JsonbRoot ( jb ) ;
1472
1472
JsonbValue * jbvp = NULL ;
1473
1473
int i ;
1474
1474
bool have_object = false,
@@ -1503,7 +1503,7 @@ jsonb_get_element(Jsonb *jb, Datum *path, int npath, bool *isnull, bool as_text)
1503
1503
{
1504
1504
return PointerGetDatum (cstring_to_text (JsonbToCString (NULL ,
1505
1505
container ,
1506
- VARSIZE (jb ))));
1506
+ JsonbGetSize (jb ))));
1507
1507
}
1508
1508
else
1509
1509
{
@@ -1623,7 +1623,7 @@ jsonb_set_element(Jsonb *jb, Datum *path, int path_len,
1623
1623
if (newval -> type == jbvArray && newval -> val .array .rawScalar )
1624
1624
* newval = newval -> val .array .elems [0 ];
1625
1625
1626
- it = JsonbIteratorInit (& jb -> root );
1626
+ it = JsonbIteratorInit (JsonbRoot ( jb ) );
1627
1627
1628
1628
res = setPath (& it ,path ,path_nulls ,path_len ,& state ,0 ,newval ,
1629
1629
JB_PATH_CREATE |JB_PATH_FILL_GAPS |
@@ -1955,7 +1955,7 @@ each_worker_jsonb(FunctionCallInfo fcinfo, const char *funcname, bool as_text)
1955
1955
"jsonb_each temporary cxt" ,
1956
1956
ALLOCSET_DEFAULT_SIZES );
1957
1957
1958
- it = JsonbIteratorInit (& jb -> root );
1958
+ it = JsonbIteratorInit (JsonbRoot ( jb ) );
1959
1959
1960
1960
while ((r = JsonbIteratorNext (& it ,& v ,skipNested ))!= WJB_DONE )
1961
1961
{
@@ -2252,7 +2252,7 @@ elements_worker_jsonb(FunctionCallInfo fcinfo, const char *funcname,
2252
2252
"jsonb_array_elements temporary cxt" ,
2253
2253
ALLOCSET_DEFAULT_SIZES );
2254
2254
2255
- it = JsonbIteratorInit (& jb -> root );
2255
+ it = JsonbIteratorInit (JsonbRoot ( jb ) );
2256
2256
2257
2257
while ((r = JsonbIteratorNext (& it ,& v ,skipNested ))!= WJB_DONE )
2258
2258
{
@@ -3041,7 +3041,7 @@ populate_scalar(ScalarIOData *io, Oid typid, int32 typmod, JsValue *jsv)
3041
3041
*/
3042
3042
Jsonb * jsonb = JsonbValueToJsonb (jbv );
3043
3043
3044
- str = JsonbToCString (NULL ,& jsonb -> root , VARSIZE (jsonb ));
3044
+ str = JsonbToCString (NULL ,JsonbRoot ( jsonb ), JsonbGetSize (jsonb ));
3045
3045
}
3046
3046
else if (jbv -> type == jbvString )/* quotes are stripped */
3047
3047
str = pnstrdup (jbv -> val .string .val ,jbv -> val .string .len );
@@ -3555,7 +3555,7 @@ populate_record_worker(FunctionCallInfo fcinfo, const char *funcname,
3555
3555
3556
3556
/* fill binary jsonb value pointing to jb */
3557
3557
jbv .type = jbvBinary ;
3558
- jbv .val .binary .data = & jb -> root ;
3558
+ jbv .val .binary .data = JsonbRoot ( jb ) ;
3559
3559
jbv .val .binary .len = VARSIZE (jb )- VARHDRSZ ;
3560
3560
}
3561
3561
@@ -3915,7 +3915,7 @@ populate_recordset_worker(FunctionCallInfo fcinfo, const char *funcname,
3915
3915
errmsg ("cannot call %s on a non-array" ,
3916
3916
funcname )));
3917
3917
3918
- it = JsonbIteratorInit (& jb -> root );
3918
+ it = JsonbIteratorInit (JsonbRoot ( jb ) );
3919
3919
3920
3920
while ((r = JsonbIteratorNext (& it ,& v ,skipNested ))!= WJB_DONE )
3921
3921
{
@@ -4253,7 +4253,7 @@ jsonb_strip_nulls(PG_FUNCTION_ARGS)
4253
4253
if (JB_ROOT_IS_SCALAR (jb ))
4254
4254
PG_RETURN_JSONB_P (jb );
4255
4255
4256
- it = JsonbIteratorInit (& jb -> root );
4256
+ it = JsonbIteratorInit (JsonbRoot ( jb ) );
4257
4257
4258
4258
while ((type = JsonbIteratorNext (& it ,& v , false))!= WJB_DONE )
4259
4259
{
@@ -4302,7 +4302,7 @@ jsonb_pretty(PG_FUNCTION_ARGS)
4302
4302
Jsonb * jb = PG_GETARG_JSONB_P (0 );
4303
4303
StringInfo str = makeStringInfo ();
4304
4304
4305
- JsonbToCStringIndent (str ,& jb -> root , VARSIZE (jb ));
4305
+ JsonbToCStringIndent (str ,JsonbRoot ( jb ), JsonbGetSize (jb ));
4306
4306
4307
4307
PG_RETURN_TEXT_P (cstring_to_text_with_len (str -> data ,str -> len ));
4308
4308
}
@@ -4313,7 +4313,7 @@ jsonb_canonical(PG_FUNCTION_ARGS)
4313
4313
Jsonb * jb = PG_GETARG_JSONB_P (0 );
4314
4314
StringInfo str = makeStringInfo ();
4315
4315
4316
- JsonbToCStringCanonical (str ,& jb -> root , VARSIZE (jb ));
4316
+ JsonbToCStringCanonical (str ,JsonbRoot ( jb ), JsonbGetSize (jb ));
4317
4317
4318
4318
PG_RETURN_TEXT_P (cstring_to_text_with_len (str -> data ,str -> len ));
4319
4319
}
@@ -4347,8 +4347,8 @@ jsonb_concat(PG_FUNCTION_ARGS)
4347
4347
PG_RETURN_JSONB_P (jb1 );
4348
4348
}
4349
4349
4350
- it1 = JsonbIteratorInit (& jb1 -> root );
4351
- it2 = JsonbIteratorInit (& jb2 -> root );
4350
+ it1 = JsonbIteratorInit (JsonbRoot ( jb1 ) );
4351
+ it2 = JsonbIteratorInit (JsonbRoot ( jb2 ) );
4352
4352
4353
4353
res = IteratorConcat (& it1 ,& it2 ,& state );
4354
4354
@@ -4386,7 +4386,7 @@ jsonb_delete(PG_FUNCTION_ARGS)
4386
4386
if (JB_ROOT_COUNT (in )== 0 )
4387
4387
PG_RETURN_JSONB_P (in );
4388
4388
4389
- it = JsonbIteratorInit (& in -> root );
4389
+ it = JsonbIteratorInit (JsonbRoot ( in ) );
4390
4390
4391
4391
while ((r = JsonbIteratorNext (& it ,& v ,skipNested ))!= WJB_DONE )
4392
4392
{
@@ -4451,7 +4451,7 @@ jsonb_delete_array(PG_FUNCTION_ARGS)
4451
4451
if (keys_len == 0 )
4452
4452
PG_RETURN_JSONB_P (in );
4453
4453
4454
- it = JsonbIteratorInit (& in -> root );
4454
+ it = JsonbIteratorInit (JsonbRoot ( in ) );
4455
4455
4456
4456
while ((r = JsonbIteratorNext (& it ,& v ,skipNested ))!= WJB_DONE )
4457
4457
{
@@ -4530,7 +4530,7 @@ jsonb_delete_idx(PG_FUNCTION_ARGS)
4530
4530
if (JB_ROOT_COUNT (in )== 0 )
4531
4531
PG_RETURN_JSONB_P (in );
4532
4532
4533
- it = JsonbIteratorInit (& in -> root );
4533
+ it = JsonbIteratorInit (JsonbRoot ( in ) );
4534
4534
4535
4535
r = JsonbIteratorNext (& it ,& v , false);
4536
4536
Assert (r == WJB_BEGIN_ARRAY );
@@ -4604,7 +4604,7 @@ jsonb_set(PG_FUNCTION_ARGS)
4604
4604
if (path_len == 0 )
4605
4605
PG_RETURN_JSONB_P (in );
4606
4606
4607
- it = JsonbIteratorInit (& in -> root );
4607
+ it = JsonbIteratorInit (JsonbRoot ( in ) );
4608
4608
4609
4609
res = setPath (& it ,path_elems ,path_nulls ,path_len ,& st ,
4610
4610
0 ,& newval ,create ?JB_PATH_CREATE :JB_PATH_REPLACE );
@@ -4716,7 +4716,7 @@ jsonb_delete_path(PG_FUNCTION_ARGS)
4716
4716
if (path_len == 0 )
4717
4717
PG_RETURN_JSONB_P (in );
4718
4718
4719
- it = JsonbIteratorInit (& in -> root );
4719
+ it = JsonbIteratorInit (JsonbRoot ( in ) );
4720
4720
4721
4721
res = setPath (& it ,path_elems ,path_nulls ,path_len ,& st ,
4722
4722
0 ,NULL ,JB_PATH_DELETE );
@@ -4762,7 +4762,7 @@ jsonb_insert(PG_FUNCTION_ARGS)
4762
4762
if (path_len == 0 )
4763
4763
PG_RETURN_JSONB_P (in );
4764
4764
4765
- it = JsonbIteratorInit (& in -> root );
4765
+ it = JsonbIteratorInit (JsonbRoot ( in ) );
4766
4766
4767
4767
res = setPath (& it ,path_elems ,path_nulls ,path_len ,& st ,0 ,& newval ,
4768
4768
after ?JB_PATH_INSERT_AFTER :JB_PATH_INSERT_BEFORE );
@@ -5249,7 +5249,7 @@ parse_jsonb_index_flags(Jsonb *jb)
5249
5249
JsonbIteratorToken type ;
5250
5250
uint32 flags = 0 ;
5251
5251
5252
- it = JsonbIteratorInit (& jb -> root );
5252
+ it = JsonbIteratorInit (JsonbRoot ( jb ) );
5253
5253
5254
5254
type = JsonbIteratorNext (& it ,& v , false);
5255
5255
@@ -5317,7 +5317,7 @@ iterate_jsonb_values(Jsonb *jb, uint32 flags, void *state,
5317
5317
JsonbValue v ;
5318
5318
JsonbIteratorToken type ;
5319
5319
5320
- it = JsonbIteratorInit (& jb -> root );
5320
+ it = JsonbIteratorInit (JsonbRoot ( jb ) );
5321
5321
5322
5322
/*
5323
5323
* Just recursively iterating over jsonb and call callback on all
@@ -5457,7 +5457,7 @@ transform_jsonb_string_values(Jsonb *jsonb, void *action_state,
5457
5457
JsonbParseState * st = NULL ;
5458
5458
text * out ;
5459
5459
5460
- it = JsonbIteratorInit (& jsonb -> root );
5460
+ it = JsonbIteratorInit (JsonbRoot ( jsonb ) );
5461
5461
5462
5462
while ((type = JsonbIteratorNext (& it ,& v , false))!= WJB_DONE )
5463
5463
{