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

Re: [PATCH] Correctly initialize 'installed_handlers'

From
Junio C Hamano <gitster@pobox.com>
Date
May 8, 2020, 15:36 UTC
Message-ID
<xmqqy2q2zbej.fsf@gitster.c.googlers.com>
In-Reply-To
<20200508083340.GA36538@Carlos-MBP>
Carlo Marcelo Arenas Belón <carenas@gmail.com> writes:
Show 7 quoted lines
> the way this is handled would seem to indicate otherwise
>
> if (!installed_handlers) {
>                 atexit(remove_tmp_objdir);
>                 sigchain_push_common(remove_tmp_objdir_on_signal);
>                 installed_handlers++;
> }
It is a curious piece of code.  

The "prepare a file-scope static and do something and increment it when it is 0" pattern expects the function to be called many times and do the guarded thing only once. However, there is this code:

	if (the_tmp_objdir)
		BUG(...);

before we do anything else, and then before that "arrange to clean up, but do so just once" block, there is

	the_tmp_objdir = t;

where t is the pointer to a "struct tmp_objdir" instance. So one part of the function expects to be called at most once, while another part is prepared to be called more than once.

Almost all of this function is attributed to 2564d994 (tmp-objdir: introduce API for temporary object directories, 2016-10-03), so let's see if Peff remembers anything about this curiosity.

Thanks.
Previous: Carlo Marcelo Arenas BelónNext: Jeff King
Message 3 of 4 in “Correctly initialize 'installed_handlers'”
  1. Correctly initialize 'installed_handlers'Force Charlie via GitGitGadget, May 8, 2020
  2. Carlo Marcelo Arenas BelónMay 8, 2020
  3. Junio C HamanoMay 8, 2020
  4. Jeff KingMay 8, 2020

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.