DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] kvargs: make pointers in string arrays const
@ 2017-01-12 16:18 Bruce Richardson
  2017-01-13 17:44 ` Olivier Matz
  0 siblings, 1 reply; 3+ messages in thread
From: Bruce Richardson @ 2017-01-12 16:18 UTC (permalink / raw)
  To: olivier.matz; +Cc: dev, Bruce Richardson

Change the parameters of functions from const char *valid[] to
const char * const valid[]. This additional const is needed to
allow us to fix some checkpatch warnings, as well as being good
programming practice.

For the checkpatch warnings, if we have a set of command line
args that we want to check defined as:
	static const char *args[] = { "arg1", "arg2", NULL };
	kvlist = rte_kvargs_parse(params, args);

checkpatch will complain:
	WARNING:STATIC_CONST_CHAR_ARRAY: static const char *
	array should probably be static const char * const

Adding the additional const to the definition of the args
will then trigger a compiler error in the absense of this
change to the kvargs library, as we lose the const in the
call to kvargs_parse.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 lib/librte_kvargs/rte_kvargs.c | 8 ++++----
 lib/librte_kvargs/rte_kvargs.h | 3 ++-
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/lib/librte_kvargs/rte_kvargs.c b/lib/librte_kvargs/rte_kvargs.c
index 8d56abd..854ac83 100644
--- a/lib/librte_kvargs/rte_kvargs.c
+++ b/lib/librte_kvargs/rte_kvargs.c
@@ -92,9 +92,9 @@ rte_kvargs_tokenize(struct rte_kvargs *kvlist, const char *params)
  * into a list of valid keys.
  */
 static int
-is_valid_key(const char *valid[], const char *key_match)
+is_valid_key(const char * const valid[], const char *key_match)
 {
-	const char **valid_ptr;
+	const char * const *valid_ptr;
 
 	for (valid_ptr = valid; *valid_ptr != NULL; valid_ptr++) {
 		if (strcmp(key_match, *valid_ptr) == 0)
@@ -109,7 +109,7 @@ is_valid_key(const char *valid[], const char *key_match)
  */
 static int
 check_for_valid_keys(struct rte_kvargs *kvlist,
-		const char *valid[])
+		const char * const valid[])
 {
 	unsigned i, ret;
 	struct rte_kvargs_pair *pair;
@@ -187,7 +187,7 @@ rte_kvargs_free(struct rte_kvargs *kvlist)
  * check if only valid keys were used.
  */
 struct rte_kvargs *
-rte_kvargs_parse(const char *args, const char *valid_keys[])
+rte_kvargs_parse(const char *args, const char * const valid_keys[])
 {
 	struct rte_kvargs *kvlist;
 
diff --git a/lib/librte_kvargs/rte_kvargs.h b/lib/librte_kvargs/rte_kvargs.h
index ae9ae79..5821c72 100644
--- a/lib/librte_kvargs/rte_kvargs.h
+++ b/lib/librte_kvargs/rte_kvargs.h
@@ -97,7 +97,8 @@ struct rte_kvargs {
  *   - A pointer to an allocated rte_kvargs structure on success
  *   - NULL on error
  */
-struct rte_kvargs *rte_kvargs_parse(const char *args, const char *valid_keys[]);
+struct rte_kvargs *rte_kvargs_parse(const char *args,
+		const char *const valid_keys[]);
 
 /**
  * Free a rte_kvargs structure
-- 
2.9.3

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

* Re: [dpdk-dev] [PATCH] kvargs: make pointers in string arrays const
  2017-01-12 16:18 [dpdk-dev] [PATCH] kvargs: make pointers in string arrays const Bruce Richardson
@ 2017-01-13 17:44 ` Olivier Matz
  2017-01-13 18:29   ` Thomas Monjalon
  0 siblings, 1 reply; 3+ messages in thread
From: Olivier Matz @ 2017-01-13 17:44 UTC (permalink / raw)
  To: Bruce Richardson; +Cc: dev

On Thu, 12 Jan 2017 16:18:27 +0000, Bruce Richardson
<bruce.richardson@intel.com> wrote:
> Change the parameters of functions from const char *valid[] to
> const char * const valid[]. This additional const is needed to
> allow us to fix some checkpatch warnings, as well as being good
> programming practice.
> 
> For the checkpatch warnings, if we have a set of command line
> args that we want to check defined as:
> 	static const char *args[] = { "arg1", "arg2", NULL };
> 	kvlist = rte_kvargs_parse(params, args);
> 
> checkpatch will complain:
> 	WARNING:STATIC_CONST_CHAR_ARRAY: static const char *
> 	array should probably be static const char * const
> 
> Adding the additional const to the definition of the args
> will then trigger a compiler error in the absense of this
> change to the kvargs library, as we lose the const in the
> call to kvargs_parse.
> 
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>

Acked-by: Olivier Matz <olivier.matz@6wind.com>

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

* Re: [dpdk-dev] [PATCH] kvargs: make pointers in string arrays const
  2017-01-13 17:44 ` Olivier Matz
@ 2017-01-13 18:29   ` Thomas Monjalon
  0 siblings, 0 replies; 3+ messages in thread
From: Thomas Monjalon @ 2017-01-13 18:29 UTC (permalink / raw)
  To: Bruce Richardson; +Cc: dev, Olivier Matz

2017-01-13 18:44, Olivier Matz:
> On Thu, 12 Jan 2017 16:18:27 +0000, Bruce Richardson
> <bruce.richardson@intel.com> wrote:
> > Change the parameters of functions from const char *valid[] to
> > const char * const valid[]. This additional const is needed to
> > allow us to fix some checkpatch warnings, as well as being good
> > programming practice.
> > 
> > For the checkpatch warnings, if we have a set of command line
> > args that we want to check defined as:
> > 	static const char *args[] = { "arg1", "arg2", NULL };
> > 	kvlist = rte_kvargs_parse(params, args);
> > 
> > checkpatch will complain:
> > 	WARNING:STATIC_CONST_CHAR_ARRAY: static const char *
> > 	array should probably be static const char * const
> > 
> > Adding the additional const to the definition of the args
> > will then trigger a compiler error in the absense of this
> > change to the kvargs library, as we lose the const in the
> > call to kvargs_parse.
> > 
> > Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> 
> Acked-by: Olivier Matz <olivier.matz@6wind.com>

Applied, thanks

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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-12 16:18 [dpdk-dev] [PATCH] kvargs: make pointers in string arrays const Bruce Richardson
2017-01-13 17:44 ` Olivier Matz
2017-01-13 18:29   ` Thomas Monjalon

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).