aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--TODO.xgawk5
-rw-r--r--awkgram.c19
-rw-r--r--awkgram.y19
-rw-r--r--test/ChangeLog8
-rw-r--r--test/Makefile.am28
-rw-r--r--test/Makefile.in28
-rw-r--r--test/incdupe4.ok2
-rw-r--r--test/incdupe5.ok2
-rw-r--r--test/incdupe6.ok3
-rw-r--r--test/incdupe7.ok3
-rw-r--r--test/inchello.awk1
12 files changed, 109 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index 86011883..d75c82ef 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2012-08-11 Andrew J. Schorr <aschorr@telemetry-investments.com>
+
+ * awkgram.y (add_srcfile): It is now a fatal error to load the
+ same file with -f and -i (or @include).
+ * TODO.xgawk: Update to reflect this change.
+
2012-08-10 Arnold D. Robbins <arnold@skeeve.com>
* FUTURES, TODO.xgawk: Updates.
diff --git a/TODO.xgawk b/TODO.xgawk
index e0913514..d26baa13 100644
--- a/TODO.xgawk
+++ b/TODO.xgawk
@@ -1,8 +1,5 @@
To-do list for xgawk enhancements:
-- Attempting to load the same file with -f and -i (or @include) should
- be a fatal error.
-
Low priority:
- Enhance extension/fork.c waitpid to allow the caller to specify the options.
@@ -141,3 +138,5 @@ Done:
* Still to go: Rework iop_alloc, interaction with open hooks, and
skipping command line directories.
+- Attempting to load the same file with -f and -i (or @include) should
+ be a fatal error.
diff --git a/awkgram.c b/awkgram.c
index 64a75832..83fc1ddb 100644
--- a/awkgram.c
+++ b/awkgram.c
@@ -5048,11 +5048,13 @@ add_srcfile(int stype, char *src, SRCFILE *thisfile, bool *already_included, int
}
/* N.B. We do not eliminate duplicate SRC_FILE (-f) programs. */
- if (stype == SRC_INC || stype == SRC_EXTLIB) {
- for (s = srcfiles->next; s != srcfiles; s = s->next) {
- if ((s->stype == SRC_FILE || s->stype == SRC_INC || s->stype == SRC_EXTLIB)
- && files_are_same(path, s)
- ) {
+ for (s = srcfiles->next; s != srcfiles; s = s->next) {
+ if ((s->stype == SRC_FILE || s->stype == SRC_INC || s->stype == SRC_EXTLIB) && files_are_same(path, s)) {
+ if (stype == SRC_INC || stype == SRC_EXTLIB) {
+ /* eliminate duplicates */
+ if ((stype == SRC_INC) && (s->stype == SRC_FILE))
+ fatal(_("can't include `%s' and use it as a program file"), src);
+
if (do_lint) {
int line = sourceline;
/* Kludge: the line number may be off for `@include file'.
@@ -5072,6 +5074,13 @@ add_srcfile(int stype, char *src, SRCFILE *thisfile, bool *already_included, int
if (already_included)
*already_included = true;
return NULL;
+ } else {
+ /* duplicates are allowed for -f */
+ if (s->stype == SRC_INC)
+ fatal(_("can't include `%s' and use it as a program file"), src);
+ /* no need to scan for further matches, since
+ * they must be of homogeneous type */
+ break;
}
}
}
diff --git a/awkgram.y b/awkgram.y
index d094b0e7..a6669e97 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -2328,11 +2328,13 @@ add_srcfile(int stype, char *src, SRCFILE *thisfile, bool *already_included, int
}
/* N.B. We do not eliminate duplicate SRC_FILE (-f) programs. */
- if (stype == SRC_INC || stype == SRC_EXTLIB) {
- for (s = srcfiles->next; s != srcfiles; s = s->next) {
- if ((s->stype == SRC_FILE || s->stype == SRC_INC || s->stype == SRC_EXTLIB)
- && files_are_same(path, s)
- ) {
+ for (s = srcfiles->next; s != srcfiles; s = s->next) {
+ if ((s->stype == SRC_FILE || s->stype == SRC_INC || s->stype == SRC_EXTLIB) && files_are_same(path, s)) {
+ if (stype == SRC_INC || stype == SRC_EXTLIB) {
+ /* eliminate duplicates */
+ if ((stype == SRC_INC) && (s->stype == SRC_FILE))
+ fatal(_("can't include `%s' and use it as a program file"), src);
+
if (do_lint) {
int line = sourceline;
/* Kludge: the line number may be off for `@include file'.
@@ -2352,6 +2354,13 @@ add_srcfile(int stype, char *src, SRCFILE *thisfile, bool *already_included, int
if (already_included)
*already_included = true;
return NULL;
+ } else {
+ /* duplicates are allowed for -f */
+ if (s->stype == SRC_INC)
+ fatal(_("can't include `%s' and use it as a program file"), src);
+ /* no need to scan for further matches, since
+ * they must be of homogeneous type */
+ break;
}
}
}
diff --git a/test/ChangeLog b/test/ChangeLog
index 2b1ac648..94c6ef18 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,11 @@
+2012-08-11 Andrew J. Schorr <aschorr@telemetry-investments.com>
+
+ * Makefile.am (EXTRA_DIST): Add inchello.awk and incdupe[4-7].ok.
+ (GAWK_EXT_TESTS): Add incdupe[4-7].
+ (incdupe[4-7]): New tests to ensure that mixing -f with include
+ causes a fatal error.
+ * incdupe[4-7].ok, inchello.awk: New files.
+
2012-08-08 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.am (fts): New test.
diff --git a/test/Makefile.am b/test/Makefile.am
index 3a8e48ca..c067f669 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -380,6 +380,11 @@ EXTRA_DIST = \
incdupe.ok \
incdupe2.ok \
incdupe3.ok \
+ inchello.awk \
+ incdupe4.ok \
+ incdupe5.ok \
+ incdupe6.ok \
+ incdupe7.ok \
indirectcall.awk \
indirectcall.in \
indirectcall.ok \
@@ -881,7 +886,8 @@ GAWK_EXT_TESTS = \
rebuf regx8bit reint reint2 rsstart1 \
rsstart2 rsstart3 rstest6 shadow sortfor sortu splitarg4 strftime \
strtonum switch2 \
- include include2 incdupe incdupe2 incdupe3
+ include include2 incdupe incdupe2 incdupe3 \
+ incdupe4 incdupe5 incdupe6 incdupe7
EXTRA_TESTS = inftest regtest
@@ -1593,6 +1599,26 @@ incdupe3::
@AWKPATH=$(srcdir) $(AWK) --lint -f hello -f hello.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@
+incdupe4::
+ @echo $@
+ @AWKPATH=$(srcdir) $(AWK) --lint -f hello -i hello.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@
+
+incdupe5::
+ @echo $@
+ @AWKPATH=$(srcdir) $(AWK) --lint -i hello -f hello.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@
+
+incdupe6::
+ @echo $@
+ @AWKPATH=$(srcdir) $(AWK) --lint -i inchello -f hello.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@
+
+incdupe7::
+ @echo $@
+ @AWKPATH=$(srcdir) $(AWK) --lint -f hello -i inchello >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@
+
testext::
@echo $@
@$(AWK) '/^(@load|BEGIN)/,/^}/' $(top_srcdir)/extension/testext.c > testext.awk
diff --git a/test/Makefile.in b/test/Makefile.in
index 0ba7c5c5..10d7b6a5 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -593,6 +593,11 @@ EXTRA_DIST = \
incdupe.ok \
incdupe2.ok \
incdupe3.ok \
+ inchello.awk \
+ incdupe4.ok \
+ incdupe5.ok \
+ incdupe6.ok \
+ incdupe7.ok \
indirectcall.awk \
indirectcall.in \
indirectcall.ok \
@@ -1094,7 +1099,8 @@ GAWK_EXT_TESTS = \
rebuf regx8bit reint reint2 rsstart1 \
rsstart2 rsstart3 rstest6 shadow sortfor sortu splitarg4 strftime \
strtonum switch2 \
- include include2 incdupe incdupe2 incdupe3
+ include include2 incdupe incdupe2 incdupe3 \
+ incdupe4 incdupe5 incdupe6 incdupe7
EXTRA_TESTS = inftest regtest
INET_TESTS = inetdayu inetdayt inetechu inetecht
@@ -1976,6 +1982,26 @@ incdupe3::
@AWKPATH=$(srcdir) $(AWK) --lint -f hello -f hello.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@
+incdupe4::
+ @echo $@
+ @AWKPATH=$(srcdir) $(AWK) --lint -f hello -i hello.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@
+
+incdupe5::
+ @echo $@
+ @AWKPATH=$(srcdir) $(AWK) --lint -i hello -f hello.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@
+
+incdupe6::
+ @echo $@
+ @AWKPATH=$(srcdir) $(AWK) --lint -i inchello -f hello.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@
+
+incdupe7::
+ @echo $@
+ @AWKPATH=$(srcdir) $(AWK) --lint -f hello -i inchello >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@
+
testext::
@echo $@
@$(AWK) '/^(@load|BEGIN)/,/^}/' $(top_srcdir)/extension/testext.c > testext.awk
diff --git a/test/incdupe4.ok b/test/incdupe4.ok
new file mode 100644
index 00000000..a6fc26e2
--- /dev/null
+++ b/test/incdupe4.ok
@@ -0,0 +1,2 @@
+gawk: fatal: can't include `hello.awk' and use it as a program file
+EXIT CODE: 2
diff --git a/test/incdupe5.ok b/test/incdupe5.ok
new file mode 100644
index 00000000..a6fc26e2
--- /dev/null
+++ b/test/incdupe5.ok
@@ -0,0 +1,2 @@
+gawk: fatal: can't include `hello.awk' and use it as a program file
+EXIT CODE: 2
diff --git a/test/incdupe6.ok b/test/incdupe6.ok
new file mode 100644
index 00000000..42a4f9fd
--- /dev/null
+++ b/test/incdupe6.ok
@@ -0,0 +1,3 @@
+gawk: inchello:1: warning: `include' is a gawk extension
+gawk: inchello:2: fatal: can't include `hello' and use it as a program file
+EXIT CODE: 2
diff --git a/test/incdupe7.ok b/test/incdupe7.ok
new file mode 100644
index 00000000..42a4f9fd
--- /dev/null
+++ b/test/incdupe7.ok
@@ -0,0 +1,3 @@
+gawk: inchello:1: warning: `include' is a gawk extension
+gawk: inchello:2: fatal: can't include `hello' and use it as a program file
+EXIT CODE: 2
diff --git a/test/inchello.awk b/test/inchello.awk
new file mode 100644
index 00000000..148d4bef
--- /dev/null
+++ b/test/inchello.awk
@@ -0,0 +1 @@
+@include "hello"