Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 850ec37

Browse files
author
Nikita Glukhov
committed
Add JsonFreeIfCopy()
1 parent 2849493 commit 850ec37

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/include/utils/json_generic.h

+10-8
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)