git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH] builtins + test helpers: use return instead of exit() in cmd_*
Date: Tue, 8 Jun 2021 02:49:26 -0400	[thread overview]
Message-ID: <YL8S9jDmrtdKr5N+@coredump.intra.peff.net> (raw)
In-Reply-To: <patch-1.1-61d7e6e079-20210607T111008Z-avarab@gmail.com>

On Mon, Jun 07, 2021 at 01:12:48PM +0200, Ævar Arnfjörð Bjarmason wrote:

> Change various cmd_* functions to use "return" instead of exit() to
> indicate an exit code. On Solaris with SunCC the compiler legitimately
> complains about these, since we'll e.g. skip the cleanup (e.g. closing
> fd's, erroring if we can't) in git.c's run_builtin() when we exit()
> directly like this.

Each of these cases looks like a simple and obvious conversion, and I
certainly don't mind us doing it.

But I do wonder what SunCC is complaining about exactly. Calling exit()
means you don't have to worry about cleanup anymore. Does the compiler
not have any notion of NORETURN or equivalent? If so, I'd expect many
more complaints in general that we probably _won't_ want to silence,
because it will be awkward to do so.

> diff --git a/builtin/difftool.c b/builtin/difftool.c
> index 89334b77fb..6a9242a803 100644
> --- a/builtin/difftool.c
> +++ b/builtin/difftool.c
> @@ -675,7 +675,7 @@ static int run_file_diff(int prompt, const char *prefix,
>  		"GIT_PAGER=", "GIT_EXTERNAL_DIFF=git-difftool--helper", NULL,
>  		NULL
>  	};
> -	int ret = 0, i;
> +	int i;
>  
>  	if (prompt > 0)
>  		env[2] = "GIT_DIFFTOOL_PROMPT=true";
> @@ -686,8 +686,7 @@ static int run_file_diff(int prompt, const char *prefix,
>  	strvec_push(&args, "diff");
>  	for (i = 0; i < argc; i++)
>  		strvec_push(&args, argv[i]);
> -	ret = run_command_v_opt_cd_env(args.v, RUN_GIT_CMD, prefix, env);
> -	exit(ret);
> +	return run_command_v_opt_cd_env(args.v, RUN_GIT_CMD, prefix, env);
>  }

This one I'm not surprised that a compiler would complain about. The
function returns an int, but there are no return paths from the
function (and hence the caller doing "return run_diff_files()" likewise
could not ever return there. Which is not quite what you said it
complained about above, hence my curiosity. :)

-Peff

  parent reply	other threads:[~2021-06-08  6:49 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-07 11:12 Ævar Arnfjörð Bjarmason
2021-06-07 17:02 ` Felipe Contreras
2021-06-08  6:49 ` Jeff King [this message]
2021-06-08 10:53   ` Ævar Arnfjörð Bjarmason
2021-06-10 13:16   ` Phillip Wood
2021-06-10 13:19     ` Ævar Arnfjörð Bjarmason
2021-06-08 10:48 ` [PATCH v2] " Ævar Arnfjörð Bjarmason
2021-06-08 23:55   ` Junio C Hamano
2021-06-09  1:54     ` Ævar Arnfjörð Bjarmason
2021-06-09  3:38       ` Junio C Hamano

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=YL8S9jDmrtdKr5N+@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --subject='Re: [PATCH] builtins + test helpers: use return instead of exit() in cmd_*' \
    /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

git@vger.kernel.org list mirror (unofficial, one of many)

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 git git/ https://public-inbox.org/git \
		git@vger.kernel.org
	public-inbox-index git

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/inbox.comp.version-control.git
	nntp://ie5yzdi7fg72h7s4sdcztq5evakq23rdt33mfyfcddc5u3ndnw24ogqd.onion/inbox.comp.version-control.git
	nntp://4uok3hntl7oi7b4uf4rtfwefqeexfzil2w6kgk2jn5z2f764irre7byd.onion/inbox.comp.version-control.git
	nntp://news.gmane.io/gmane.comp.version-control.git
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git