Skip to content

Commit 9c5809a

Browse files
author
Nikita Glukhov
committed
Add JsonFreeIfCopy()
1 parent a6d81b8 commit 9c5809a

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/include/utils/json_generic.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,16 @@ typedef struct Json
156156
#undef PG_GETARG_JSONB
157157
#define PG_GETARG_JSONB(n) PG_GETARG_JSONX_TMP(n, alloca(sizeof(Json))) /* FIXME conditional alloca() */
158158

159-
#define PG_FREE_IF_COPY_JSONB(json, n) \
160-
do { \
161-
if (!VARATT_IS_EXTERNAL_EXPANDED(PG_GETARG_POINTER(n))) \
162-
JsonFree(json); \
163-
else \
164-
Assert(DatumGetEOHP(PG_GETARG_DATUM(n)) == &(json)->obj.eoh); \
165-
} while (0)
159+
#define JsonFreeIfCopy(json, datum) \
160+
do { \
161+
if (!VARATT_IS_EXTERNAL_EXPANDED(DatumGetPointer(datum))) \
162+
JsonFree(json); \
163+
else \
164+
Assert(DatumGetEOHP(datum) == &(json)->obj.eoh); \
165+
} while (0)
166166

167+
#define PG_FREE_IF_COPY_JSONB(json, n) \
168+
JsonFreeIfCopy(json, PG_GETARG_DATUM(n))
167169

168170
#define JsonRoot(json) (&(json)->root)
169171
#define JsonGetSize(json) (JsonRoot(json)->len)

0 commit comments

Comments
 (0)