linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] kconfig: remove duplicated file name and lineno of recursive inclusion
@ 2018-03-22 17:00 Masahiro Yamada
  2018-03-22 17:00 ` [PATCH 2/3] kconfig: detect recursive inclusion earlier Masahiro Yamada
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Masahiro Yamada @ 2018-03-22 17:00 UTC (permalink / raw)
  To: linux-kbuild
  Cc: Michal Marek, Sam Ravnborg, Ulf Magnusson, Luis R . Rodriguez,
	Masahiro Yamada, linux-kernel

As in the unit test, the error message for the recursive inclusion
looks like this:

  Kconfig.inc1:4: recursive inclusion detected. Inclusion path:
    current file : 'Kconfig.inc1'
    included from: 'Kconfig.inc3:1'
    included from: 'Kconfig.inc2:3'
    included from: 'Kconfig.inc1:4'

The 'Kconfig.inc1:4' is duplicated in the first and last lines.
Also, the single quotes do not help readability.

Change the message like follows:

  Recursive inclusion detected.
  Inclusion path:
    current file : Kconfig.inc1
    included from: Kconfig.inc3:1
    included from: Kconfig.inc2:3
    included from: Kconfig.inc1:4

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

 scripts/kconfig/tests/err_recursive_inc/expected_stderr | 11 ++++++-----
 scripts/kconfig/zconf.l                                 |  9 ++++-----
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/scripts/kconfig/tests/err_recursive_inc/expected_stderr b/scripts/kconfig/tests/err_recursive_inc/expected_stderr
index a15dbed..6b582ee 100644
--- a/scripts/kconfig/tests/err_recursive_inc/expected_stderr
+++ b/scripts/kconfig/tests/err_recursive_inc/expected_stderr
@@ -1,5 +1,6 @@
-Kconfig.inc1:4: recursive inclusion detected. Inclusion path:
-  current file : 'Kconfig.inc1'
-  included from: 'Kconfig.inc3:1'
-  included from: 'Kconfig.inc2:3'
-  included from: 'Kconfig.inc1:4'
+Recursive inclusion detected.
+Inclusion path:
+  current file : Kconfig.inc1
+  included from: Kconfig.inc3:1
+  included from: Kconfig.inc2:3
+  included from: Kconfig.inc1:4
diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l
index 88b650e..6f139d2 100644
--- a/scripts/kconfig/zconf.l
+++ b/scripts/kconfig/zconf.l
@@ -328,14 +328,13 @@ void zconf_nextfile(const char *name)
 	for (iter = current_file->parent; iter; iter = iter->parent ) {
 		if (!strcmp(current_file->name,iter->name) ) {
 			fprintf(stderr,
-				"%s:%d: recursive inclusion detected. "
-				"Inclusion path:\n  current file : '%s'\n",
-				zconf_curname(), zconf_lineno(),
-				zconf_curname());
+				"Recursive inclusion detected.\n"
+				"Inclusion path:\n"
+				"  current file : %s\n", zconf_curname());
 			iter = current_file;
 			do {
 				iter = iter->parent;
-				fprintf(stderr, "  included from: '%s:%d'\n",
+				fprintf(stderr, "  included from: %s:%d\n",
 					iter->name, iter->lineno - 1);
 			} while (strcmp(iter->name, current_file->name));
 			exit(1);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/3] kconfig: detect recursive inclusion earlier
  2018-03-22 17:00 [PATCH 1/3] kconfig: remove duplicated file name and lineno of recursive inclusion Masahiro Yamada
@ 2018-03-22 17:00 ` Masahiro Yamada
  2018-03-26 15:24   ` Masahiro Yamada
  2018-03-22 17:00 ` [PATCH 3/3] kconfig: use yylineno option instead of manual lineno increments Masahiro Yamada
  2018-03-26 15:24 ` [PATCH 1/3] kconfig: remove duplicated file name and lineno of recursive inclusion Masahiro Yamada
  2 siblings, 1 reply; 6+ messages in thread
From: Masahiro Yamada @ 2018-03-22 17:00 UTC (permalink / raw)
  To: linux-kbuild
  Cc: Michal Marek, Sam Ravnborg, Ulf Magnusson, Luis R . Rodriguez,
	Masahiro Yamada, linux-kernel

Currently, the recursive inclusion is not detected when the offending
file is about to be included; it is detected the offending file is
about to include the *next* file.  This is because the detection loop
does not involve the file being included.

Do this check against the file that is about to be included so that
the recursive inclusion is detected before unneeded parsing happens.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

 scripts/kconfig/zconf.l | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l
index 6f139d2..29b5d33 100644
--- a/scripts/kconfig/zconf.l
+++ b/scripts/kconfig/zconf.l
@@ -325,23 +325,25 @@ void zconf_nextfile(const char *name)
 	buf->parent = current_buf;
 	current_buf = buf;
 
-	for (iter = current_file->parent; iter; iter = iter->parent ) {
-		if (!strcmp(current_file->name,iter->name) ) {
+	file->parent = current_file;
+
+	for (iter = current_file; iter; iter = iter->parent) {
+		if (!strcmp(iter->name, file->name)) {
 			fprintf(stderr,
 				"Recursive inclusion detected.\n"
 				"Inclusion path:\n"
-				"  current file : %s\n", zconf_curname());
-			iter = current_file;
+				"  current file : %s\n", file->name);
+			iter = file;
 			do {
 				iter = iter->parent;
 				fprintf(stderr, "  included from: %s:%d\n",
 					iter->name, iter->lineno - 1);
-			} while (strcmp(iter->name, current_file->name));
+			} while (strcmp(iter->name, file->name));
 			exit(1);
 		}
 	}
+
 	file->lineno = 1;
-	file->parent = current_file;
 	current_file = file;
 }
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/3] kconfig: use yylineno option instead of manual lineno increments
  2018-03-22 17:00 [PATCH 1/3] kconfig: remove duplicated file name and lineno of recursive inclusion Masahiro Yamada
  2018-03-22 17:00 ` [PATCH 2/3] kconfig: detect recursive inclusion earlier Masahiro Yamada
