From: Junio C Hamano <gitster@pobox.com>
To: "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: Re: [PATCH 2/2] parse-options: adjust `parse_opt_unknown_cb()`s declared return type
Date: Tue, 14 May 2019 08:29:08 +0900 [thread overview]
Message-ID: <xmqqk1eu9bnf.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <dd283736b72d3e52bd298b0360ab66ffd15c1cf9.1557787395.git.gitgitgadget@gmail.com> (Johannes Schindelin via GitGitGadget's message of "Mon, 13 May 2019 15:43:17 -0700 (PDT)")
"Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
writes:
> 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.
>
> 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);
prev parent reply other threads:[~2019-05-13 23:29 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-13 22:43 [PATCH 0/2] pkt-line: fix incorrect function declaration Johannes Schindelin via GitGitGadget
2019-05-13 22:43 ` [PATCH 1/2] pkt-line: fix declaration of `set_packet_header()` Johannes Schindelin via GitGitGadget
2019-05-13 23:24 ` Junio C Hamano
2019-05-14 12:57 ` Johannes Schindelin
2019-05-14 14:43 ` Jeff King
2019-05-14 14:44 ` Jeff King
2019-05-15 1:42 ` Junio C Hamano
2019-05-15 1:44 ` Jeff King
2019-05-15 10:39 ` Johannes Schindelin
2019-05-16 2:24 ` Junio C Hamano
2019-05-16 3:42 ` Jeff King
2019-05-16 4:28 ` Junio C Hamano
2019-05-17 18:54 ` Johannes Schindelin
2019-05-13 22:43 ` [PATCH 2/2] parse-options: adjust `parse_opt_unknown_cb()`s declared return type Johannes Schindelin via GitGitGadget
2019-05-13 23:29 ` Junio C Hamano [this message]
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqk1eu9bnf.fsf@gitster-ct.c.googlers.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=johannes.schindelin@gmx.de \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).