git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] parse-options: adjust `parse_opt_unknown_cb()`s declared return type

From
Junio C Hamano <gitster@pobox.com>
Date
May 13, 2019, 23:29 UTC
Message-ID
<xmqqk1eu9bnf.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<dd283736b72d3e52bd298b0360ab66ffd15c1cf9.1557787395.git.gitgitgadget@gmail.com>

"Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com> writes:

Show 12 quoted lines
> From: Johannes Schindelin <johannes.schindelin@gmx.de>
>
> In f41179f16ba2 (parse-options: avoid magic return codes, 2019-01-27),
> the signature of the low-level parse-opt callback function was changed
> to return an `enum`.
>
> And while the implementations were changed, one declaration was left
> unchanged, still claiming to return `int`.
>
> This can potentially lead to problems, as compilers are free to choose
> any integral type for an `enum` as long as it can represent all declared
> values.

The enum is meant to represent "these magic negative numbers", and if the compiler chose "long" for it and the implementation of the function returned a "long", while the caller thought it would yield an "int", things will break.

Looks good to make callers' expectation and what callee does consistent.

Show 20 quoted lines
>
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
>  parse-options.h | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/parse-options.h b/parse-options.h
> index bd00cf0049..cd756833a9 100644
> --- a/parse-options.h
> +++ b/parse-options.h
> @@ -286,7 +286,9 @@ int parse_opt_commit(const struct option *, const char *, int);
>  int parse_opt_tertiary(const struct option *, const char *, int);
>  int parse_opt_string_list(const struct option *, const char *, int);
>  int parse_opt_noop_cb(const struct option *, const char *, int);
> -int parse_opt_unknown_cb(struct parse_opt_ctx_t *ctx, const struct option *, const char *, int);
> +enum parse_opt_result parse_opt_unknown_cb(struct parse_opt_ctx_t *ctx,
> +					   const struct option *,
> +					   const char *, int);
>  int parse_opt_passthru(const struct option *, const char *, int);
>  int parse_opt_passthru_argv(const struct option *, const char *, int);
Previous: Johannes Schindelin via GitGitGadget
Message 15 of 15 in “pkt-line: fix incorrect function declaration”
  1. 0/2 pkt-line: fix incorrect function declarationJohannes Schindelin via GitGitGadget, May 13, 2019
  2. 1/2 pkt-line: fix declaration of `set_packet_header()`Johannes Schindelin via GitGitGadget, May 13, 2019
  3. Junio C HamanoMay 13, 2019
  4. Johannes SchindelinMay 14, 2019
  5. Jeff KingMay 14, 2019
  6. Jeff KingMay 14, 2019
  7. Junio C HamanoMay 15, 2019
  8. Jeff KingMay 15, 2019
  9. Johannes SchindelinMay 15, 2019
  10. Junio C HamanoMay 16, 2019
  11. Jeff KingMay 16, 2019
  12. Junio C HamanoMay 16, 2019
  13. Johannes SchindelinMay 17, 2019
  14. 2/2 parse-options: adjust `parse_opt_unknown_cb()`s declared return typeJohannes Schindelin via GitGitGadget, May 13, 2019
  15. Junio C HamanoMay 13, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.