Skip to content

Commit 702b47d

Browse files
author
Nikita Glukhov
committed
Add JsonFreeIfCopy()
1 parent 93bb2dc commit 702b47d

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/include/utils/json_generic.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,18 +163,20 @@ JsontPGetDatum(Json *json)
163163
#define PG_GETARG_JSONB_P(n) PG_GETARG_JSONX_TMP(n, alloca(sizeof(Json))) /* FIXME conditional alloca() */
164164
#define PG_GETARG_JSONT_P(n) DatumGetJsontP(PG_GETARG_DATUM(n))
165165

166-
#define PG_FREE_IF_COPY_JSONB(json, n) \
167-
do { \
168-
if (!VARATT_IS_EXTERNAL_EXPANDED(PG_GETARG_POINTER(n))) \
169-
JsonFree(json); \
170-
else \
171-
Assert(DatumGetEOHP(PG_GETARG_DATUM(n)) == &(json)->obj.eoh); \
172-
} while (0)
173-
174166
#undef PG_GETARG_JSONB_P_COPY
175167
#define PG_GETARG_JSONB_P_COPY(x) DatumGetJsonxPCopy(PG_GETARG_DATUM(x))
176168
#define PG_GETARG_JSONT_P_COPY(x) DatumGetJsontPCopy(PG_GETARG_DATUM(x))
177169

170+
#define JsonFreeIfCopy(json, datum) \
171+
do { \
172+
if (!VARATT_IS_EXTERNAL_EXPANDED(DatumGetPointer(datum))) \
173+
JsonFree(json); \
174+
else \
175+
Assert(DatumGetEOHP(datum) == &(json)->obj.eoh); \
176+
} while (0)
177+
178+
#define PG_FREE_IF_COPY_JSONB(json, n) \
179+
JsonFreeIfCopy(json, PG_GETARG_DATUM(n))
178180

179181
#define JsonRoot(json) (&(json)->root)
180182
#define JsonGetSize(json) (JsonRoot(json)->len)

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