7
7
* Portions Copyright (c) 1994, Regents of the University of California
8
8
*
9
9
* IDENTIFICATION
10
- * src/backend/utils/adt /jsonapi.c
10
+ * src/common /jsonapi.c
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
14
+ #ifndef FRONTEND
14
15
#include "postgres.h"
16
+ #else
17
+ #include "postgres_fe.h"
18
+ #endif
15
19
20
+ #include "common/jsonapi.h"
16
21
#include "mb/pg_wchar.h"
22
+
23
+ #ifdef FRONTEND
24
+ #include "common/logging.h"
25
+ #else
17
26
#include "miscadmin.h"
18
- #include "utils/jsonapi.h"
27
+ #endif
28
+
29
+ #ifdef FRONTEND
30
+ #define check_stack_depth ()
31
+ #define json_log_and_abort (...) \
32
+ do { pg_log_fatal(__VA_ARGS__); exit(1); } while(0)
33
+ #else
34
+ #define json_log_and_abort (...) elog(ERROR, __VA_ARGS__)
35
+ #endif
19
36
20
37
/*
21
38
* The context of the parser is maintained by the recursive descent
@@ -135,13 +152,14 @@ IsValidJsonNumber(const char *str, int len)
135
152
* if really required.
136
153
*/
137
154
JsonLexContext *
138
- makeJsonLexContextCstringLen (char * json , int len , bool need_escapes )
155
+ makeJsonLexContextCstringLen (char * json , int len , int encoding , bool need_escapes )
139
156
{
140
157
JsonLexContext * lex = palloc0 (sizeof (JsonLexContext ));
141
158
142
159
lex -> input = lex -> token_terminator = lex -> line_start = json ;
143
160
lex -> line_number = 1 ;
144
161
lex -> input_length = len ;
162
+ lex -> input_encoding = encoding ;
145
163
if (need_escapes )
146
164
lex -> strval = makeStringInfo ();
147
165
return lex ;
@@ -720,7 +738,7 @@ json_lex_string(JsonLexContext *lex)
720
738
ch = (ch * 16 ) + (* s - 'A' ) + 10 ;
721
739
else
722
740
{
723
- lex -> token_terminator = s + pg_mblen ( s );
741
+ lex -> token_terminator = s + pg_encoding_mblen ( lex -> input_encoding , s );
724
742
return JSON_UNICODE_ESCAPE_FORMAT ;
725
743
}
726
744
}
@@ -759,7 +777,7 @@ json_lex_string(JsonLexContext *lex)
759
777
/* We can't allow this, since our TEXT type doesn't */
760
778
return JSON_UNICODE_CODE_POINT_ZERO ;
761
779
}
762
- else if (GetDatabaseEncoding () == PG_UTF8 )
780
+ else if (lex -> input_encoding == PG_UTF8 )
763
781
{
764
782
unicode_to_utf8 (ch , (unsigned char * ) utf8str );
765
783
utf8len = pg_utf_mblen ((unsigned char * ) utf8str );
@@ -809,7 +827,7 @@ json_lex_string(JsonLexContext *lex)
809
827
default :
810
828
/* Not a valid string escape, so signal error. */
811
829
lex -> token_start = s ;
812
- lex -> token_terminator = s + pg_mblen ( s );
830
+ lex -> token_terminator = s + pg_encoding_mblen ( lex -> input_encoding , s );
813
831
return JSON_ESCAPING_INVALID ;
814
832
}
815
833
}
@@ -823,7 +841,7 @@ json_lex_string(JsonLexContext *lex)
823
841
* shown it's not a performance win.
824
842
*/
825
843
lex -> token_start = s ;
826
- lex -> token_terminator = s + pg_mblen ( s );
844
+ lex -> token_terminator = s + pg_encoding_mblen ( lex -> input_encoding , s );
827
845
return JSON_ESCAPING_INVALID ;
828
846
}
829
847
@@ -1010,7 +1028,7 @@ report_parse_error(JsonParseContext ctx, JsonLexContext *lex)
1010
1028
* unhandled enum values. But this needs to be here anyway to cover the
1011
1029
* possibility of an incorrect input.
1012
1030
*/
1013
- elog ( ERROR , "unexpected json parse state: %d" , (int ) ctx );
1031
+ json_log_and_abort ( "unexpected json parse state: %d" , (int ) ctx );
1014
1032
return JSON_SUCCESS ; /* silence stupider compilers */
1015
1033
}
1016
1034
@@ -1077,7 +1095,7 @@ json_errdetail(JsonParseErrorType error, JsonLexContext *lex)
1077
1095
* unhandled enum values. But this needs to be here anyway to cover the
1078
1096
* possibility of an incorrect input.
1079
1097
*/
1080
- elog ( ERROR , "unexpected json parse error type: %d" , (int ) error );
1098
+ json_log_and_abort ( "unexpected json parse error type: %d" , (int ) error );
1081
1099
return NULL ; /* silence stupider compilers */
1082
1100
}
1083
1101
0 commit comments