All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/1] kconfig: expr_print(): print constant symbols within quotes
@ 2018-06-29 12:08 Dirk Gouders
  2018-06-29 12:08 ` [PATCH v3 1/1] " Dirk Gouders
  2018-06-29 13:18 ` [PATCH v4 0/1] " Dirk Gouders
  0 siblings, 2 replies; 4+ messages in thread
From: Dirk Gouders @ 2018-06-29 12:08 UTC (permalink / raw)
  To: Masahiro Yamada; +Cc: Dirk Gouders, Linux Kbuild mailing list

Hi Masahiro,

I'm sorry to have to send a v3 before you could even comment on v2.

But, I was so concentrated on the default values that I totaly missed
the remaining part of expressions to be handled consistently.

Dirk

Dirk Gouders (1):
  kconfig: expr_print(): print constant symbols within quotes

 scripts/kconfig/expr.c | 57 ++++++++++++++++++++++++++------------------------
 1 file changed, 30 insertions(+), 27 deletions(-)

-- 
2.16.1


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

* [PATCH v3 1/1] kconfig: expr_print(): print constant symbols within quotes
  2018-06-29 12:08 [PATCH v3 0/1] kconfig: expr_print(): print constant symbols within quotes Dirk Gouders
@ 2018-06-29 12:08 ` Dirk Gouders
  2018-06-29 13:18 ` [PATCH v4 0/1] " Dirk Gouders
  1 sibling, 0 replies; 4+ messages in thread
From: Dirk Gouders @ 2018-06-29 12:08 UTC (permalink / raw)
  To: Masahiro Yamada; +Cc: Dirk Gouders, Linux Kbuild mailing list

Motivation for this commit was the problem that xfwrite() uses
assert() to ensure it does not operate on empty strings.  This caused
aborts when the dependency for an empty default string was printed.

A possibility to fix this issue would be to print all string
constants in quotes which has the positive effect that empty
strings have a length of 2 and do not trigger aborts.

But currently, constant symbols are typeless, so this patch implements
a fix by identifying all constant symbols by the symbol flag
SYMBOL_CONST and printing their names within quotes.

Note:

The symbols y, m and n are statically defined as constants in symbol.c
and hence also printed within quotes.  Kconfig files contain a mixture
of those symbols specified within and without quotes and we cannot
reproduce that after parsing.

Also, the kconfig language allows for (semantically meant) constant
string, int and hex symbols to be specified within quotes or without,
which is OK as long as there is no other symbol that is something
other than the constant symbol was meant to be; the following
Kconfig file tries to illustrate this:

config a
       int "Meant to have default 5..."
       default 5

config 5
       int "but this symbol plays games."
       default "7"

This implementation reproduces exactly the described mixture from the
Kconfig files, thus original data.

Signed-off-by: Dirk Gouders <dirk@gouders.net>
---
Changes in V3: Do the described handling for all parts of expressions.
---
 scripts/kconfig/expr.c | 57 ++++++++++++++++++++++++++------------------------
 1 file changed, 30 insertions(+), 27 deletions(-)

diff --git a/scripts/kconfig/expr.c b/scripts/kconfig/expr.c
index e1a39e90841d..380e98ef4de8 100644
--- a/scripts/kconfig/expr.c
+++ b/scripts/kconfig/expr.c
@@ -1137,10 +1137,28 @@ static int expr_compare_type(enum expr_type t1, enum expr_type t2)
 	return 0;
 }
 
