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

[PATCH] run-command.c: fix missing include under `NO_PTHREADS`

From
Taylor Blau <me@ttaylorr.com>
Date
May 16, 2023, 17:56 UTC
Message-ID
<db403de74da839084165f11dab05d71484457c6f.1684259780.git.me@ttaylorr.com>
In-Reply-To
<ZGO4LesPe4A2ftdm@nand.local>

When building git with `NO_PTHREADS=YesPlease`, we fail to build run-command.o since we don't have a definition for ALLOC_GROW:

    $ make NO_PTHREADS=1 DEVELOPER=1 run-command.o
    GIT_VERSION = 2.41.0.rc0.1.g787eb3beae.dirty
        CC run-command.o
    run-command.c: In function ‘git_atexit’:
    run-command.c:1103:9: error: implicit declaration of function ‘ALLOC_GROW’ [-Werror=implicit-function-declaration]
     1103 |         ALLOC_GROW(git_atexit_hdlrs.handlers, git_atexit_hdlrs.nr + 1, git_atexit_hdlrs.alloc);
          |         ^~~~~~~~~~
    cc1: all warnings being treated as errors
    make: *** [Makefile:2715: run-command.o] Error 1

This bisects to 36bf195890 (alloc.h: move ALLOC_GROW() functions from cache.h, 2023-02-24), which replaced includes of "cache.h" with "alloc.h", which is the new home of `ALLOC_GROW()` (and `ALLOC_GROW_BY()`).

run-command.c compiles fine when `NO_PTHREADS` is undefined, since its use of `ALLOC_GROW()` is behind a `#ifndef NO_PTHREADS`. (Everything else compiles fine when NO_PTHREADS is defined, so this is the only spot that needs fixing).

We could fix this by conditionally including "alloc.h" when `NO_PTHREADS` is defined. But we have relatively few examples of conditional includes throughout the tree[^1].

Instead, include "alloc.h" unconditionally in run-command.c to allow it to successfully compile even when NO_PTHREADS is defined.

[^1]: With `git grep -E -A1 '#if(n)?def' -- **/*.c | grep '#include' -B1`.
Reported-by: Randall S. Becker <randall.becker@nexbridge.ca>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
 run-command.c | 1 +
 1 file changed, 1 insertion(+)
diff --git a/run-command.c b/run-command.c
index d4247d5fcc..60c9419866 100644
--- a/run-command.c
+++ b/run-command.c
@@ -16,6 +16,7 @@
 #include "packfile.h"
 #include "hook.h"
 #include "compat/nonblock.h"
+#include "alloc.h"
 
 void child_process_init(struct child_process *child)
 {
-- 
2.41.0.rc0.dirty
Previous: Junio C HamanoNext: Junio C Hamano
Message 11 of 15 in “[BUG] Git 2.41.0-rc0 - Compile Error ALLOC_GROW”
  1. rsbecker@nexbridge.comMay 16, 2023
  2. Taylor BlauMay 16, 2023
  3. Junio C HamanoMay 16, 2023
  4. run-command.c: need alloc.h for our own at-exit handler emulationJunio C Hamano, May 16, 2023
  5. rsbecker@nexbridge.comMay 16, 2023
  6. Taylor BlauMay 16, 2023
  7. Taylor BlauMay 16, 2023
  8. Junio C HamanoMay 16, 2023
  9. Taylor BlauMay 16, 2023
  10. Junio C HamanoMay 16, 2023
  11. run-command.c: fix missing include under `NO_PTHREADS`Taylor Blau, May 16, 2023
  12. Junio C HamanoMay 16, 2023
  13. rsbecker@nexbridge.comMay 16, 2023
  14. Taylor BlauMay 16, 2023
  15. Elijah NewrenMay 18, 2023

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.