aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/nls.mk4
-rw-r--r--src/backend/replication/repl_gram.y7
-rw-r--r--src/backend/replication/repl_scanner.l10
-rw-r--r--src/backend/replication/syncrep.c8
-rw-r--r--src/backend/replication/syncrep_gram.y9
-rw-r--r--src/backend/replication/syncrep_scanner.l22
-rw-r--r--src/backend/replication/walsender.c4
7 files changed, 39 insertions, 25 deletions
diff --git a/src/backend/nls.mk b/src/backend/nls.mk
index 5a5298b33f7..b7d5dd46e45 100644
--- a/src/backend/nls.mk
+++ b/src/backend/nls.mk
@@ -9,9 +9,9 @@ GETTEXT_TRIGGERS = $(BACKEND_COMMON_GETTEXT_TRIGGERS) \
yyerror \
jsonpath_yyerror:4 \
parser_yyerror \
- replication_yyerror:2 \
+ replication_yyerror:3 \
scanner_yyerror \
- syncrep_yyerror:2 \
+ syncrep_yyerror:4 \
report_invalid_record:2 \
ereport_startup_progress \
json_token_error:2 \
diff --git a/src/backend/replication/repl_gram.y b/src/backend/replication/repl_gram.y
index 61e68d0727a..7440aae5a1a 100644
--- a/src/backend/replication/repl_gram.y
+++ b/src/backend/replication/repl_gram.y
@@ -25,10 +25,6 @@
#include "repl_gram.h"
-/* Result of the parsing is returned here */
-Node *replication_parse_result;
-
-
/*
* Bison doesn't allocate anything that needs to live across parser calls,
* so we can easily have it use palloc instead of malloc. This prevents
@@ -39,6 +35,7 @@ Node *replication_parse_result;
%}
+%parse-param {Node **replication_parse_result_p}
%parse-param {yyscan_t yyscanner}
%lex-param {yyscan_t yyscanner}
%pure-parser
@@ -104,7 +101,7 @@ Node *replication_parse_result;
firstcmd: command opt_semicolon
{
- replication_parse_result = $1;
+ *replication_parse_result_p = $1;
(void) yynerrs; /* suppress compiler warning */
}
diff --git a/src/backend/replication/repl_scanner.l b/src/backend/replication/repl_scanner.l
index de10cb5abd1..014ea8d25c6 100644
--- a/src/backend/replication/repl_scanner.l
+++ b/src/backend/replication/repl_scanner.l
@@ -156,7 +156,7 @@ UPLOAD_MANIFEST { return K_UPLOAD_MANIFEST; }
uint32 hi,
lo;
if (sscanf(yytext, "%X/%X", &hi, &lo) != 2)
- replication_yyerror(yyscanner, "invalid streaming start location");
+ replication_yyerror(NULL, yyscanner, "invalid streaming start location");
yylval->recptr = ((uint64) hi) << 32 | lo;
return RECPTR;
}
@@ -213,7 +213,7 @@ UPLOAD_MANIFEST { return K_UPLOAD_MANIFEST; }
return yytext[0];
}
-<xq,xd><<EOF>> { replication_yyerror(yyscanner, "unterminated quoted string"); }
+<xq,xd><<EOF>> { replication_yyerror(NULL, yyscanner, "unterminated quoted string"); }
<<EOF>> {
@@ -252,8 +252,12 @@ addlitchar(unsigned char ychar, yyscan_t yyscanner)
appendStringInfoChar(&yyextra->litbuf, ychar);
}
+/*
+ * (The first argument is enforced by Bison to match the first argument of
+ * yyparse(), but it is not used here.)
+ */
void
-replication_yyerror(yyscan_t yyscanner, const char *message)
+replication_yyerror(Node **replication_parse_result_p, yyscan_t yyscanner, const char *message)
{
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
diff --git a/src/backend/replication/syncrep.c b/src/backend/replication/syncrep.c
index 1ce8bc7533f..d75e3968035 100644
--- a/src/backend/replication/syncrep.c
+++ b/src/backend/replication/syncrep.c
@@ -996,13 +996,13 @@ check_synchronous_standby_names(char **newval, void **extra, GucSource source)
int parse_rc;
SyncRepConfigData *pconf;
- /* Reset communication variables to ensure a fresh start */
- syncrep_parse_result = NULL;
- syncrep_parse_error_msg = NULL;
+ /* Result of parsing is returned in one of these two variables */
+ SyncRepConfigData *syncrep_parse_result = NULL;
+ char *syncrep_parse_error_msg = NULL;
/* Parse the synchronous_standby_names string */
syncrep_scanner_init(*newval, &scanner);
- parse_rc = syncrep_yyparse(scanner);
+ parse_rc = syncrep_yyparse(&syncrep_parse_result, &syncrep_parse_error_msg, scanner);
syncrep_scanner_finish(scanner);
if (parse_rc != 0 || syncrep_parse_result == NULL)
diff --git a/src/backend/replication/syncrep_gram.y b/src/backend/replication/syncrep_gram.y
index 1a3b89ca674..22297bb151a 100644
--- a/src/backend/replication/syncrep_gram.y
+++ b/src/backend/replication/syncrep_gram.y
@@ -19,10 +19,6 @@
#include "syncrep_gram.h"
-/* Result of parsing is returned in one of these two variables */
-SyncRepConfigData *syncrep_parse_result;
-char *syncrep_parse_error_msg;
-
static SyncRepConfigData *create_syncrep_config(const char *num_sync,
List *members, uint8 syncrep_method);
@@ -36,7 +32,10 @@ static SyncRepConfigData *create_syncrep_config(const char *num_sync,
%}
+%parse-param {SyncRepConfigData **syncrep_parse_result_p}
+%parse-param {char **syncrep_parse_error_msg_p}
%parse-param {yyscan_t yyscanner}
+%lex-param {char **syncrep_parse_error_msg_p}
%lex-param {yyscan_t yyscanner}
%pure-parser
%expect 0
@@ -60,7 +59,7 @@ static SyncRepConfigData *create_syncrep_config(const char *num_sync,
%%
result:
standby_config {
- syncrep_parse_result = $1;
+ *syncrep_parse_result_p = $1;
(void) yynerrs; /* suppress compiler warning */
}
;
diff --git a/src/backend/replication/syncrep_scanner.l b/src/backend/replication/syncrep_scanner.l
index 05e5fdecf1b..7dec1f869c7 100644
--- a/src/backend/replication/syncrep_scanner.l
+++ b/src/backend/replication/syncrep_scanner.l
@@ -42,6 +42,13 @@ struct syncrep_yy_extra_type
StringInfoData xdbuf;
};
+/*
+ * Better keep this definition here than put it in replication/syncrep.h and
+ * save a bit of duplication. Putting it in replication/syncrep.h would leak
+ * the definition to other parts and possibly affect other scanners.
+*/
+#define YY_DECL extern int syncrep_yylex(union YYSTYPE *yylval_param, char **syncrep_parse_error_msg_p, yyscan_t yyscanner)
+
/* LCOV_EXCL_START */
%}
@@ -104,7 +111,7 @@ xdinside [^"]+
return NAME;
}
<xd><<EOF>> {
- syncrep_yyerror(yyscanner, "unterminated quoted identifier");
+ syncrep_yyerror(NULL, syncrep_parse_error_msg_p, yyscanner, "unterminated quoted identifier");
return JUNK;
}
@@ -136,12 +143,21 @@ xdinside [^"]+
#undef yyextra
#define yyextra (((struct yyguts_t *) yyscanner)->yyextra_r)
-/* Needs to be here for access to yytext */
+/*
+ * This yyerror() function does not raise an error (elog or similar), it just
+ * collects the error message in *syncrep_parse_error_msg_p and leaves it to
+ * the ultimate caller of the syncrep parser to raise the error. (The
+ * ultimate caller will do that with special GUC error functions.)
+ *
+ * (The first argument is enforced by Bison to match the first argument of
+ * yyparse(), but it is not used here.)
+ */
void
-syncrep_yyerror(yyscan_t yyscanner, const char *message)
+syncrep_yyerror(SyncRepConfigData **syncrep_parse_result_p, char **syncrep_parse_error_msg_p, yyscan_t yyscanner, const char *message)
{
struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; /* needed for yytext
* macro */
+ char *syncrep_parse_error_msg = *syncrep_parse_error_msg_p;
/* report only the first error in a parse operation */
if (syncrep_parse_error_msg)
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index a0782b1bbf6..bac504b554e 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -2017,7 +2017,7 @@ exec_replication_command(const char *cmd_string)
/*
* Looks like a WalSender command, so parse it.
*/
- parse_rc = replication_yyparse(scanner);
+ parse_rc = replication_yyparse(&cmd_node, scanner);
if (parse_rc != 0)
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
@@ -2025,8 +2025,6 @@ exec_replication_command(const char *cmd_string)
parse_rc)));
replication_scanner_finish(scanner);
- cmd_node = replication_parse_result;
-
/*
* Report query to various monitoring facilities. For this purpose, we
* report replication commands just like SQL commands.