Subject: Re: [PATCH v2 2/7] parse-options: add precision handling for PARSE_OPT_CMDMODE

From: Patrick Steinhardt <[email-masked]>
Date: Wed, 9 Jul 2025 15:58:52 +0200

On Wed, Jul 09, 2025 at 11:45:14AM +0200, René Scharfe wrote:
> Build on 09705696f7 (parse-options: introduce precision handling for
> `OPTION_INTEGER`, 2025-04-17) to support value variables of different
> sizes for PARSE_OPT_CMDMODE options.  Do that by requiring their
> "precision" to be set and casting their "value" pointer accordingly.
> 
> Call the function that does the raw casting do_get_int_value() to
> reserve the name get_int_value() for a more friendly wrapper we're
> going to introduce in one of the next patches.
> 
> Signed-off-by: René Scharfe <[email-masked]>
> ---
>  builtin/am.c                  |  1 +
>  parse-options.c               | 41 ++++++++++++++++++++++++++++++-----
>  parse-options.h               |  1 +
>  t/helper/test-parse-options.c | 13 ++++++++---
>  4 files changed, 48 insertions(+), 8 deletions(-)
> 
> diff --git a/builtin/am.c b/builtin/am.c
> index a800003340..c9d925f7b9 100644
> --- a/builtin/am.c
> +++ b/builtin/am.c
> @@ -2406,6 +2406,7 @@ int cmd_am(int argc,
>  			.type = OPTION_CALLBACK,
>  			.long_name = "show-current-patch",
>  			.value = &resume_mode,
> +			.precision = sizeof(resume_mode),
>  			.argh = "(diff|raw)",
>  			.help = N_("show the patch being applied"),
>  			.flags = PARSE_OPT_CMDMODE | PARSE_OPT_OPTARG | PARSE_OPT_NONEG | PARSE_OPT_LITERAL_ARGHELP,
> diff --git a/parse-options.c b/parse-options.c
> index 68ff494492..ddac008a5e 100644
> --- a/parse-options.c
> +++ b/parse-options.c
> @@ -68,6 +68,26 @@ static char *fix_filename(const char *prefix, const char *file)
>  		return prefix_filename_except_for_dash(prefix, file);
>  }
>  
> +static int do_get_int_value(const void *value, size_t precision, intmax_t *ret)

Nit: after the fourth patch we have `do_get_int_value()` and
`get_int_value()`, where the major difference is that the latter dies if
we failed to parse the value. It might be easier to discern which is
which if we called them `get_int_value()` and `get_int_value_or_die()`.

Patrick