@ 2018-03-22 17:00 ` Masahiro Yamada
  2018-03-26 15:25   ` Masahiro Yamada
  2018-03-26 15:24 ` [PATCH 1/3] kconfig: remove duplicated file name and lineno of recursive inclusion Masahiro Yamada
  2 siblings, 1 reply; 6+ messages in thread
From: Masahiro Yamada @ 2018-03-22 17:00 UTC (permalink / raw)
  To: linux-kbuild
  Cc: Michal Marek, Sam Ravnborg, Ulf Magnusson, Luis R . Rodriguez,
	Masahiro Yamada, linux-kernel

Tracking the line number by hand is error-prone since we need to make
sure to increment it in all the \n matching patterns.

If '%option yylineno' is set, flex defines 'yylineno' to contain the
current line number and automatically updates it each time it reads a
\n character.  This is much more convenient although the lexer does
not initializes yylineno, so you need to set it to 1 each time you
start reading a new file, and restore it you go back to the previous
file.

I tested this with DEBUG_PARSE, and confirmed the same dump message
was produced.

I removed the perf-report option.  Otherwise, I see the following
message:
  %option yylineno entails a performance penalty ONLY on rules that
  can match newline characters

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

 scripts/kconfig/lkc.h   |  1 +
 scripts/kconfig/zconf.l | 20 +++++++++-----------
 2 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h
index 2d5ec2d..f4394af 100644
--- a/scripts/kconfig/lkc.h
+++ b/scripts/kconfig/lkc.h
@@ -68,6 +68,7 @@ struct kconf_id {
 	enum symbol_type stype;
 };
 
+extern int yylineno;
 void zconfdump(FILE *out);
 void zconf_starthelp(void);
 FILE *zconf_fopen(const char *name);
diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l
index 29b5d33..045093d 100644
--- a/scripts/kconfig/zconf.l
+++ b/scripts/kconfig/zconf.l
@@ -1,5 +1,5 @@
 %option nostdinit noyywrap never-interactive full ecs
-%option 8bit nodefault perf-report perf-report
+%option 8bit nodefault yylineno
 %option noinput
 %x COMMAND HELP STRING PARAM
 %{
@@ -83,7 +83,6 @@ n	[A-Za-z0-9_-]
 
 [ \t]*#.*\n	|
 [ \t]*\n	{
-	current_file->lineno++;
 	return T_EOL;
 }
 [ \t]*#.*
@@ -104,7 +103,7 @@ n	[A-Za-z0-9_-]
 		const struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
 		BEGIN(PARAM);
 		current_pos.file = current_file;
-		current_pos.lineno = current_file->lineno;
+		current_pos.lineno = yylineno;
 		if (id && id->flags & TF_COMMAND) {
 			yylval.id = id;
 			return id->token;
@@ -116,7 +115,6 @@ n	[A-Za-z0-9_-]
 	.	warn_ignored_character(*yytext);
 	\n	{
 		BEGIN(INITIAL);
-		current_file->lineno++;
 		return T_EOL;
 	}
 }
@@ -138,7 +136,7 @@ n	[A-Za-z0-9_-]
 		new_string();
 		BEGIN(STRING);
 	}
-	\n	BEGIN(INITIAL); current_file->lineno++; return T_EOL;
+	\n	BEGIN(INITIAL); return T_EOL;
 	({n}|[/.])+	{
 		const struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
 		if (id && id->flags & TF_PARAM) {
@@ -150,7 +148,7 @@ n	[A-Za-z0-9_-]
 		return T_WORD;
 	}
 	#.*	/* comment */
-	\\\n	current_file->lineno++;
+	\\\n	;
 	[[:blank:]]+
 	.	warn_ignored_character(*yytext);
 	<<EOF>> {
@@ -187,7 +185,6 @@ n	[A-Za-z0-9_-]
 		fprintf(stderr,
 			"%s:%d:warning: multi-line strings not supported\n",
 			zconf_curname(), zconf_lineno());
-		current_file->lineno++;
 		BEGIN(INITIAL);
 		return T_EOL;
 	}
@@ -220,12 +217,10 @@ n	[A-Za-z0-9_-]
 		}
 	}
 	[ \t]*\n/[^ \t\n] {
-		current_file->lineno++;
 		zconf_endhelp();
 		return T_HELPTEXT;
 	}
 	[ \t]*\n	{
-		current_file->lineno++;
 		append_string("\n", 1);
 	}
 	[^ \t\n].* {
@@ -304,7 +299,7 @@ void zconf_initscan(const char *name)
 	memset(current_buf, 0, sizeof(*current_buf));
 
 	current_file = file_lookup(name);
-	current_file->lineno = 1;
+	yylineno = 1;
 }
 
 void zconf_nextfile(const char *name)
@@ -325,6 +320,7 @@ void zconf_nextfile(const char *name)
 	buf->parent = current_buf;
 	current_buf = buf;
 
+	current_file->lineno = yylineno;
 	file->parent = current_file;
 
 	for (iter = current_file; iter; iter = iter->parent) {
@@ -343,7 +339,7 @@ void zconf_nextfile(const char *name)
 		}
 	}
 
-	file->lineno = 1;
+	yylineno = 1;
 	current_file = file;
 }
 
@@ -352,6 +348,8 @@ static void zconf_endfile(void)
 	struct buffer *parent;
 
 	current_file = current_file->parent;
+	if (current_file)
+		yylineno = current_file->lineno;
 
 	parent = current_buf->parent;
 	if (parent) {
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/3] kconfig: remove duplicated file name and lineno of recursive inclusion
  2018-03-22 17:00 [PATCH 1/3] kconfig: remove duplicated file name and lineno of recursive inclusion Masahiro Yamada
  2018-03-22 17:00 ` [PATCH 2/3] kconfig: detect recursive inclusion earlier Masahiro Yamada
  2018-03-22 17:00 ` [PATCH 3/3] kconfig: use yylineno option instead of manual lineno increments Masahiro Yamada
@ 2018-03-26 15:24 ` Masahiro Yamada
  2 siblings, 0 replies; 6+ messages in thread
