Skip to content

Commit 85128e5

Browse files
committed
Rethink the idea of having plpgsql depend on parser/gram.h. Aside from the
fact that this is breaking the MSVC build, it's probably not really a good idea to expand the dependencies of gram.h any further than the core parser; for instance the value of SCONST might depend on which bison version you'd built with. Better to expose an additional call point in parser.c, so move what I had put into pl_funcs.c into parser.c. Also PGDLLIMPORT'ify the reference to standard_conforming_strings, per buildfarm results.
1 parent 22c9222 commit 85128e5

File tree

6 files changed

+43
-50
lines changed

6 files changed

+43
-50
lines changed

src/backend/parser/parser.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Portions Copyright (c) 1994, Regents of the University of California
1515
*
1616
* IDENTIFICATION
17-
* $PostgreSQL: pgsql/src/backend/parser/parser.c,v 1.76 2009/01/01 17:23:46 momjian Exp $
17+
* $PostgreSQL: pgsql/src/backend/parser/parser.c,v 1.77 2009/04/19 21:50:08 tgl Exp $
1818
*
1919
*-------------------------------------------------------------------------
2020
*/
@@ -62,6 +62,36 @@ raw_parser(const char *str)
6262
}
6363

6464

65+
/*
66+
* pg_parse_string_token - get the value represented by a string literal
67+
*
68+
* Given the textual form of a SQL string literal, produce the represented
69+
* value as a palloc'd string. It is caller's responsibility that the
70+
* passed string does represent one single string literal.
71+
*
72+
* We export this function to avoid having plpgsql depend on internal details
73+
* of the core grammar (such as the token code assigned to SCONST). Note
74+
* that since the scanner isn't presently re-entrant, this cannot be used
75+
* during use of the main parser/scanner.
76+
*/
77+
char *
78+
pg_parse_string_token(const char *token)
79+
{
80+
int ctoken;
81+
82+
scanner_init(token);
83+
84+
ctoken = base_yylex();
85+
86+
if (ctoken != SCONST) /* caller error */
87+
elog(ERROR, "expected string constant, got token code %d", ctoken);
88+
89+
scanner_finish();
90+
91+
return base_yylval.str;
92+
}
93+
94+
6595
/*
6696
* Intermediate filter between parser and base lexer (base_yylex in scan.l).
6797
*

src/include/parser/parser.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/parser/parser.h,v 1.24 2009/01/01 17:24:00 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/parser/parser.h,v 1.25 2009/04/19 21:50:08 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -18,4 +18,6 @@
1818

1919
extern List *raw_parser(const char *str);
2020

21+
extern char *pg_parse_string_token(const char *token);
22+
2123
#endif /* PARSER_H */

src/pl/plpgsql/src/gram.y

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/pl/plpgsql/src/gram.y,v 1.122 2009/04/19 18:52:57 tgl Exp $
12+
* $PostgreSQL: pgsql/src/pl/plpgsql/src/gram.y,v 1.123 2009/04/19 21:50:09 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -2737,10 +2737,9 @@ plpgsql_sql_error_callback(void *arg)
27372737
/*
27382738
* Convert a string-literal token to the represented string value.
27392739
*
2740-
* To do this, we need to invoke the core lexer. To avoid confusion between
2741-
* the core bison/flex definitions and our own, the actual invocation is in
2742-
* pl_funcs.c. Here we are only concerned with setting up the right errcontext
2743-
* state, which is handled the same as in check_sql_expr().
2740+
* To do this, we need to invoke the core lexer. Here we are only concerned
2741+
* with setting up the right errcontext state, which is handled the same as
2742+
* in check_sql_expr().
27442743
*/
27452744
static char *
27462745
parse_string_token(const char *token)
@@ -2758,7 +2757,7 @@ parse_string_token(const char *token)
27582757
syntax_errcontext.previous = error_context_stack->previous;
27592758
error_context_stack = &syntax_errcontext;
27602759

2761-
result = plpgsql_parse_string_token(token);
2760+
result = pg_parse_string_token(token);
27622761

27632762
/* Restore former ereport callback */
27642763
error_context_stack = previous_errcontext;

src/pl/plpgsql/src/pl_funcs.c

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_funcs.c,v 1.77 2009/04/19 18:52:57 tgl Exp $
11+
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_funcs.c,v 1.78 2009/04/19 21:50:09 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -17,8 +17,6 @@
1717

1818
#include <ctype.h>
1919

20-
#include "parser/gramparse.h"
21-
#include "parser/gram.h"
2220
#include "parser/scansup.h"
2321

2422

@@ -461,41 +459,6 @@ plpgsql_convert_ident(const char *s, char **output, int numidents)
461459
}
462460

463461

464-
/*
465-
* plpgsql_parse_string_token - get the value represented by a string literal
466-
*
467-
* We do not make plpgsql's lexer produce the represented value, because
468-
* in many cases we don't need it. Instead this function is invoked when
469-
* we do need it. The input is the T_STRING token as identified by the lexer.
470-
*
471-
* The result is a palloc'd string.
472-
*
473-
* Note: this is called only from plpgsql's gram.y, but we can't just put it
474-
* there because including parser/gram.h there would cause confusion.
475-
*/
476-
char *
477-
plpgsql_parse_string_token(const char *token)
478-
{
479-
int ctoken;
480-
481-
/*
482-
* We use the core lexer to do the dirty work. Aside from getting the
483-
* right results for escape sequences and so on, this helps us produce
484-
* appropriate warnings for escape_string_warning etc.
485-
*/
486-
scanner_init(token);
487-
488-
ctoken = base_yylex();
489-
490-
if (ctoken != SCONST)
491-
elog(ERROR, "unexpected result from base lexer: %d", ctoken);
492-
493-
scanner_finish();
494-
495-
return base_yylval.str;
496-
}
497-
498-
499462
/*
500463
* Statement type as a string, for use in error messages etc.
501464
*/

src/pl/plpgsql/src/plpgsql.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/pl/plpgsql/src/plpgsql.h,v 1.111 2009/04/19 18:52:57 tgl Exp $
11+
* $PostgreSQL: pgsql/src/pl/plpgsql/src/plpgsql.h,v 1.112 2009/04/19 21:50:09 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -880,7 +880,6 @@ extern void plpgsql_ns_rename(char *oldname, char *newname);
880880
* ----------
881881
*/
882882
extern void plpgsql_convert_ident(const char *s, char **output, int numidents);
883-
extern char *plpgsql_parse_string_token(const char *token);
884883
extern const char *plpgsql_stmt_typename(PLpgSQL_stmt *stmt);
885884
extern void plpgsql_dumptree(PLpgSQL_function *func);
886885

src/pl/plpgsql/src/scan.l

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/pl/plpgsql/src/scan.l,v 1.68 2009/04/19 18:52:57 tgl Exp $
12+
* $PostgreSQL: pgsql/src/pl/plpgsql/src/scan.l,v 1.69 2009/04/19 21:50:09 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -43,7 +43,7 @@ static int cur_line_num;
4343
static int xcdepth = 0; /* depth of nesting in slash-star comments */
4444
static char *dolqstart; /* current $foo$ quote start string */
4545

46-
extern bool standard_conforming_strings;
46+
extern PGDLLIMPORT bool standard_conforming_strings;
4747

4848
bool plpgsql_SpaceScanned = false;
4949
%}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy