diff options
Diffstat (limited to 'src/common/jsonapi.c')
-rw-r--r-- | src/common/jsonapi.c | 61 |
1 files changed, 30 insertions, 31 deletions
diff --git a/src/common/jsonapi.c b/src/common/jsonapi.c index d376ab152d4..5504072b4fb 100644 --- a/src/common/jsonapi.c +++ b/src/common/jsonapi.c @@ -20,20 +20,10 @@ #include "common/jsonapi.h" #include "mb/pg_wchar.h" -#ifdef FRONTEND -#include "common/logging.h" -#else +#ifndef FRONTEND #include "miscadmin.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 * mechanism, but is passed explicitly to the error reporting routine @@ -61,7 +51,6 @@ static JsonParseErrorType parse_object(JsonLexContext *lex, JsonSemAction *sem); static JsonParseErrorType parse_array_element(JsonLexContext *lex, JsonSemAction *sem); static JsonParseErrorType parse_array(JsonLexContext *lex, JsonSemAction *sem); static JsonParseErrorType report_parse_error(JsonParseContext ctx, JsonLexContext *lex); -static char *extract_token(JsonLexContext *lex); /* the null action object used for pure validation */ JsonSemAction nullSemAction = @@ -378,7 +367,9 @@ parse_object(JsonLexContext *lex, JsonSemAction *sem) JsonTokenType tok; JsonParseErrorType result; +#ifndef FRONTEND check_stack_depth(); +#endif if (ostart != NULL) (*ostart) (sem->semstate); @@ -478,7 +469,9 @@ parse_array(JsonLexContext *lex, JsonSemAction *sem) json_struct_action aend = sem->array_end; JsonParseErrorType result; +#ifndef FRONTEND check_stack_depth(); +#endif if (astart != NULL) (*astart) (sem->semstate); @@ -1044,15 +1037,34 @@ report_parse_error(JsonParseContext ctx, JsonLexContext *lex) /* * We don't use a default: case, so that the compiler will warn about - * unhandled enum values. But this needs to be here anyway to cover the - * possibility of an incorrect input. + * unhandled enum values. */ - json_log_and_abort("unexpected json parse state: %d", (int) ctx); + Assert(false); return JSON_SUCCESS; /* silence stupider compilers */ } + +#ifndef FRONTEND +/* + * Extract the current token from a lexing context, for error reporting. + */ +static char * +extract_token(JsonLexContext *lex) +{ + int toklen = lex->token_terminator - lex->token_start; + char *token = palloc(toklen + 1); + + memcpy(token, lex->token_start, toklen); + token[toklen] = '\0'; + return token; +} + /* * Construct a detail message for a JSON error. + * + * Note that the error message generated by this routine may not be + * palloc'd, making it unsafe for frontend code as there is no way to + * know if this can be safery pfree'd or not. */ char * json_errdetail(JsonParseErrorType error, JsonLexContext *lex) @@ -1115,20 +1127,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. */ - json_log_and_abort("unexpected json parse error type: %d", (int) error); - return NULL; /* silence stupider compilers */ -} - -/* - * Extract the current token from a lexing context, for error reporting. - */ -static char * -extract_token(JsonLexContext *lex) -{ - int toklen = lex->token_terminator - lex->token_start; - char *token = palloc(toklen + 1); - - memcpy(token, lex->token_start, toklen); - token[toklen] = '\0'; - return token; + elog(ERROR, "unexpected json parse error type: %d", (int) error); + return NULL; } +#endif |