Skip to content

Commit ce76cec

Browse files
pks-tgitster
authored andcommitted
git-zlib: use struct z_stream_s instead of typedef
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 12a9aa8 commit ce76cec

File tree

4 files changed

+7
-9
lines changed

4 files changed

+7
-9
lines changed

Documentation/howto/recover-corrupted-object-harder.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ static int try_zlib(unsigned char *buf, int len)
125125
{
126126
/* make this absurdly large so we don't have to loop */
127127
static unsigned char out[1024*1024];
128-
z_stream z;
128+
struct z_stream_s z;
129129
int ret;
130130
131131
memset(&z, 0, sizeof(z));
@@ -278,7 +278,7 @@ int main(int argc, char **argv)
278278
static unsigned char buf[25 * 1024 * 1024];
279279
static unsigned char out[25 * 1024 * 1024];
280280
int len;
281-
z_stream z;
281+
struct z_stream_s z;
282282
int ret;
283283
284284
len = read(0, buf, sizeof(buf));

compat/zlib-compat.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#ifdef HAVE_ZLIB_NG
55
# include <zlib-ng.h>
66

7-
# define z_stream zng_stream
8-
#define gz_header_s zng_gz_header_s
7+
# define z_stream_s zng_stream_s
8+
# define gz_header_s zng_gz_header_s
99

1010
# define crc32(crc, buf, len) zng_crc32(crc, buf, len)
1111

git-zlib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "compat/zlib-compat.h"
55

66
typedef struct git_zstream {
7-
z_stream z;
7+
struct z_stream_s z;
88
unsigned long avail_in;
99
unsigned long avail_out;
1010
unsigned long total_in;

reftable/block.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* allocation overhead.
1919
*/
2020
struct block_writer {
21-
z_stream *zstream;
21+
struct z_stream_s *zstream;
2222
unsigned char *compressed;
2323
size_t compressed_cap;
2424

@@ -62,8 +62,6 @@ int block_writer_finish(struct block_writer *w);
6262
/* clears out internally allocated block_writer members. */
6363
void block_writer_release(struct block_writer *bw);
6464

65-
struct z_stream;
66-
6765
/*
6866
* A block part of a reftable. Contains records as well as some metadata
6967
* describing them.
@@ -78,7 +76,7 @@ struct reftable_block {
7876
uint32_t hash_size;
7977

8078
/* Uncompressed data for log entries. */
81-
z_stream *zstream;
79+
struct z_stream_s *zstream;
8280
unsigned char *uncompressed_data;
8381
size_t uncompressed_cap;
8482

0 commit comments

Comments
 (0)