From: Masahiro Yamada @ 2018-03-26 15:24 UTC (permalink / raw)
  To: Linux Kbuild mailing list
  Cc: Michal Marek, Sam Ravnborg, Ulf Magnusson, Luis R . Rodriguez,
	Masahiro Yamada, Linux Kernel Mailing List

2018-03-23 2:00 GMT+09:00 Masahiro Yamada <yamada.masahiro@socionext.com>:
> As in the unit test, the error message for the recursive inclusion
> looks like this:
>
>   Kconfig.inc1:4: recursive inclusion detected. Inclusion path:
>     current file : 'Kconfig.inc1'
>     included from: 'Kconfig.inc3:1'
>     included from: 'Kconfig.inc2:3'
>     included from: 'Kconfig.inc1:4'
>
> The 'Kconfig.inc1:4' is duplicated in the first and last lines.
> Also, the single quotes do not help readability.
>
> Change the message like follows:
>
>   Recursive inclusion detected.
>   Inclusion path:
>     current file : Kconfig.inc1
>     included from: Kconfig.inc3:1
>     included from: Kconfig.inc2:3
>     included from: Kconfig.inc1:4
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> ---

Applied to linux-kbuild/kconfig.




-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/3] kconfig: detect recursive inclusion earlier
  2018-03-22 17:00 ` [PATCH 2/3] kconfig: detect recursive inclusion earlier Masahiro Yamada
@ 2018-03-26 15:24   ` Masahiro Yamada
  0 siblings, 0 replies; 6+ messages in thread
