[PATCH] git-compat-util.h: Fix build without threads

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Fabrice Fontaine <fontaine.fabrice@xxxxxxxxx>

Git build with toolchains without threads support is broken (as reported
by Buildroot autobuilder [1]) since version 2.29.0, which traces back to
15b52a44e0 (compat-util: type-check parameters of no-op replacement
functions, 2020-08-06):

In file included from cache.h:4,
                 from blame.c:1:
git-compat-util.h:1238:20: error: static declaration of 'flockfile' follows non-static declaration
 static inline void flockfile(FILE *fh)
                    ^~~~~~~~~
In file included from git-compat-util.h:168,
                 from cache.h:4,
                 from blame.c:1:
/nvme/rc-buildroot-test/scripts/instance-0/output-1/host/arm-buildroot-linux-uclibcgnueabihf/sysroot/usr/include/stdio.h:806:13: note: previous declaration of 'flockfile' was here
 extern void flockfile (FILE *__stream) __THROW;
             ^~~~~~~~~
In file included from cache.h:4,
                 from blame.c:1:
git-compat-util.h:1242:20: error: static declaration of 'funlockfile' follows non-static declaration
 static inline void funlockfile(FILE *fh)
                    ^~~~~~~~~~~
In file included from git-compat-util.h:168,
                 from cache.h:4,
                 from blame.c:1:
/nvme/rc-buildroot-test/scripts/instance-0/output-1/host/arm-buildroot-linux-uclibcgnueabihf/sysroot/usr/include/stdio.h:813:13: note: previous declaration of 'funlockfile' was here
 extern void funlockfile (FILE *__stream) __THROW;
             ^~~~~~~~~~~

To avoid this build failure, check if flockfile is available before
defining flockfile, funlockfile and getc_unlocked.

Link: http://autobuild.buildroot.org/results/d41638d1ad8e78dd6f654367c905996b838ee649 [1]
Signed-off-by: Fabrice Fontaine <fontaine.fabrice@xxxxxxxxx>
[Bagas: Rebase to current main, resolve minor conflicts, and slight rewording]
Signed-off-by: Bagas Sanjaya <bagasdotme@xxxxxxxxx>
---
 Makefile          | 5 +++++
 configure.ac      | 6 ++++++
 git-compat-util.h | 3 ++-
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index b258fdbed8..2a8831a9ad 100644
--- a/Makefile
+++ b/Makefile
@@ -149,6 +149,8 @@ include shared.mak
 # Define NO_STRUCT_ITIMERVAL if you don't have struct itimerval
 # This also implies NO_SETITIMER
 #
+# Define NO_FLOCKFILE if you don't have flockfile()
+#
 # Define NO_FAST_WORKING_DIRECTORY if accessing objects in pack files is
 # generally faster on your platform than accessing the working directory.
 #
@@ -1826,6 +1828,9 @@ endif
 ifdef NO_SETITIMER
 	COMPAT_CFLAGS += -DNO_SETITIMER
 endif
+ifdef NO_FLOCKFILE
+	COMPAT_CFLAGS += -DNO_FLOCKFILE
+endif
 ifdef NO_PREAD
 	COMPAT_CFLAGS += -DNO_PREAD
 	COMPAT_OBJS += compat/pread.o
diff --git a/configure.ac b/configure.ac
index 38ff86678a..3a4c230529 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1094,6 +1094,12 @@ GIT_CHECK_FUNC(setitimer,
 [NO_SETITIMER=YesPlease])
 GIT_CONF_SUBST([NO_SETITIMER])
 #
+# Define NO_FLOCKFILE if you don't have flockfile.
+GIT_CHECK_FUNC(flockfile,
+[NO_FLOCKFILE=],
+[NO_FLOCKFILE=YesPlease])
+GIT_CONF_SUBST([NO_FLOCKFILE])
+#
 # Define NO_STRCASESTR if you don't have strcasestr.
 GIT_CHECK_FUNC(strcasestr,
 [NO_STRCASESTR=],
diff --git a/git-compat-util.h b/git-compat-util.h
index a76d0526f7..034f564614 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -1470,7 +1470,8 @@ int open_nofollow(const char *path, int flags);
 # define SHELL_PATH "/bin/sh"
 #endif
 
-#ifndef _POSIX_THREAD_SAFE_FUNCTIONS
+
+#if !defined(_POSIX_THREAD_SAFE_FUNCTIONS) && defined(NO_FLOCKFILE)
 static inline void flockfile(FILE *fh UNUSED)
 {
 	; /* nothing */

base-commit: c000d916380bb59db69c78546928eadd076b9c7d
-- 
An old man doll... just what I always wanted! - Clara




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux