From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: Bruce Richardson <bruce.richardson@intel.com>,
Chengwen Feng <fengchengwen@huawei.com>
Subject: [PATCH 2/3] argparse: mark parameter struct as const
Date: Mon, 16 Jun 2025 11:49:42 +0100 [thread overview]
Message-ID: <20250616104944.3425929-3-bruce.richardson@intel.com> (raw)
In-Reply-To: <20250616104944.3425929-1-bruce.richardson@intel.com>
Now that argparse no longer modifies the parameters passed in by the
user, mark them as explicitly "const" to provide that guarantee to the
user.
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
lib/argparse/rte_argparse.c | 40 ++++++++++++++++++-------------------
lib/argparse/rte_argparse.h | 2 +-
2 files changed, 21 insertions(+), 21 deletions(-)
diff --git a/lib/argparse/rte_argparse.c b/lib/argparse/rte_argparse.c
index 431d0f9b84..331f05f01d 100644
--- a/lib/argparse/rte_argparse.c
+++ b/lib/argparse/rte_argparse.c
@@ -323,10 +323,10 @@ calc_position_count(const struct rte_argparse *obj)
return count;
}
-static struct rte_argparse_arg *
-find_position_arg(struct rte_argparse *obj, uint32_t index)
+static const struct rte_argparse_arg *
+find_position_arg(const struct rte_argparse *obj, uint32_t index)
{
- struct rte_argparse_arg *arg;
+ const struct rte_argparse_arg *arg;
uint32_t count = 0;
uint32_t i;
@@ -345,7 +345,7 @@ find_position_arg(struct rte_argparse *obj, uint32_t index)
}
static bool
-is_arg_match(struct rte_argparse_arg *arg, const char *curr_argv, uint32_t len)
+is_arg_match(const struct rte_argparse_arg *arg, const char *curr_argv, uint32_t len)
{
if (strlen(arg->name_long) == len && strncmp(arg->name_long, curr_argv, len) == 0)
return true;
@@ -359,12 +359,12 @@ is_arg_match(struct rte_argparse_arg *arg, const char *curr_argv, uint32_t len)
return false;
}
-static struct rte_argparse_arg *
-find_option_arg(struct rte_argparse *obj, uint32_t *idx,
+static const struct rte_argparse_arg *
+find_option_arg(const struct rte_argparse *obj, uint32_t *idx,
const char *curr_argv, const char *has_equal, const char **arg_name)
{
uint32_t len = strlen(curr_argv) - (has_equal != NULL ? strlen(has_equal) : 0);
- struct rte_argparse_arg *arg;
+ const struct rte_argparse_arg *arg;
uint32_t i;
bool match;
@@ -385,7 +385,7 @@ find_option_arg(struct rte_argparse *obj, uint32_t *idx,
}
static int
-parse_arg_int(struct rte_argparse_arg *arg, const char *value)
+parse_arg_int(const struct rte_argparse_arg *arg, const char *value)
{
char *s = NULL;
@@ -410,7 +410,7 @@ parse_arg_int(struct rte_argparse_arg *arg, const char *value)
}
static int
-parse_arg_u8(struct rte_argparse_arg *arg, const char *value)
+parse_arg_u8(const struct rte_argparse_arg *arg, const char *value)
{
unsigned long val;
char *s = NULL;
@@ -438,7 +438,7 @@ parse_arg_u8(struct rte_argparse_arg *arg, const char *value)
}
static int
-parse_arg_u16(struct rte_argparse_arg *arg, const char *value)
+parse_arg_u16(const struct rte_argparse_arg *arg, const char *value)
{
unsigned long val;
char *s = NULL;
@@ -466,7 +466,7 @@ parse_arg_u16(struct rte_argparse_arg *arg, const char *value)
}
static int
-parse_arg_u32(struct rte_argparse_arg *arg, const char *value)
+parse_arg_u32(const struct rte_argparse_arg *arg, const char *value)
{
unsigned long val;
char *s = NULL;
@@ -494,7 +494,7 @@ parse_arg_u32(struct rte_argparse_arg *arg, const char *value)
}
static int
-parse_arg_u64(struct rte_argparse_arg *arg, const char *value)
+parse_arg_u64(const struct rte_argparse_arg *arg, const char *value)
{
unsigned long val;
char *s = NULL;
@@ -522,7 +522,7 @@ parse_arg_u64(struct rte_argparse_arg *arg, const char *value)
}
static int
-parse_arg_str(struct rte_argparse_arg *arg, const char *value)
+parse_arg_str(const struct rte_argparse_arg *arg, const char *value)
{
if (value == NULL) {
*(char **)arg->val_saver = arg->val_set;
@@ -534,7 +534,7 @@ parse_arg_str(struct rte_argparse_arg *arg, const char *value)
}
static int
-parse_arg_bool(struct rte_argparse_arg *arg, const char *value)
+parse_arg_bool(const struct rte_argparse_arg *arg, const char *value)
{
if (value == NULL) {
*(bool *)arg->val_saver = (arg->val_set != NULL);
@@ -555,7 +555,7 @@ parse_arg_bool(struct rte_argparse_arg *arg, const char *value)
}
static int
-parse_arg_autosave(struct rte_argparse_arg *arg, const char *value)
+parse_arg_autosave(const struct rte_argparse_arg *arg, const char *value)
{
switch (arg->value_type) {
case RTE_ARGPARSE_VALUE_TYPE_NONE:
@@ -582,8 +582,8 @@ parse_arg_autosave(struct rte_argparse_arg *arg, const char *value)
/* arg_parse indicates the name entered by the user, which can be long-name or short-name. */
static int
-parse_arg_val(struct rte_argparse *obj, const char *arg_name,
- struct rte_argparse_arg *arg, char *value)
+parse_arg_val(const struct rte_argparse *obj, const char *arg_name,
+ const struct rte_argparse_arg *arg, char *value)
{
int ret;
@@ -606,11 +606,11 @@ is_help(const char *curr_argv)
}
static int
-parse_args(struct rte_argparse *obj, bool *arg_parsed,
+parse_args(const struct rte_argparse *obj, bool *arg_parsed,
int argc, char **argv, bool *show_help)
{
uint32_t position_count = calc_position_count(obj);
- struct rte_argparse_arg *arg;
+ const struct rte_argparse_arg *arg;
uint32_t position_index = 0;
const char *arg_name;
uint32_t arg_idx;
@@ -795,7 +795,7 @@ show_args_help(const struct rte_argparse *obj)
RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_argparse_parse, 24.03)
int
-rte_argparse_parse(struct rte_argparse *obj, int argc, char **argv)
+rte_argparse_parse(const struct rte_argparse *obj, int argc, char **argv)
{
bool *arg_parsed = NULL;
bool show_help = false;
diff --git a/lib/argparse/rte_argparse.h b/lib/argparse/rte_argparse.h
index 3d04d47771..52bef34363 100644
--- a/lib/argparse/rte_argparse.h
+++ b/lib/argparse/rte_argparse.h
@@ -187,7 +187,7 @@ struct rte_argparse {
* Otherwise negative error code is returned.
*/
__rte_experimental
-int rte_argparse_parse(struct rte_argparse *obj, int argc, char **argv);
+int rte_argparse_parse(const struct rte_argparse *obj, int argc, char **argv);
/**
* @warning
--
2.48.1
next prev parent reply other threads:[~2025-06-16 10:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-16 10:49 [PATCH 0/3] argparse: improve handling of multi-instance args Bruce Richardson
2025-06-16 10:49 ` [PATCH 1/3] argparse: track parsed arguments internally Bruce Richardson
2025-06-16 10:49 ` Bruce Richardson [this message]
2025-06-16 10:49 ` [PATCH 3/3] test/argparse: add test for repeated arguments Bruce Richardson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250616104944.3425929-3-bruce.richardson@intel.com \
--to=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
--cc=fengchengwen@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).