From: Masahiro Yamada @ 2018-03-26 15:24 UTC (permalink / raw)
  To: Linux Kbuild mailing list
  Cc: Michal Marek, Sam Ravnborg, Ulf Magnusson, Luis R . Rodriguez,
	Masahiro Yamada, Linux Kernel Mailing List

2018-03-23 2:00 GMT+09:00 Masahiro Yamada <yamada.masahiro@socionext.com>:
> Currently, the recursive inclusion is not detected when the offending
> file is about to be included; it is detected the offending file is
> about to include the *next* file.  This is because the detection loop
> does not involve the file being included.
>
> Do this check against the file that is about to be included so that
> the recursive inclusion is detected before unneeded parsing happens.
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> ---

Applied to linux-kbuild/kconfig.


-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 3/3] kconfig: use yylineno option instead of manual lineno increments
  2018-03-22 17:00 ` [PATCH 3/3] kconfig: use yylineno option instead of manual lineno increments Masahiro Yamada
@ 2018-03-26 15:25   ` Masahiro Yamada
  0 siblings, 0 replies; 6+ messages in thread
From: Masahiro Yamada @ 2018-03-26 15:25 UTC (permalink / raw)
  To: Linux Kbuild mailing list
  Cc: Michal Marek, Sam Ravnborg, Ulf Magnusson, Luis R . Rodriguez,
	Masahiro Yamada, Linux Kernel Mailing List

2018-03-23 2:00 GMT+09:00 Masahiro Yamada <yamada.masahiro@socionext.com>:
> Tracking the line number by hand is error-prone since we need to make
> sure to increment it in all the \n matching patterns.
>
> If '%option yylineno' is set, flex defines 'yylineno' to contain the
> current line number and automatically updates it each time it reads a
> \n character.  This is much more convenient although the lexer does
> not initializes yylineno, so you need to set it to 1 each time you
> start reading a new file, and restore it you go back to the previous
> file.
>
> I tested this with DEBUG_PARSE, and confirmed the same dump message
> was produced.
>
> I removed the perf-report option.  Otherwise, I see the following
> message:
>   %option yylineno entails a performance penalty ONLY on rules that
>   can match newline characters
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> ---

Applied to linux-kbuild/kconfig.



-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-03-26 15:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-22 17:00 [PATCH 1/3] kconfig: remove duplicated file name and lineno of recursive inclusion Masahiro Yamada
2018-03-22 17:00 ` [PATCH 2/3] kconfig: detect recursive inclusion earlier Masahiro Yamada
2018-03-26 15:24   ` Masahiro Yamada
2018-03-22 17:00 ` [PATCH 3/3] kconfig: use yylineno option instead of manual lineno increments Masahiro Yamada
2018-03-26 15:25   ` Masahiro Yamada
2018-03-26 15:24 ` [PATCH 1/3] kconfig: remove duplicated file name and lineno of recursive inclusion Masahiro Yamada

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).