index 10ec392775ecfda3a876cbd63f446ef32755eb7d..f3174f2995110fabb38acfedf41b93e4b0d009e0 100644 (file)
#include "access/htup_details.h"
#include "catalog/pg_type.h"
+#include "common/jsonapi.h"
#include "funcapi.h"
#include "hstore.h"
#include "lib/stringinfo.h"
#include "libpq/pqformat.h"
#include "utils/builtins.h"
#include "utils/json.h"
-#include "utils/jsonapi.h"
#include "utils/jsonb.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
index adf181c191f3d98c1c3ad78f9cf27b8ecd3d2744..1fe67c4c9987d1e2eee148f6378aade53ad09593 100644 (file)
*/
#include "postgres.h"
+#include "common/jsonapi.h"
#include "tsearch/ts_cache.h"
#include "tsearch/ts_utils.h"
#include "utils/builtins.h"
-#include "utils/jsonapi.h"
#include "utils/jsonfuncs.h"
index c7499a94ac61934d6788bd1a8cc64543429a1531..88005c0519a0bd15a9780d6b1ca6e7fdf26ea9d6 100644 (file)
#include "catalog/namespace.h"
#include "catalog/pg_type.h"
#include "commands/defrem.h"
+#include "common/jsonapi.h"
#include "funcapi.h"
#include "tsearch/ts_cache.h"
#include "tsearch/ts_utils.h"
#include "utils/builtins.h"
-#include "utils/jsonapi.h"
#include "utils/jsonfuncs.h"
#include "utils/varlena.h"
index 790d7a24fb84568040b3ab8bfb41dccb8d36b89b..13efa9338c165f32e90621d2636c04388df01fc3 100644 (file)
int.o \
int8.o \
json.o \
- jsonapi.o \
jsonb.o \
jsonb_gin.o \
jsonb_op.o \
index f6cd2b991159e797cf971ea0f2803c633fc88a2f..567eab1e01e235e26ccbf7d896303b8d4d8478ce 100644 (file)
str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes);
/* Validate it. */
- lex = makeJsonLexContextCstringLen(str, nbytes, false);
+ lex = makeJsonLexContextCstringLen(str, nbytes, GetDatabaseEncoding(), false);
pg_parse_json_or_ereport(lex, &nullSemAction);
PG_RETURN_TEXT_P(cstring_to_text_with_len(str, nbytes));
index c912f8932df6bc4c34bc942f398ac6012a12699a..fea4335951519a5975417687eaa05154cfe22d5e 100644 (file)
memset(&state, 0, sizeof(state));
memset(&sem, 0, sizeof(sem));
- lex = makeJsonLexContextCstringLen(json, len, true);
+ lex = makeJsonLexContextCstringLen(json, len, GetDatabaseEncoding(), true);
sem.semstate = (void *) &state;
index b33c3ef43ce163b3d171088b251282f8582530fd..edec657cd3ceaadfc3e26e3dd6d4a1057f9cf4bd 100644 (file)
#include "catalog/pg_collation.h"
#include "catalog/pg_type.h"
+#include "common/jsonapi.h"
#include "miscadmin.h"
#include "utils/builtins.h"
#include "utils/datetime.h"
#include "utils/hashutils.h"
#include "utils/json.h"
-#include "utils/jsonapi.h"
#include "utils/jsonb.h"
#include "utils/memutils.h"
#include "utils/varlena.h"
index 66ea11b971ca01c47fee50daf219413a18163a00..4f6fd0de023c94cb27e0b0a49d4e15f12d1507bd 100644 (file)
#include "access/htup_details.h"
#include "catalog/pg_type.h"
+#include "common/jsonapi.h"
#include "fmgr.h"
#include "funcapi.h"
#include "lib/stringinfo.h"
#include "utils/builtins.h"
#include "utils/hsearch.h"
#include "utils/json.h"
-#include "utils/jsonapi.h"
#include "utils/jsonb.h"
#include "utils/jsonfuncs.h"
#include "utils/lsyscache.h"
@@ -514,6 +514,7 @@ makeJsonLexContext(text *json, bool need_escapes)
{
return makeJsonLexContextCstringLen(VARDATA_ANY(json),
VARSIZE_ANY_EXHDR(json),
+ GetDatabaseEncoding(),
need_escapes);
}
@@ -2605,7 +2606,7 @@ populate_array_json(PopulateArrayContext *ctx, char *json, int len)
PopulateArrayState state;
JsonSemAction sem;
- state.lex = makeJsonLexContextCstringLen(json, len, true);
+ state.lex = makeJsonLexContextCstringLen(json, len, GetDatabaseEncoding(), true);
state.ctx = ctx;
memset(&sem, 0, sizeof(sem));
@@ -3448,7 +3449,7 @@ get_json_object_as_hash(char *json, int len, const char *funcname)
HASHCTL ctl;
HTAB *tab;
JHashState *state;
- JsonLexContext *lex = makeJsonLexContextCstringLen(json, len, true);
+ JsonLexContext *lex = makeJsonLexContextCstringLen(json, len, GetDatabaseEncoding(), true);
JsonSemAction *sem;
memset(&ctl, 0, sizeof(ctl));
index 44ca68fa6c377138a37eeb9ccfa621ca15f077be..e757fb73996da1332dd2d54ffbf73a28c1cc3780 100644 (file)
f2s.o \
file_perm.o \
ip.o \
+ jsonapi.o \
keywords.o \
kwlookup.o \
link-canary.o \
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * src/backend/utils/adt/jsonapi.c
+ * src/common/jsonapi.c
*
*-------------------------------------------------------------------------
*/
+#ifndef FRONTEND
#include "postgres.h"
+#else
+#include "postgres_fe.h"
+#endif
+#include "common/jsonapi.h"
#include "mb/pg_wchar.h"
+
+#ifdef FRONTEND
+#include "common/logging.h"
+#else
#include "miscadmin.h"
-#include "utils/jsonapi.h"
+#endif
+
+#ifdef FRONTEND
+#define check_stack_depth()
+#define json_log_and_abort(...) \
+ do { pg_log_fatal(__VA_ARGS__); exit(1); } while(0)
+#else
+#define json_log_and_abort(...) elog(ERROR, __VA_ARGS__)
+#endif
/*
* The context of the parser is maintained by the recursive descent
* if really required.
*/
JsonLexContext *
-makeJsonLexContextCstringLen(char *json, int len, bool need_escapes)
+makeJsonLexContextCstringLen(char *json, int len, int encoding, bool need_escapes)
{
JsonLexContext *lex = palloc0(sizeof(JsonLexContext));
lex->input = lex->token_terminator = lex->line_start = json;
lex->line_number = 1;
lex->input_length = len;
+ lex->input_encoding = encoding;
if (need_escapes)
lex->strval = makeStringInfo();
return lex;
ch = (ch * 16) + (*s - 'A') + 10;
else
{
- lex->token_terminator = s + pg_mblen(s);
+ lex->token_terminator = s + pg_encoding_mblen(lex->input_encoding, s);
return JSON_UNICODE_ESCAPE_FORMAT;
}
}
/* We can't allow this, since our TEXT type doesn't */
return JSON_UNICODE_CODE_POINT_ZERO;
}
- else if (GetDatabaseEncoding() == PG_UTF8)
+ else if (lex->input_encoding == PG_UTF8)
{
unicode_to_utf8(ch, (unsigned char *) utf8str);
utf8len = pg_utf_mblen((unsigned char *) utf8str);
default:
/* Not a valid string escape, so signal error. */
lex->token_start = s;
- lex->token_terminator = s + pg_mblen(s);
+ lex->token_terminator = s + pg_encoding_mblen(lex->input_encoding, s);
return JSON_ESCAPING_INVALID;
}
}
* shown it's not a performance win.
*/
lex->token_start = s;
- lex->token_terminator = s + pg_mblen(s);
+ lex->token_terminator = s + pg_encoding_mblen(lex->input_encoding, s);
return JSON_ESCAPING_INVALID;
}
@@ -1010,7 +1028,7 @@ report_parse_error(JsonParseContext ctx, JsonLexContext *lex)
* unhandled enum values. But this needs to be here anyway to cover the
* possibility of an incorrect input.
*/
- elog(ERROR, "unexpected json parse state: %d", (int) ctx);
+ json_log_and_abort("unexpected json parse state: %d", (int) ctx);
return JSON_SUCCESS; /* silence stupider compilers */
}
@@ -1077,7 +1095,7 @@ json_errdetail(JsonParseErrorType error, JsonLexContext *lex)
* unhandled enum values. But this needs to be here anyway to cover the
* possibility of an incorrect input.
*/
- elog(ERROR, "unexpected json parse error type: %d", (int) error);
+ json_log_and_abort("unexpected json parse error type: %d", (int) error);
return NULL; /* silence stupider compilers */
}
{
char *input;
int input_length;
+ int input_encoding;
char *token_start;
char *token_terminator;
char *prev_token_terminator;
@@ -149,6 +150,7 @@ extern JsonParseErrorType json_count_array_elements(JsonLexContext *lex,
*/
extern JsonLexContext *makeJsonLexContextCstringLen(char *json,
int len,
+ int encoding,
bool need_escapes);
/* lex one token */
index b993f38409f4859e48bf6d60065c236207310fc7..1f1b4029cbf121cbe4eedc74c887b3339cbeb3d2 100644 (file)
#ifndef JSONFUNCS_H
#define JSONFUNCS_H
-#include "utils/jsonapi.h"
+#include "common/jsonapi.h"
#include "utils/jsonb.h"
/*