+static void sym_print_name(void (*fn)(void *, struct symbol *, const char *),
+			   void *data, struct symbol *sym) {
+	const char *quoted;
+
+	if (sym->name)
+		/*
+		 * Print constant symbols within quotes
+		 */
+		if (sym->flags & SYMBOL_CONST) {
+			quoted = sym_escape_string_value(sym->name);
+			fn(data, sym, quoted);
+			free((void*)quoted);
+		} else
+			fn(data, sym, sym->name);
+	else
+		fn(data, NULL, "<choice>");
+}
 void expr_print(struct expr *e,
 		void (*fn)(void *, struct symbol *, const char *),
 		void *data, int prevtoken)
 {
+
 	if (!e) {
 		fn(data, NULL, "y");
 		return;
@@ -1150,48 +1168,33 @@ void expr_print(struct expr *e,
 		fn(data, NULL, "(");
 	switch (e->type) {
 	case E_SYMBOL:
-		if (e->left.sym->name)
-			fn(data, e->left.sym, e->left.sym->name);
-		else
-			fn(data, NULL, "<choice>");
+		sym_print_name(fn, data, e->left.sym);
 		break;
 	case E_NOT:
 		fn(data, NULL, "!");
 		expr_print(e->left.expr, fn, data, E_NOT);
 		break;
 	case E_EQUAL:
-		if (e->left.sym->name)
-			fn(data, e->left.sym, e->left.sym->name);
-		else
-			fn(data, NULL, "<choice>");
+		sym_print_name(fn, data, e->left.sym);
 		fn(data, NULL, "=");
-		fn(data, e->right.sym, e->right.sym->name);
+		sym_print_name(fn, data, e->right.sym);
 		break;
 	case E_LEQ:
 	case E_LTH:
-		if (e->left.sym->name)
-			fn(data, e->left.sym, e->left.sym->name);
-		else
-			fn(data, NULL, "<choice>");
+		sym_print_name(fn, data, e->left.sym);
 		fn(data, NULL, e->type == E_LEQ ? "<=" : "<");
-		fn(data, e->right.sym, e->right.sym->name);
+		sym_print_name(fn, data, e->right.sym);
 		break;
 	case E_GEQ:
 	case E_GTH:
-		if (e->left.sym->name)
-			fn(data, e->left.sym, e->left.sym->name);
-		else
-			fn(data, NULL, "<choice>");
+		sym_print_name(fn, data, e->left.sym);
 		fn(data, NULL, e->type == E_GEQ ? ">=" : ">");
-		fn(data, e->right.sym, e->right.sym->name);
+		sym_print_name(fn, data, e->right.sym);
 		break;
 	case E_UNEQUAL:
-		if (e->left.sym->name)
-			fn(data, e->left.sym, e->left.sym->name);
-		else
-			fn(data, NULL, "<choice>");
+		sym_print_name(fn, data, e->left.sym);
 		fn(data, NULL, "!=");
-		fn(data, e->right.sym, e->right.sym->name);
+		sym_print_name(fn, data, e->right.sym);
 		break;
 	case E_OR:
 		expr_print(e->left.expr, fn, data, E_OR);
@@ -1204,7 +1207,7 @@ void expr_print(struct expr *e,
 		expr_print(e->right.expr, fn, data, E_AND);
 		break;
 	case E_LIST:
-		fn(data, e->right.sym, e->right.sym->name);
+		sym_print_name(fn, data, e->right.sym);
 		if (e->left.expr) {
 			fn(data, NULL, " ^ ");
 			expr_print(e->left.expr, fn, data, E_LIST);
@@ -1212,9 +1215,9 @@ void expr_print(struct expr *e,
 		break;
 	case E_RANGE:
 		fn(data, NULL, "[");
-		fn(data, e->left.sym, e->left.sym->name);
+		sym_print_name(fn, data, e->left.sym);
 		fn(data, NULL, " ");
-		fn(data, e->right.sym, e->right.sym->name);
+		sym_print_name(fn, data, e->right.sym);
 		fn(data, NULL, "]");
 		break;
 	default:
-- 
2.16.1


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

* [PATCH v4 0/1] kconfig: expr_print(): print constant symbols within quotes
  2018-06-29 12:08 [PATCH v3 0/1] kconfig: expr_print(): print constant symbols within quotes Dirk Gouders
  2018-06-29 12:08 ` [PATCH v3 1/1] " Dirk Gouders
@ 2018-06-29 13:18 ` Dirk Gouders
  2018-06-29 13:18   ` [PATCH v4 1/1] " Dirk Gouders
  1 sibling, 1 reply; 4+ messages in thread
From: Dirk Gouders @ 2018-06-29 13:18 UTC (permalink / raw)
  To: Masahiro Yamada; +Cc: Dirk Gouders, Linux Kbuild mailing list

Hi Masahiro,

somehow, I expect you will ask to print y,m and n without quotes to stay
consistend with the current behavior.  I have to confess in mconf, for
example that looks more consistent, whereas with zconfdump() I like
the quotes more...

For that case, I created a v4 that prints constants within quotes,
except y,m and n.

Dirk

Dirk Gouders (1):
  kconfig: expr_print(): print constant symbols within quotes

 scripts/kconfig/expr.c | 60 +++++++++++++++++++++++++++-----------------------
 1 file changed, 33 insertions(+), 27 deletions(-)

-- 
2.16.1


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

* [PATCH v4 1/1] kconfig: expr_print(): print constant symbols within quotes
  2018-06-29 13:18 ` [PATCH v4 0/1] " Dirk Gouders
@ 2018-06-29 13:18   ` Dirk Gouders
  0 siblings, 0 replies; 4+ messages in thread
From: Dirk Gouders @ 2018-06-29 13:18 UTC (permalink / raw)
  To: Masahiro Yamada; +Cc: Dirk Gouders, Linux Kbuild mailing list

Motivation for this commit was the problem that xfwrite() uses
assert() to ensure it does not operate on empty strings.  This caused
aborts when the dependency for an empty default string was printed.

A possibility to fix this issue would be to print all string
constants in quotes which has the positive effect that empty
strings have a length of 2 and do not trigger aborts.

But currently, constant symbols are typeless, so this patch implements
a fix by identifying all constant symbols by the symbol flag
SYMBOL_CONST and printing their names within quotes.

Note:

The symbols y, m and n are statically defined as constants in symbol.c
but still printed without quotes.  Kconfig files contain a mixture
of those symbols specified within and without quotes and we cannot
reproduce that after parsing, so we keep the known behaviour.

Further, the kconfig language allows for (semantically meant) constant
string, int and hex symbols to be specified within quotes or without,
which is OK as long as there is no other symbol that is something
other than the constant symbol was meant to be; the following
Kconfig file tries to illustrate this:

config a
       int "Meant to have default 5..."
       default 5

config 5
       int "but this symbol plays games."
       default "7"

This implementation reproduces exactly the described mixture from the
Kconfig files, thus original data.

Signed-off-by: Dirk Gouders <dirk@gouders.net>
---
 scripts/kconfig/expr.c | 60 +++++++++++++++++++++++++++-----------------------
 1 file changed, 33 insertions(+), 27 deletions(-)

diff --git a/scripts/kconfig/expr.c b/scripts/kconfig/expr.c
index e1a39e90841d..b5424aca140c 100644
--- a/scripts/kconfig/expr.c
+++ b/scripts/kconfig/expr.c
@@ -1137,6 +1137,27 @@ static int expr_compare_type(enum expr_type t1, enum expr_type t2)
 	return 0;
 }
 
+static void sym_print_name(void (*fn)(void *, struct symbol *, const char *),
+			   void *data, struct symbol *sym) {
+	const char *quoted;
+
+	if (sym->name)
+		if (!(sym->flags & SYMBOL_CONST) ||
+		    sym == &symbol_yes ||
+		    sym == &symbol_mod ||
+		    sym == &symbol_no)
+			fn(data, sym, sym->name);
+		else {
+			/*
+			 * Print constant symbols within quotes
+			 */
+			quoted = sym_escape_string_value(sym->name);
+			fn(data, sym, quoted);
+			free((void*)quoted);
+		}
+	else
+		fn(data, NULL, "<choice>");
+}
 void expr_print(struct expr *e,
 		void (*fn)(void *, struct symbol *, const char *),
 		void *data, int prevtoken)
@@ -1150,48 +1171,33 @@ void expr_print(struct expr *e,
 		fn(data, NULL, "(");
 	switch (e->type) {
 	case E_SYMBOL:
-		if (e->left.sym->name)
-			fn(data, e->left.sym, e->left.sym->name);
-		else
-			fn(data, NULL, "<choice>");
+		sym_print_name(fn, data, e->left.sym);
 		break;
 	case E_NOT:
 		fn(data, NULL, "!");
 		expr_print(e->left.expr, fn, data, E_NOT);
 		break;
 	case E_EQUAL:
-		if (e->left.sym->name)
-			fn(data, e->left.sym, e->left.sym->name);
-		else
-			fn(data, NULL, "<choice>");
+		sym_print_name(fn, data, e->left.sym);
 		fn(data, NULL, "=");
-		fn(data, e->right.sym, e->right.sym->name);
+		sym_print_name(fn, data, e->right.sym);
 		break;
 	case E_LEQ:
 	case E_LTH:
-		if (e->left.sym->name)
-			fn(data, e->left.sym, e->left.sym->name);
-		else
-			fn(data, NULL, "<choice>");
+		sym_print_name(fn, data, e->left.sym);
 		fn(data, NULL, e->type == E_LEQ ? "<=" : "<");
-		fn(data, e->right.sym, e->right.sym->name);
+		sym_print_name(fn, data, e->right.sym);
 		break;
 	case E_GEQ:
 	case E_GTH:
-		if (e->left.sym->name)
-			fn(data, e->left.sym, e->left.sym->name);
-		else
-			fn(data, NULL, "<choice>");
+		sym_print_name(fn, data, e->left.sym);
 		fn(data, NULL, e->type == E_GEQ ? ">=" : ">");
-		fn(data, e->right.sym, e->right.sym->name);
+		sym_print_name(fn, data, e->right.sym);
 		break;
 	case E_UNEQUAL:
-		if (e->left.sym->name)
-			fn(data, e->left.sym, e->left.sym->name);
-		else
-			fn(data, NULL, "<choice>");
+		sym_print_name(fn, data, e->left.sym);
 		fn(data, NULL, "!=");
-		fn(data, e->right.sym, e->right.sym->name);
+		sym_print_name(fn, data, e->right.sym);
 		break;
 	case E_OR:
 		expr_print(e->left.expr, fn, data, E_OR);
@@ -1204,7 +1210,7 @@ void expr_print(struct expr *e,
 		expr_print(e->right.expr, fn, data, E_AND);
 		break;
 	case E_LIST:
-		fn(data, e->right.sym, e->right.sym->name);
+		sym_print_name(fn, data, e->right.sym);
 		if (e->left.expr) {
 			fn(data, NULL, " ^ ");
 			expr_print(e->left.expr, fn, data, E_LIST);
@@ -1212,9 +1218,9 @@ void expr_print(struct expr *e,
 		break;
 	case E_RANGE:
 		fn(data, NULL, "[");
-		fn(data, e->left.sym, e->left.sym->name);
+		sym_print_name(fn, data, e->left.sym);
 		fn(data, NULL, " ");
-		fn(data, e->right.sym, e->right.sym->name);
+		sym_print_name(fn, data, e->right.sym);
 		fn(data, NULL, "]");
 		break;
 	default:
-- 
2.16.1


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

end of thread, other threads:[~2018-06-29 13:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-29 12:08 [PATCH v3 0/1] kconfig: expr_print(): print constant symbols within quotes Dirk Gouders
2018-06-29 12:08 ` [PATCH v3 1/1] " Dirk Gouders
2018-06-29 13:18 ` [PATCH v4 0/1] " Dirk Gouders
2018-06-29 13:18   ` [PATCH v4 1/1] " Dirk Gouders

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.