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

Re: [PATCH] builtins + test helpers: use return instead of exit() in cmd_*

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Jun 8, 2021, 10:53 UTC
Message-ID
<87zgw039p1.fsf@evledraar.gmail.com>
In-Reply-To
<YL8S9jDmrtdKr5N+@coredump.intra.peff.net>
On Tue, Jun 08 2021, Jeff King wrote:
Show 16 quoted lines
> 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.

It does, but in this case there's no NORETURN and we declared the command to return int, and it's not the "main" function.

I believe that's what trips it up, as noted in a v2 I just submitted now: https://lore.kernel.org/git/patch-1.1-f225b78e01-20210608T104454Z-avarab@gmail.com/

It's not whining about every instance of "exit" in the codebase.
Show 27 quoted lines
>> 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. :)

I sent a few miscellaneous fixes recently for 15-20 SunCC warnings. Around 1/2 of these are legitimate issues like these, the rest are bugs in SunCC or flaws in it flow analysis or other known bugs in the compiler.

Previous: Jeff KingNext: Phillip Wood
Message 4 of 10 in “builtins + test helpers: use return instead of exit() in cmd_*”
  1. builtins + test helpers: use return instead of exit() in cmd_*Ævar Arnfjörð Bjarmason, Jun 7, 2021
  2. Felipe ContrerasJun 7, 2021
  3. Jeff KingJun 8, 2021
  4. Ævar Arnfjörð BjarmasonJun 8, 2021
  5. Phillip WoodJun 10, 2021
  6. Ævar Arnfjörð BjarmasonJun 10, 2021
  7. builtins + test helpers: use return instead of exit() in cmd_*Ævar Arnfjörð Bjarmason, Jun 8, 2021
  8. Junio C HamanoJun 8, 2021
  9. Ævar Arnfjörð BjarmasonJun 9, 2021
  10. Junio C HamanoJun 9, 2021

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.