Skip to content

Commit c1b6a48

Browse files
author
Nikita Glukhov
committed
Extract JsonValueFromCString()
1 parent 5c4d00b commit c1b6a48

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/backend/utils/adt/jsonb.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -221,15 +221,8 @@ jsonb_typeof(PG_FUNCTION_ARGS)
221221
PG_RETURN_TEXT_P(cstring_to_text(result));
222222
}
223223

224-
/*
225-
* jsonb_from_cstring
226-
*
227-
* Turns json string into a jsonb Datum.
228-
*
229-
* Uses the json parser (with hooks) to construct a jsonb.
230-
*/
231-
static inline Datum
232-
jsonb_from_cstring(char *json, int len)
224+
static JsonbValue *
225+
JsonValueFromCString(char *json, int len)
233226
{
234227
JsonLexContext *lex;
235228
JsonbInState state;
@@ -251,9 +244,21 @@ jsonb_from_cstring(char *json, int len)
251244
pg_parse_json(lex, &sem);
252245

253246
/* after parsing, the item member has the composed jsonb structure */
254-
PG_RETURN_JSONB(JsonbValueToJsonb(state.res));
247+
return state.res;
255248
}
256249

250+
/*
251+
* jsonb_from_cstring
252+
*
253+
* Turns json string into a jsonb Datum.
254+
*
255+
* Uses the json parser (with hooks) to construct a jsonb.
256+
*/
257+
static inline Datum
258+
jsonb_from_cstring(char *json, int len)
259+
{
260+
PG_RETURN_JSONB(JsonbValueToJsonb(JsonValueFromCString(json, len)));
261+
}
257262

258263
static void
259264
jsonb_in_object_start(void *pstate)

0 commit comments

Comments
 (0)