Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ecf2487

Browse files
committed
Add makefile rules to check for backtracking in backend and psql lexers.
Per discussion, we should enforce the policy of "no backtracking" in these performance-sensitive scanners.
1 parent 77ce50a commit ecf2487

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/backend/parser/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ OBJS= analyze.o gram.o keywords.o kwlookup.o parser.o \
1717
parse_expr.o parse_func.o parse_node.o parse_oper.o parse_param.o \
1818
parse_relation.o parse_target.o parse_type.o parse_utilcmd.o scansup.o
1919

20-
FLEXFLAGS = -CF
20+
FLEXFLAGS = -CF -b -p -p
2121

2222
include $(top_srcdir)/src/backend/common.mk
2323

@@ -51,6 +51,7 @@ endif
5151
scan.c: scan.l
5252
ifdef FLEX
5353
$(FLEX) $(FLEXFLAGS) -o'$@' $<
54+
@if [ `wc -l <lex.backup` -eq 1 ]; then rm lex.backup; else echo "Scanner requires backup, see lex.backup."; exit 1; fi
5455
else
5556
@$(missing) flex $< $@
5657
endif
@@ -62,3 +63,5 @@ gram.o keywords.o parser.o: gram.h
6263

6364
# gram.c, gram.h, and scan.c are in the distribution tarball, so they
6465
# are not cleaned here.
66+
clean distclean maintainer-clean:
67+
rm -f lex.backup

src/backend/parser/scan.l

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
* for handling float numbers and continued string literals. If you change
1818
* the lexical rules, verify that you haven't broken the no-backtrack
1919
* property by running flex with the "-b" option and checking that the
20-
* resulting "lex.backup" file says that no backing up is needed.
20+
* resulting "lex.backup" file says that no backing up is needed. (As of
21+
* Postgres 9.2, this check is made automatically by the Makefile.)
2122
*
2223
*
2324
* Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group

src/bin/psql/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ OBJS= command.o common.o help.o input.o stringutils.o mainloop.o copy.o \
2626
sql_help.o \
2727
$(WIN32RES)
2828

29-
FLEXFLAGS = -Cfe
29+
FLEXFLAGS = -Cfe -b -p -p
3030

3131

3232
all: psql
@@ -52,6 +52,7 @@ mainloop.o: psqlscan.c
5252
psqlscan.c: psqlscan.l
5353
ifdef FLEX
5454
$(FLEX) $(FLEXFLAGS) -o'$@' $<
55+
@if [ `wc -l <lex.backup` -eq 1 ]; then rm lex.backup; else echo "Scanner requires backup, see lex.backup."; exit 1; fi
5556
else
5657
@$(missing) flex $< $@
5758
endif
@@ -70,7 +71,7 @@ uninstall:
7071

7172
# psqlscan.c is in the distribution tarball, so is not cleaned here
7273
clean distclean:
73-
rm -f psql$(X) $(OBJS) dumputils.c keywords.c kwlookup.c
74+
rm -f psql$(X) $(OBJS) dumputils.c keywords.c kwlookup.c lex.backup
7475

7576
maintainer-clean: distclean
7677
rm -f sql_help.h sql_help.c psqlscan.c

0 commit comments

Comments
 (0)