Skip to content

Commit 7b9c90f

Browse files
author
Nikita Glukhov
committed
Add JsonContainerAlloc() macro
1 parent 63efa8e commit 7b9c90f

File tree

4 files changed

+6
-4
lines changed

4 files changed

+6
-4
lines changed

src/backend/utils/adt/json_generic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ JsonValueToContainer(const JsonValue *val)
173173
return val->val.binary.data;
174174
else
175175
{
176-
JsonContainerData *jc = palloc(sizeof(JsonContainerData));
176+
JsonContainerData *jc = JsonContainerAlloc();
177177
jsonvInitContainer(jc, val);
178178
return jc;
179179
}

src/backend/utils/adt/jsonb_util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ fillJsonbValue(const JsonbContainer *container, int index,
642642
{
643643
Assert(JBE_ISCONTAINER(entry));
644644
result->type = jbvBinary;
645-
result->val.binary.data = palloc(sizeof(JsonContainerData));
645+
result->val.binary.data = JsonContainerAlloc();
646646
jsonbInitContainer((JsonContainerData *) result->val.binary.data,
647647
/* Remove alignment padding from data pointer and length */
648648
(JsonbContainer *)(base_addr + INTALIGN(offset)),

src/common/jsonapi.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,8 +1334,7 @@ jsontFillValue(JsonIterator **pit, JsonValue *res, bool skipNested,
13341334

13351335
res->type = jbvBinary;
13361336
res->val.binary.len = 0;
1337-
res->val.binary.data = (JsonContainer *)
1338-
palloc(sizeof(JsonContainer));
1337+
res->val.binary.data = JsonContainerAlloc();
13391338

13401339
if (skipNested)
13411340
{

src/include/utils/json_generic.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ JsonIteratorNext(JsonIterator **it, JsonValue *val, bool skipNested)
249249

250250
extern Json *DatumGetJson(Datum value, JsonContainerOps *ops);
251251

252+
#define JsonContainerAlloc() \
253+
((JsonContainerData *) palloc(sizeof(JsonContainerData)))
254+
252255
extern JsonValue *JsonFindValueInContainer(JsonContainer *json, uint32 flags,
253256
JsonValue *key);
254257

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