@@ -86,7 +86,7 @@ typedef struct GetState
8686{
8787 JsonLexContext * lex ;
8888 text * tresult ;
89- char * result_start ;
89+ const char * result_start ;
9090 bool normalize_results ;
9191 bool next_scalar ;
9292 int npath ; /* length of each path-related array */
@@ -111,7 +111,7 @@ typedef struct EachState
111111 Tuplestorestate * tuple_store ;
112112 TupleDesc ret_tdesc ;
113113 MemoryContext tmp_cxt ;
114- char * result_start ;
114+ const char * result_start ;
115115 bool normalize_results ;
116116 bool next_scalar ;
117117 char * normalized_scalar ;
@@ -125,7 +125,7 @@ typedef struct ElementsState
125125 Tuplestorestate * tuple_store ;
126126 TupleDesc ret_tdesc ;
127127 MemoryContext tmp_cxt ;
128- char * result_start ;
128+ const char * result_start ;
129129 bool normalize_results ;
130130 bool next_scalar ;
131131 char * normalized_scalar ;
@@ -138,7 +138,7 @@ typedef struct JHashState
138138 const char * function_name ;
139139 HTAB * hash ;
140140 char * saved_scalar ;
141- char * save_json_start ;
141+ const char * save_json_start ;
142142 JsonTokenType saved_token_type ;
143143} JHashState ;
144144
@@ -247,7 +247,7 @@ typedef struct PopulateRecordsetState
247247 const char * function_name ;
248248 HTAB * json_hash ;
249249 char * saved_scalar ;
250- char * save_json_start ;
250+ const char * save_json_start ;
251251 JsonTokenType saved_token_type ;
252252 Tuplestorestate * tuple_store ;
253253 HeapTupleHeader rec ;
@@ -273,7 +273,7 @@ typedef struct PopulateArrayState
273273{
274274 JsonLexContext * lex ; /* json lexer */
275275 PopulateArrayContext * ctx ; /* context */
276- char * element_start ; /* start of the current array element */
276+ const char * element_start ; /* start of the current array element */
277277 char * element_scalar ; /* current array element token if it is a
278278 * scalar */
279279 JsonTokenType element_type ; /* current array element type */
@@ -295,7 +295,7 @@ typedef struct JsValue
295295 {
296296 struct
297297 {
298- char * str ; /* json string */
298+ const char * str ; /* json string */
299299 int len ; /* json string length or -1 if null-terminated */
300300 JsonTokenType type ; /* json type */
301301 } json ; /* json value */
@@ -390,7 +390,7 @@ static JsonParseErrorType elements_array_element_end(void *state, bool isnull);
390390static JsonParseErrorType elements_scalar (void * state , char * token , JsonTokenType tokentype );
391391
392392/* 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 ,
394394 Node * escontext );
395395
396396/* semantic actions for populate_array_json */
@@ -456,7 +456,7 @@ static Datum populate_record_field(ColumnIOData *col, Oid typid, int32 typmod,
456456static RecordIOData * allocate_record_info (MemoryContext mcxt , int ncolumns );
457457static bool JsObjectGetField (JsObject * obj , char * field , JsValue * jsv );
458458static 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 );
460460static bool populate_array_dim_jsonb (PopulateArrayContext * ctx , JsonbValue * jbv ,
461461 int ndim );
462462static void populate_array_report_expected_array (PopulateArrayContext * ctx , int ndim );
@@ -1181,7 +1181,7 @@ get_object_end(void *state)
11811181 if (lex_level == 0 && _state -> npath == 0 )
11821182 {
11831183 /* Special case: return the entire object */
1184- char * start = _state -> result_start ;
1184+ const char * start = _state -> result_start ;
11851185 int len = _state -> lex -> prev_token_terminator - start ;
11861186
11871187 _state -> tresult = cstring_to_text_with_len (start , len );
@@ -1275,7 +1275,7 @@ get_object_field_end(void *state, char *fname, bool isnull)
12751275 _state -> tresult = (text * ) NULL ;
12761276 else
12771277 {
1278- char * start = _state -> result_start ;
1278+ const char * start = _state -> result_start ;
12791279 int len = _state -> lex -> prev_token_terminator - start ;
12801280
12811281 _state -> tresult = cstring_to_text_with_len (start , len );
@@ -1337,7 +1337,7 @@ get_array_end(void *state)
13371337 if (lex_level == 0 && _state -> npath == 0 )
13381338 {
13391339 /* Special case: return the entire array */
1340- char * start = _state -> result_start ;
1340+ const char * start = _state -> result_start ;
13411341 int len = _state -> lex -> prev_token_terminator - start ;
13421342
13431343 _state -> tresult = cstring_to_text_with_len (start , len );
@@ -1426,7 +1426,7 @@ get_array_element_end(void *state, bool isnull)
14261426 _state -> tresult = (text * ) NULL ;
14271427 else
14281428 {
1429- char * start = _state -> result_start ;
1429+ const char * start = _state -> result_start ;
14301430 int len = _state -> lex -> prev_token_terminator - start ;
14311431
14321432 _state -> tresult = cstring_to_text_with_len (start , len );
@@ -1463,7 +1463,7 @@ get_scalar(void *state, char *token, JsonTokenType tokentype)
14631463 * scalar token, but not whitespace before it. Probably not worth
14641464 * doing our own space-skipping to avoid that.
14651465 */
1466- char * start = _state -> lex -> input ;
1466+ const char * start = _state -> lex -> input ;
14671467 int len = _state -> lex -> prev_token_terminator - start ;
14681468
14691469 _state -> tresult = cstring_to_text_with_len (start , len );
@@ -2782,7 +2782,7 @@ populate_array_scalar(void *_state, char *token, JsonTokenType tokentype)
27822782 * Returns false if an error occurs when parsing.
27832783 */
27842784static bool
2785- populate_array_json (PopulateArrayContext * ctx , char * json , int len )
2785+ populate_array_json (PopulateArrayContext * ctx , const char * json , int len )
27862786{
27872787 PopulateArrayState state ;
27882788 JsonSemAction sem ;
@@ -3123,7 +3123,7 @@ populate_scalar(ScalarIOData *io, Oid typid, int32 typmod, JsValue *jsv,
31233123{
31243124 Datum res ;
31253125 char * str = NULL ;
3126- char * json = NULL ;
3126+ const char * json = NULL ;
31273127
31283128 if (jsv -> is_json )
31293129 {
@@ -3139,7 +3139,10 @@ populate_scalar(ScalarIOData *io, Oid typid, int32 typmod, JsValue *jsv,
31393139 str [len ] = '\0' ;
31403140 }
31413141 else
3142- str = json ; /* string is already null-terminated */
3142+ {
3143+ /* string is already null-terminated */
3144+ str = unconstify (char * , json );
3145+ }
31433146
31443147 /* If converting to json/jsonb, make string into valid JSON literal */
31453148 if ((typid == JSONOID || typid == JSONBOID ) &&
@@ -3784,7 +3787,7 @@ populate_record_worker(FunctionCallInfo fcinfo, const char *funcname,
37843787 * Returns the hash table if the json is parsed successfully, NULL otherwise.
37853788 */
37863789static 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 ,
37883791 Node * escontext )
37893792{
37903793 HASHCTL ctl ;
0 commit comments