summaryrefslogtreecommitdiff
path: root/compat
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2022-01-24 18:27:59 (GMT)
committerJunio C Hamano <gitster@pobox.com>2022-01-26 17:05:55 (GMT)
commit07564773c2569d012719ab9e26b9b27251f3d354 (patch)
treec881be6715f9fa1a326ace33c92dc27cf72f7ec9 /compat
parent297ca895a27a6bbdb7906371d533f72a12ad25b2 (diff)
downloadgit-07564773c2569d012719ab9e26b9b27251f3d354.zip
git-07564773c2569d012719ab9e26b9b27251f3d354.tar.gz
git-07564773c2569d012719ab9e26b9b27251f3d354.tar.bz2
compat: auto-detect if zlib has uncompress2()
We have a copy of uncompress2() implementation in compat/ so that we can build with an older version of zlib that lack the function, and the build procedure selects if it is used via the NO_UNCOMPRESS2 $(MAKE) variable. This is yet another "annoying" knob the porters need to tweak on platforms that are not common enough to have the default set in the config.mak.uname file. Attempt to instead ask the system header <zlib.h> to decide if we need the compatibility implementation. This is a deviation from the way we have been handling the "compatiblity" features so far, and if it can be done cleanly enough, it could work as a model for features that need compatibility definition we discover in the future. With that goal in mind, avoid expedient but ugly hacks, like shoving the code that is conditionally compiled into an unrelated .c file, which may not work in future cases---instead, take an approach that uses a file that is independently compiled and stands on its own. Compile and link compat/zlib-uncompress2.c file unconditionally, but conditionally hide the implementation behind #if/#endif when zlib version is 1.2.9 or newer, and unconditionally archive the resulting object file in the libgit.a to be picked up by the linker. There are a few things to note in the shape of the code base after this change: - We no longer use NO_UNCOMPRESS2 knob; if the system header <zlib.h> claims a version that is more cent than the library actually is, this would break, but it is easy to add it back when we find such a system. - The object file compat/zlib-uncompress2.o is always compiled and archived in libgit.a, just like a few other compat/ object files already are. - The inclusion of <zlib.h> is done in <git-compat-util.h>; we used to do so from <cache.h> which includes <git-compat-util.h> as the first thing it does, so from the *.c codes, there is no practical change. - Until objects in libgit.a that is already used gains a reference to the function, the reftable code will be the only one that wants it, so libgit.a on the linker command line needs to appear once more at the end to satisify the mutual dependency. - Beat found a trick used by OpenSSL to avoid making the conditionally-compiled object truly empty (apparently because they had to deal with compilers that do not want to see an effectively empty input file). Our compat/zlib-uncompress2.c file borrows the same trick for portabilty. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Helped-by: Beat Bolli <dev+git@drbeat.li> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'compat')
-rw-r--r--compat/zlib-uncompress2.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/compat/zlib-uncompress2.c b/compat/zlib-uncompress2.c
index 722610b..77a1b08 100644
--- a/compat/zlib-uncompress2.c
+++ b/compat/zlib-uncompress2.c
@@ -1,3 +1,6 @@
+#include "git-compat-util.h"
+
+#if ZLIB_VERNUM < 0x1290
/* taken from zlib's uncompr.c
commit cacf7f1d4e3d44d871b605da3b647f07d718623f
@@ -8,16 +11,11 @@
*/
-#include "../reftable/system.h"
-#define z_const
-
/*
* Copyright (C) 1995-2003, 2010, 2014, 2016 Jean-loup Gailly, Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-#include <zlib.h>
-
/* clang-format off */
/* ===========================================================================
@@ -93,3 +91,6 @@ int ZEXPORT uncompress2 (
err == Z_BUF_ERROR && left + stream.avail_out ? Z_DATA_ERROR :
err;
}
+#else
+static void *dummy_variable = &dummy_variable;
+#endif