@@ -86,7 +86,7 @@ typedef struct GetState
86
86
{
87
87
JsonLexContext * lex ;
88
88
text * tresult ;
89
- char * result_start ;
89
+ const char * result_start ;
90
90
bool normalize_results ;
91
91
bool next_scalar ;
92
92
int npath ; /* length of each path-related array */
@@ -111,7 +111,7 @@ typedef struct EachState
111
111
Tuplestorestate * tuple_store ;
112
112
TupleDesc ret_tdesc ;
113
113
MemoryContext tmp_cxt ;
114
- char * result_start ;
114
+ const char * result_start ;
115
115
bool normalize_results ;
116
116
bool next_scalar ;
117
117
char * normalized_scalar ;
@@ -125,7 +125,7 @@ typedef struct ElementsState
125
125
Tuplestorestate * tuple_store ;
126
126
TupleDesc ret_tdesc ;
127
127
MemoryContext tmp_cxt ;
128
- char * result_start ;
128
+ const char * result_start ;
129
129
bool normalize_results ;
130
130
bool next_scalar ;
131
131
char * normalized_scalar ;
@@ -138,7 +138,7 @@ typedef struct JHashState
138
138
const char * function_name ;
139
139
HTAB * hash ;
140
140
char * saved_scalar ;
141
- char * save_json_start ;
141
+ const char * save_json_start ;
142
142
JsonTokenType saved_token_type ;
143
143
} JHashState ;
144
144
@@ -247,7 +247,7 @@ typedef struct PopulateRecordsetState
247
247
const char * function_name ;
248
248
HTAB * json_hash ;
249
249
char * saved_scalar ;
250
- char * save_json_start ;
250
+ const char * save_json_start ;
251
251
JsonTokenType saved_token_type ;
252
252
Tuplestorestate * tuple_store ;
253
253
HeapTupleHeader rec ;
@@ -273,7 +273,7 @@ typedef struct PopulateArrayState
273
273
{
274
274
JsonLexContext * lex ; /* json lexer */
275
275
PopulateArrayContext * ctx ; /* context */
276
- char * element_start ; /* start of the current array element */
276
+ const char * element_start ; /* start of the current array element */
277
277
char * element_scalar ; /* current array element token if it is a
278
278
* scalar */
279
279
JsonTokenType element_type ; /* current array element type */
@@ -295,7 +295,7 @@ typedef struct JsValue
295
295
{
296
296
struct
297
297
{
298
- char * str ; /* json string */
298
+ const char * str ; /* json string */
299
299
int len ; /* json string length or -1 if null-terminated */
300
300
JsonTokenType type ; /* json type */
301
301
} json ; /* json value */
@@ -390,7 +390,7 @@ static JsonParseErrorType elements_array_element_end(void *state, bool isnull);
390
390
static JsonParseErrorType elements_scalar (void * state , char * token , JsonTokenType tokentype );
391
391
392
392
/* turn a json object into a hash table */
393
- static HTAB * get_json_object_as_hash (char * json , int len , const char * funcname ,
393
+ static HTAB * get_json_object_as_hash (const char * json , int len , const char * funcname ,
394
394
Node * escontext );
395
395
396
396
/* semantic actions for populate_array_json */
@@ -456,7 +456,7 @@ static Datum populate_record_field(ColumnIOData *col, Oid typid, int32 typmod,
456
456
static RecordIOData * allocate_record_info (MemoryContext mcxt , int ncolumns );
457
457
static bool JsObjectGetField (JsObject * obj , char * field , JsValue * jsv );
458
458
static void populate_recordset_record (PopulateRecordsetState * state , JsObject * obj );
459
- static bool populate_array_json (PopulateArrayContext * ctx , char * json , int len );
459
+ static bool populate_array_json (PopulateArrayContext * ctx , const char * json , int len );
460
460
static bool populate_array_dim_jsonb (PopulateArrayContext * ctx , JsonbValue * jbv ,
461
461
int ndim );
462
462
static void populate_array_report_expected_array (PopulateArrayContext * ctx , int ndim );
@@ -1181,7 +1181,7 @@ get_object_end(void *state)
1181
1181
if (lex_level == 0 && _state -> npath == 0 )
1182
1182
{
1183
1183
/* Special case: return the entire object */
1184
- char * start = _state -> result_start ;
1184
+ const char * start = _state -> result_start ;
1185
1185
int len = _state -> lex -> prev_token_terminator - start ;
1186
1186
1187
1187
_state -> tresult = cstring_to_text_with_len (start , len );
@@ -1275,7 +1275,7 @@ get_object_field_end(void *state, char *fname, bool isnull)
1275
1275
_state -> tresult = (text * ) NULL ;
1276
1276
else
1277
1277
{
1278
- char * start = _state -> result_start ;
1278
+ const char * start = _state -> result_start ;
1279
1279
int len = _state -> lex -> prev_token_terminator - start ;
1280
1280
1281
1281
_state -> tresult = cstring_to_text_with_len (start , len );
@@ -1337,7 +1337,7 @@ get_array_end(void *state)
1337
1337
if (lex_level == 0 && _state -> npath == 0 )
1338
1338
{
1339
1339
/* Special case: return the entire array */
1340
- char * start = _state -> result_start ;
1340
+ const char * start = _state -> result_start ;
1341
1341
int len = _state -> lex -> prev_token_terminator - start ;
1342
1342
1343
1343
_state -> tresult = cstring_to_text_with_len (start , len );
@@ -1426,7 +1426,7 @@ get_array_element_end(void *state, bool isnull)
1426
1426
_state -> tresult = (text * ) NULL ;
1427
1427
else
1428
1428
{
1429
- char * start = _state -> result_start ;
1429
+ const char * start = _state -> result_start ;
1430
1430
int len = _state -> lex -> prev_token_terminator - start ;
1431
1431
1432
1432
_state -> tresult = cstring_to_text_with_len (start , len );
@@ -1463,7 +1463,7 @@ get_scalar(void *state, char *token, JsonTokenType tokentype)
1463
1463
* scalar token, but not whitespace before it. Probably not worth
1464
1464
* doing our own space-skipping to avoid that.
1465
1465
*/
1466
- char * start = _state -> lex -> input ;
1466
+ const char * start = _state -> lex -> input ;
1467
1467
int len = _state -> lex -> prev_token_terminator - start ;
1468
1468
1469
1469
_state -> tresult = cstring_to_text_with_len (start , len );
@@ -2782,7 +2782,7 @@ populate_array_scalar(void *_state, char *token, JsonTokenType tokentype)
2782
2782
* Returns false if an error occurs when parsing.
2783
2783
*/
2784
2784
static bool
2785
- populate_array_json (PopulateArrayContext * ctx , char * json , int len )
2785
+ populate_array_json (PopulateArrayContext * ctx , const char * json , int len )
2786
2786
{
2787
2787
PopulateArrayState state ;
2788
2788
JsonSemAction sem ;
@@ -3123,7 +3123,7 @@ populate_scalar(ScalarIOData *io, Oid typid, int32 typmod, JsValue *jsv,
3123
3123
{
3124
3124
Datum res ;
3125
3125
char * str = NULL ;
3126
- char * json = NULL ;
3126
+ const char * json = NULL ;
3127
3127
3128
3128
if (jsv -> is_json )
3129
3129
{
@@ -3139,7 +3139,10 @@ populate_scalar(ScalarIOData *io, Oid typid, int32 typmod, JsValue *jsv,
3139
3139
str [len ] = '\0' ;
3140
3140
}
3141
3141
else
3142
- str = json ; /* string is already null-terminated */
3142
+ {
3143
+ /* string is already null-terminated */
3144
+ str = unconstify (char * , json );
3145
+ }
3143
3146
3144
3147
/* If converting to json/jsonb, make string into valid JSON literal */
3145
3148
if ((typid == JSONOID || typid == JSONBOID ) &&
@@ -3784,7 +3787,7 @@ populate_record_worker(FunctionCallInfo fcinfo, const char *funcname,
3784
3787
* Returns the hash table if the json is parsed successfully, NULL otherwise.
3785
3788
*/
3786
3789
static HTAB *
3787
- get_json_object_as_hash (char * json , int len , const char * funcname ,
3790
+ get_json_object_as_hash (const char * json , int len , const char * funcname ,
3788
3791
Node * escontext )
3789
3792
{
3790
3793
HASHCTL ctl ;
0 commit comments