]> git.ipfire.org Git - thirdparty/git.git/commitdiff
git-zlib: use `struct z_stream_s` instead of typedef
authorPatrick Steinhardt <ps@pks.im>
Mon, 7 Apr 2025 13:16:20 +0000 (15:16 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 7 Apr 2025 21:53:11 +0000 (14:53 -0700)
Throughout the Git codebase we're using the typedeffed version of
`z_stream`, which maps to `struct z_stream_s`. By using a typedef
instead of the struct it becomes somewhat harder to predeclare the
symbol so that headers depending on the struct can do so without having
to pull in "zlib-compat.h".

We don't yet have users that would really care about this: the only
users that declare `z_stream` as a pointer are in "reftable/block.h",
which is a header that is internal to the reftable library. But in the
next step we're going to expose the `struct reftable_block` publicly,
and that struct does contain a pointer to `z_stream`. And as the public
header shouldn't depend on "reftable/system.h", which is an internal
implementation detail, we won't have the typedef for `z_stream` readily
available.

Prepare for this change by using `struct z_stream_s` throughout our code
base. In case zlib-ng is used we use a define to map from `z_stream_s`
to `zng_stream_s`.

Drop the pre-declaration of `struct z_stream` while at it. This struct
does not exist in the first place, and the declaration wasn't needed
because "reftable/block.h" already includes "reftable/basics.h" which
transitively includes "reftable/system.h" and thus "git-zlib.h".

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/howto/recover-corrupted-object-harder.adoc
compat/zlib-compat.h
git-zlib.h
reftable/block.h

index 5efb4fe81ff120e50027b836e85c8ee205923821..86a1ba75cf96701d16f88c0cd6743c85dd49987e 100644 (file)
@@ -125,7 +125,7 @@ static int try_zlib(unsigned char *buf, int len)
 {
        /* make this absurdly large so we don't have to loop */
        static unsigned char out[1024*1024];
-       z_stream z;
+       struct z_stream_s z;
        int ret;
 
        memset(&z, 0, sizeof(z));
@@ -278,7 +278,7 @@ int main(int argc, char **argv)
        static unsigned char buf[25 * 1024 * 1024];
        static unsigned char out[25 * 1024 * 1024];
        int len;
-       z_stream z;
+       struct z_stream_s z;
        int ret;
 
        len = read(0, buf, sizeof(buf));
index 0c60e3af331fb5eed3f66312fc625909ab57cf53..ac0827662298af71e2bd5e60135ae40fe469cb4a 100644 (file)
@@ -4,8 +4,8 @@
 #ifdef HAVE_ZLIB_NG
 # include <zlib-ng.h>
 
-# define z_stream zng_stream
-#define gz_header_s zng_gz_header_s
+# define z_stream_s zng_stream_s
+# define gz_header_s zng_gz_header_s
 
 # define crc32(crc, buf, len) zng_crc32(crc, buf, len)
 
index 1e8d9aabcb4cb239bdf529926be60b56496e0d4f..0e66fefa8c9f0573b798c66a1602a89fb6eff14c 100644 (file)
@@ -4,7 +4,7 @@
 #include "compat/zlib-compat.h"
 
 typedef struct git_zstream {
-       z_stream z;
+       struct z_stream_s z;
        unsigned long avail_in;
        unsigned long avail_out;
        unsigned long total_in;
index 3957aee4293e800db0219c2a5ca2aa612eaec16d..422e2f872c5acab2629645259be6186b4928f5b8 100644 (file)
@@ -18,7 +18,7 @@
  * allocation overhead.
  */
 struct block_writer {
-       z_stream *zstream;
+       struct z_stream_s *zstream;
        unsigned char *compressed;
        size_t compressed_cap;
 
@@ -62,8 +62,6 @@ int block_writer_finish(struct block_writer *w);
 /* clears out internally allocated block_writer members. */
 void block_writer_release(struct block_writer *bw);
 
-struct z_stream;
-
 /*
  * A block part of a reftable. Contains records as well as some metadata
  * describing them.
@@ -78,7 +76,7 @@ struct reftable_block {
        uint32_t hash_size;
 
        /* Uncompressed data for log entries. */
-       z_stream *zstream;
+       struct z_stream_s *zstream;
        unsigned char *uncompressed_data;
        size_t uncompressed_cap;