Skip to content

Commit e70f462

Browse files
author
Nikita Glukhov
committed
Add buf parameter to JsonToCString()
1 parent c30f001 commit e70f462

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

src/backend/utils/adt/jsonb.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ jsonb_out(PG_FUNCTION_ARGS)
111111
Jsonb *jb = PG_GETARG_JSONB_P(0);
112112
char *out;
113113

114-
out = JsonToCString(JsonbRoot(jb));
114+
out = JsonToCString(JsonbRoot(jb), NULL);
115115

116116
PG_RETURN_CSTRING(out);
117117
}
@@ -129,7 +129,7 @@ jsonb_send(PG_FUNCTION_ARGS)
129129
StringInfo jtext = makeStringInfo();
130130
int version = 1;
131131

132-
(void) JsonbToCString(jtext, JsonbRoot(jb), JsonbGetSize(jb));
132+
(void) JsonToCString(JsonbRoot(jb), jtext);
133133

134134
pq_begintypsend(&buf);
135135
pq_sendint8(&buf, version);
@@ -522,8 +522,7 @@ JsonbToCStringWorker(StringInfo out, JsonbContainer *in, int estimated_len, bool
522522
{
523523
first = false;
524524
if (v.type == jbvBinary)
525-
JsonbToCString(out, v.val.binary.data,
526-
v.val.binary.data->len);
525+
JsonToCString(v.val.binary.data, out);
527526
else
528527
jsonb_put_escaped_value(out, &v);
529528
}
@@ -548,8 +547,7 @@ JsonbToCStringWorker(StringInfo out, JsonbContainer *in, int estimated_len, bool
548547
add_indent(out, use_indent, level);
549548

550549
if (v.type == jbvBinary)
551-
JsonbToCString(out, v.val.binary.data,
552-
v.val.binary.data->len);
550+
JsonToCString(v.val.binary.data, out);
553551
else
554552
jsonb_put_escaped_value(out, &v);
555553
break;

src/backend/utils/adt/jsonfuncs.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,9 +1501,8 @@ jsonb_get_element(Jsonb *jb, Datum *path, int npath, bool *isnull, bool as_text)
15011501
{
15021502
if (as_text)
15031503
{
1504-
return PointerGetDatum(cstring_to_text(JsonbToCString(NULL,
1505-
container,
1506-
JsonbGetSize(jb))));
1504+
return PointerGetDatum(cstring_to_text(JsonToCStringExt(NULL, container,
1505+
JsonbGetSize(jb))));
15071506
}
15081507
else
15091508
{
@@ -1770,8 +1769,7 @@ JsonbValueAsText(JsonbValue *v)
17701769
StringInfoData jtext;
17711770

17721771
initStringInfo(&jtext);
1773-
(void) JsonbToCString(&jtext, v->val.binary.data,
1774-
v->val.binary.data->len);
1772+
(void) JsonToCString(v->val.binary.data, &jtext);
17751773

17761774
return cstring_to_text_with_len(jtext.data, jtext.len);
17771775
}
@@ -2921,7 +2919,7 @@ populate_scalar(ScalarIOData *io, Oid typid, int32 typmod, JsValue *jsv)
29212919
*/
29222920
Jsonb *jsonb = JsonbValueToJsonb(jbv);
29232921

2924-
str = JsonbToCString(NULL, &jsonb->root, -1);
2922+
str = JsonToCString(&jsonb->root, NULL);
29252923
}
29262924
else if (jbv->type == jbvString) /* quotes are stripped */
29272925
str = pnstrdup(jbv->val.string.val, jbv->val.string.len);
@@ -2931,8 +2929,7 @@ populate_scalar(ScalarIOData *io, Oid typid, int32 typmod, JsValue *jsv)
29312929
str = DatumGetCString(DirectFunctionCall1(numeric_out,
29322930
PointerGetDatum(jbv->val.numeric)));
29332931
else if (jbv->type == jbvBinary)
2934-
str = JsonbToCString(NULL, jbv->val.binary.data,
2935-
jbv->val.binary.data->len);
2932+
str = JsonToCString(jbv->val.binary.data, NULL);
29362933
else
29372934
elog(ERROR, "unrecognized jsonb type: %d", (int) jbv->type);
29382935
}

src/include/utils/json_generic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ extern char *JsonbToCStringRaw(StringInfo out, JsonContainer *in,
258258
extern char *JsonbToCStringIndent(StringInfo out, JsonContainer *in,
259259
int estimated_len);
260260

261-
#define JsonToCString(jc) JsonToCStringExt(NULL, jc, (jc)->len)
261+
#define JsonToCString(jc, buf) ((jc)->ops->toString(buf, jc, (jc)->len))
262262

263263
#define JsonToCStringExt(out, in, estimated_len) \
264264
((*(in)->ops->toString)(out, in, estimated_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