* [PATCH 1/2] kconfig: remove unneeded buffer allocation in zconf_initscan()
@ 2024-01-07 13:19 Masahiro Yamada
2024-01-07 13:19 ` [PATCH 2/2] kconfig: fix line number in recursive inclusion detection Masahiro Yamada
0 siblings, 1 reply; 2+ messages in thread
From: Masahiro Yamada @ 2024-01-07 13:19 UTC (permalink / raw)
To: linux-kbuild; +Cc: Masahiro Yamada, linux-kernel
In Kconfig, there is a stack to save the lexer state for each inclusion
level.
Currently, it operates as an empty stack, with the 'current_buf' always
pointing to an empty buffer. There is no need to preallocate the buffer.
Change it to a full stack.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---
scripts/kconfig/lexer.l | 29 +++++++++++++----------------
1 file changed, 13 insertions(+), 16 deletions(-)
diff --git a/scripts/kconfig/lexer.l b/scripts/kconfig/lexer.l
index cc386e443683..d75423ec4eae 100644
--- a/scripts/kconfig/lexer.l
+++ b/scripts/kconfig/lexer.l
@@ -391,9 +391,6 @@ void zconf_initscan(const char *name)
exit(1);
}
- current_buf = xmalloc(sizeof(*current_buf));
- memset(current_buf, 0, sizeof(*current_buf));
-
current_file = file_lookup(name);
yylineno = 1;
}
@@ -403,9 +400,10 @@ void zconf_nextfile(const char *name)
struct file *iter;
struct file *file = file_lookup(name);
struct buffer *buf = xmalloc(sizeof(*buf));
- memset(buf, 0, sizeof(*buf));
- current_buf->state = YY_CURRENT_BUFFER;
+ buf->state = YY_CURRENT_BUFFER;
+ buf->parent = current_buf;
+ current_buf = buf;
yyin = zconf_fopen(file->name);
if (!yyin) {
fprintf(stderr, "%s:%d: can't open file \"%s\"\n",
@@ -413,8 +411,6 @@ void zconf_nextfile(const char *name)
exit(1);
}
yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
- buf->parent = current_buf;
- current_buf = buf;
current_file->lineno = yylineno;
file->parent = current_file;
@@ -441,20 +437,21 @@ void zconf_nextfile(const char *name)
static void zconf_endfile(void)
{
- struct buffer *parent;
+ struct buffer *tmp;
current_file = current_file->parent;
if (current_file)
yylineno = current_file->lineno;
- parent = current_buf->parent;
- if (parent) {
- fclose(yyin);
- yy_delete_buffer(YY_CURRENT_BUFFER);
- yy_switch_to_buffer(parent->state);
- }
- free(current_buf);
- current_buf = parent;
+ if (!current_buf)
+ return;
+
+ fclose(yyin);
+ yy_delete_buffer(YY_CURRENT_BUFFER);
+ yy_switch_to_buffer(current_buf->state);
+ tmp = current_buf;
+ current_buf = current_buf->parent;
+ free(tmp);
}
int zconf_lineno(void)
--
2.40.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH 2/2] kconfig: fix line number in recursive inclusion detection
2024-01-07 13:19 [PATCH 1/2] kconfig: remove unneeded buffer allocation in zconf_initscan() Masahiro Yamada
@ 2024-01-07 13:19 ` Masahiro Yamada
0 siblings, 0 replies; 2+ messages in thread
From: Masahiro Yamada @ 2024-01-07 13:19 UTC (permalink / raw)
To: linux-kbuild; +Cc: Masahiro Yamada, linux-kernel
The error message shows a wrong line number if the 'source' directive
is wrapped to the following line.
[Test Code]
source \
"Kconfig"
This results in the following error message:
Recursive inclusion detected.
Inclusion path:
current file : Kconfig
included from: Kconfig:2
The correct message should be as follows:
Recursive inclusion detected.
Inclusion path:
current file : Kconfig
included from: Kconfig:1
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---
scripts/kconfig/lexer.l | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/scripts/kconfig/lexer.l b/scripts/kconfig/lexer.l
index d75423ec4eae..b3aeb29695d7 100644
--- a/scripts/kconfig/lexer.l
+++ b/scripts/kconfig/lexer.l
@@ -33,6 +33,7 @@ static int text_size, text_asize;
struct buffer {
struct buffer *parent;
YY_BUFFER_STATE state;
+ int lineno;
};
static struct buffer *current_buf;
@@ -402,6 +403,7 @@ void zconf_nextfile(const char *name)
struct buffer *buf = xmalloc(sizeof(*buf));
buf->state = YY_CURRENT_BUFFER;
+ buf->lineno = yylineno;
buf->parent = current_buf;
current_buf = buf;
yyin = zconf_fopen(file->name);
@@ -412,7 +414,7 @@ void zconf_nextfile(const char *name)
}
yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
- current_file->lineno = yylineno;
+ current_file->lineno = zconf_lineno();
file->parent = current_file;
for (iter = current_file; iter; iter = iter->parent) {
@@ -425,7 +427,7 @@ void zconf_nextfile(const char *name)
do {
iter = iter->parent;
fprintf(stderr, " included from: %s:%d\n",
- iter->name, iter->lineno - 1);
+ iter->name, iter->lineno);
} while (strcmp(iter->name, file->name));
exit(1);
}
@@ -440,8 +442,6 @@ static void zconf_endfile(void)
struct buffer *tmp;
current_file = current_file->parent;
- if (current_file)
- yylineno = current_file->lineno;
if (!current_buf)
return;
@@ -449,6 +449,7 @@ static void zconf_endfile(void)
fclose(yyin);
yy_delete_buffer(YY_CURRENT_BUFFER);
yy_switch_to_buffer(current_buf->state);
+ yylineno = current_buf->lineno;
tmp = current_buf;
current_buf = current_buf->parent;
free(tmp);
--
2.40.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-01-07 13:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-07 13:19 [PATCH 1/2] kconfig: remove unneeded buffer allocation in zconf_initscan() Masahiro Yamada
2024-01-07 13:19 ` [PATCH 2/2] kconfig: fix line number in recursive inclusion detection Masahiro Yamada
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox