mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/6] commands: allow <cmd>_aliases[] to be const
@ 2017-05-17 13:24 Ian Abbott
  2017-05-17 13:24 ` [PATCH 2/6] hush: make source_aliases[] const Ian Abbott
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Ian Abbott @ 2017-05-17 13:24 UTC (permalink / raw)
  To: barebox; +Cc: Ian Abbott

Commands with aliases define an array of alias strings such as:

  static const char *<cmd>_aliases[] = { "<alias1>", NULL};

Although the elements are of type `const char *`, the elements
themselves are not `const`-qualified.  If the array is declared as:

  static const char * const <cmd>_aliases[] = { "<alias1>", NULL};

then the compiler warns about const qualifiers being discarded.  This is
because the `aliases` member of `struct command` is declared as `const
char *aliases;`.

Change the declaration of the `aliases` member of `struct command` to
`const char * const *aliases;` so that it can point to a `const` array
of `const char *`.  Also change the declaration of the `aliases`
variable in `register_command()` to avoid unnecessary type casts.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
---
 common/command.c  | 2 +-
 include/command.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/common/command.c b/common/command.c
index 03c70834d..d9cc4a6d4 100644
--- a/common/command.c
+++ b/common/command.c
@@ -104,7 +104,7 @@ int register_command(struct command *cmd)
 	list_add_sort(&cmd->list, &command_list, compare);
 
 	if (cmd->aliases) {
-		char **aliases = (char**)cmd->aliases;
+		const char * const *aliases = cmd->aliases;
 		while(*aliases) {
 			struct command *c = xzalloc(sizeof(struct command));
 
diff --git a/include/command.h b/include/command.h
index 43ee454f2..0afc5c755 100644
--- a/include/command.h
+++ b/include/command.h
@@ -40,7 +40,7 @@ struct string_list;
  */
 struct command {
 	const char	*name;		/* Command Name			*/
-	const char	**aliases;
+	const char	* const *aliases;
 					/* Implementation function	*/
 	int		(*cmd)(int, char *[]);
 	int		(*complete)(struct string_list *sl, char *instr);
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 2/6] hush: make source_aliases[] const
  2017-05-17 13:24 [PATCH 1/6] commands: allow <cmd>_aliases[] to be const Ian Abbott
@ 2017-05-17 13:24 ` Ian Abbott
  2017-05-17 13:24 ` [PATCH 3/6] edit: make edit_aliases[] const Ian Abbott
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Ian Abbott @ 2017-05-17 13:24 UTC (permalink / raw)
  To: barebox; +Cc: Ian Abbott

Although the elements of `source_aliases[]` are of type `const char *`,
the elements themselves are not const-qualified.  Make them `const`.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
---
 common/hush.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/hush.c b/common/hush.c
index d3f7bf330..792b61ac9 100644
--- a/common/hush.c
+++ b/common/hush.c
@@ -1974,7 +1974,7 @@ static int do_source(int argc, char *argv[])
 	return ret;
 }
 
-static const char *source_aliases[] = { ".", NULL};
+static const char * const source_aliases[] = { ".", NULL};
 
 BAREBOX_CMD_HELP_START(source)
 BAREBOX_CMD_HELP_TEXT("Read and execute commands from FILE in the current shell environment.")
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 3/6] edit: make edit_aliases[] const
  2017-05-17 13:24 [PATCH 1/6] commands: allow <cmd>_aliases[] to be const Ian Abbott
  2017-05-17 13:24 ` [PATCH 2/6] hush: make source_aliases[] const Ian Abbott
@ 2017-05-17 13:24 ` Ian Abbott
  2017-05-17 13:24 ` [PATCH 4/6] help: make help_aliases[] const Ian Abbott
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Ian Abbott @ 2017-05-17 13:24 UTC (permalink / raw)
  To: barebox; +Cc: Ian Abbott

Although the elements of `edit_aliases[]` are of type `const char *`,
the elements themselves are not const-qualified.  Make them `const`.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
---
 commands/edit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/commands/edit.c b/commands/edit.c
index 696a818d9..290222ce1 100644
--- a/commands/edit.c
+++ b/commands/edit.c
@@ -559,7 +559,7 @@ out:
 	return ret;
 }
 
-static const char *edit_aliases[] = { "sedit", NULL};
+static const char * const edit_aliases[] = { "sedit", NULL};
 
 BAREBOX_CMD_HELP_START(edit)
 BAREBOX_CMD_HELP_TEXT("Use cursor keys, Ctrl-C to exit and Ctrl-D to exit-with-save.")
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 4/6] help: make help_aliases[] const
  2017-05-17 13:24 [PATCH 1/6] commands: allow <cmd>_aliases[] to be const Ian Abbott
  2017-05-17 13:24 ` [PATCH 2/6] hush: make source_aliases[] const Ian Abbott
  2017-05-17 13:24 ` [PATCH 3/6] edit: make edit_aliases[] const Ian Abbott
@ 2017-05-17 13:24 ` Ian Abbott
  2017-05-17 13:24 ` [PATCH 5/6] test: make test_aliases[] const Ian Abbott
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Ian Abbott @ 2017-05-17 13:24 UTC (permalink / raw)
  To: barebox; +Cc: Ian Abbott

Although the elements of `help_aliases[]` are of type `const char *`,
the elements themselves are not const-qualified.  Make them `const`.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
---
 commands/help.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/commands/help.c b/commands/help.c
index 819c40653..34ffa9a41 100644
--- a/commands/help.c
+++ b/commands/help.c
@@ -139,7 +139,7 @@ BAREBOX_CMD_HELP_OPT ("-a", "output help on all commands")
 BAREBOX_CMD_HELP_OPT ("-v", "verbose")
 BAREBOX_CMD_HELP_END
 
-static const char *help_aliases[] = { "?", NULL};
+static const char * const help_aliases[] = { "?", NULL};
 
 BAREBOX_CMD_START(help)
 	.cmd		= do_help,
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 5/6] test: make test_aliases[] const
  2017-05-17 13:24 [PATCH 1/6] commands: allow <cmd>_aliases[] to be const Ian Abbott
                   ` (2 preceding siblings ...)
  2017-05-17 13:24 ` [PATCH 4/6] help: make help_aliases[] const Ian Abbott
@ 2017-05-17 13:24 ` Ian Abbott
  2017-05-17 13:24 ` [PATCH 6/6] true: make true_aliases[] const Ian Abbott
  2017-05-19  5:13 ` [PATCH 1/6] commands: allow <cmd>_aliases[] to be const Sascha Hauer
  5 siblings, 0 replies; 7+ messages in thread
From: Ian Abbott @ 2017-05-17 13:24 UTC (permalink / raw)
  To: barebox; +Cc: Ian Abbott

Although the elements of `test_aliases[]` are of type `const char *`,
the elements themselves are not const-qualified.  Make them `const`.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
---
 commands/test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/commands/test.c b/commands/test.c
index d0f63c139..c4f493860 100644
--- a/commands/test.c
+++ b/commands/test.c
@@ -224,7 +224,7 @@ out:
 	return expr;
 }
 
-static const char *test_aliases[] = { "[", NULL};
+static const char * const test_aliases[] = { "[", NULL};
 
 BAREBOX_CMD_HELP_START(test)
 BAREBOX_CMD_HELP_TEXT("Options:")
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 6/6] true: make true_aliases[] const
  2017-05-17 13:24 [PATCH 1/6] commands: allow <cmd>_aliases[] to be const Ian Abbott
                   ` (3 preceding siblings ...)
  2017-05-17 13:24 ` [PATCH 5/6] test: make test_aliases[] const Ian Abbott
@ 2017-05-17 13:24 ` Ian Abbott
  2017-05-19  5:13 ` [PATCH 1/6] commands: allow <cmd>_aliases[] to be const Sascha Hauer
  5 siblings, 0 replies; 7+ messages in thread
From: Ian Abbott @ 2017-05-17 13:24 UTC (permalink / raw)
  To: barebox; +Cc: Ian Abbott

Although the elements of `true_aliases[]` are of type `const char *`,
the elements themselves are not const-qualified.  Make them `const`.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
---
Note: This depends on my patch "commands: add ':' as alias for 'true'".
---
 commands/true.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/commands/true.c b/commands/true.c
index b850f5165..ad2be8e8e 100644
--- a/commands/true.c
+++ b/commands/true.c
@@ -26,7 +26,7 @@ static int do_true(int argc, char *argv[])
 	return 0;
 }
 
-static const char *true_aliases[] = { ":", NULL};
+static const char * const true_aliases[] = { ":", NULL};
 
 BAREBOX_CMD_START(true)
 	.aliases	= true_aliases,
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 1/6] commands: allow <cmd>_aliases[] to be const
  2017-05-17 13:24 [PATCH 1/6] commands: allow <cmd>_aliases[] to be const Ian Abbott
                   ` (4 preceding siblings ...)
  2017-05-17 13:24 ` [PATCH 6/6] true: make true_aliases[] const Ian Abbott
@ 2017-05-19  5:13 ` Sascha Hauer
  5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2017-05-19  5:13 UTC (permalink / raw)
  To: Ian Abbott; +Cc: barebox

