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

Commit e162076

Browse files
feodorNikita Glukhov
authored and
Nikita Glukhov
committed
add header for jsonpath type
1 parent 6cd3a61 commit e162076

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/backend/utils/adt/jsonpath.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ static int
2323
flattenJsonPathParseItem(StringInfo buf, JsonPathParseItem *item,
2424
bool forbiddenRoot)
2525
{
26-
int32 pos = buf->len - VARHDRSZ; /* position from begining of jsonpath data */
26+
/* position from begining of jsonpath data */
27+
int32 pos = buf->len - JSONPATH_HDRSZ;
2728
int32 chld, next;
2829

2930
check_stack_depth();
@@ -171,7 +172,7 @@ jsonpath_in(PG_FUNCTION_ARGS)
171172
initStringInfo(&buf);
172173
enlargeStringInfo(&buf, 4 * len /* estimation */);
173174

174-
appendStringInfoSpaces(&buf, VARHDRSZ);
175+
appendStringInfoSpaces(&buf, JSONPATH_HDRSZ);
175176

176177
if (!jsonpath)
177178
ereport(ERROR,
@@ -182,6 +183,7 @@ jsonpath_in(PG_FUNCTION_ARGS)
182183

183184
res = (JsonPath*)buf.data;
184185
SET_VARSIZE(res, buf.len);
186+
res->header = JSONPATH_VERSION;
185187

186188
PG_RETURN_JSONPATH_P(res);
187189
}
@@ -424,7 +426,8 @@ jsonpath_out(PG_FUNCTION_ARGS)
424426
void
425427
jspInit(JsonPathItem *v, JsonPath *js)
426428
{
427-
jspInitByBuffer(v, VARDATA(js), 0);
429+
Assert(js->header == JSONPATH_VERSION);
430+
jspInitByBuffer(v, js->data, 0);
428431
}
429432

430433
void

src/include/utils/jsonpath.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ typedef struct
2626
} JsonPath;
2727

2828
#define JSONPATH_VERSION (0x01)
29+
#define JSONPATH_HDRSZ (offsetof(JsonPath, data))
2930

3031
#define DatumGetJsonPathP(d) ((JsonPath *) DatumGetPointer(PG_DETOAST_DATUM(d)))
3132
#define DatumGetJsonPathPCopy(d) ((JsonPath *) DatumGetPointer(PG_DETOAST_DATUM_COPY(d)))

0 commit comments

Comments
 (0)