On Wed, May 17, 2017 at 02:24:21PM +0100, Ian Abbott wrote:
> Commands with aliases define an array of alias strings such as:
> 
>   static const char *<cmd>_aliases[] = { "<alias1>", NULL};
> 
> Although the elements are of type `const char *`, the elements
> themselves are not `const`-qualified.  If the array is declared as:
> 
>   static const char * const <cmd>_aliases[] = { "<alias1>", NULL};
> 
> then the compiler warns about const qualifiers being discarded.  This is
> because the `aliases` member of `struct command` is declared as `const
> char *aliases;`.
> 
> Change the declaration of the `aliases` member of `struct command` to
> `const char * const *aliases;` so that it can point to a `const` array
> of `const char *`.  Also change the declaration of the `aliases`
> variable in `register_command()` to avoid unnecessary type casts.
> 
> Signed-off-by: Ian Abbott <abbotti@mev.co.uk>

Applied, thanks

Sascha

> ---
>  common/command.c  | 2 +-
>  include/command.h | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/common/command.c b/common/command.c
> index 03c70834d..d9cc4a6d4 100644
> --- a/common/command.c
> +++ b/common/command.c
> @@ -104,7 +104,7 @@ int register_command(struct command *cmd)
>  	list_add_sort(&cmd->list, &command_list, compare);
>  
>  	if (cmd->aliases) {
> -		char **aliases = (char**)cmd->aliases;
> +		const char * const *aliases = cmd->aliases;
>  		while(*aliases) {
>  			struct command *c = xzalloc(sizeof(struct command));
>  
> diff --git a/include/command.h b/include/command.h
> index 43ee454f2..0afc5c755 100644
> --- a/include/command.h
> +++ b/include/command.h
> @@ -40,7 +40,7 @@ struct string_list;
>   */
>  struct command {
>  	const char	*name;		/* Command Name			*/
> -	const char	**aliases;
> +	const char	* const *aliases;
>  					/* Implementation function	*/
>  	int		(*cmd)(int, char *[]);
>  	int		(*complete)(struct string_list *sl, char *instr);
> -- 
> 2.11.0
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2017-05-19  5:14 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-17 13:24 [PATCH 1/6] commands: allow <cmd>_aliases[] to be const Ian Abbott
2017-05-17 13:24 ` [PATCH 2/6] hush: make source_aliases[] const Ian Abbott
2017-05-17 13:24 ` [PATCH 3/6] edit: make edit_aliases[] const Ian Abbott
2017-05-17 13:24 ` [PATCH 4/6] help: make help_aliases[] const Ian Abbott
2017-05-17 13:24 ` [PATCH 5/6] test: make test_aliases[] const Ian Abbott
2017-05-17 13:24 ` [PATCH 6/6] true: make true_aliases[] const Ian Abbott
2017-05-19  5:13 ` [PATCH 1/6] commands: allow <cmd>_aliases[] to be const Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox