zlib: wrap deflateBound() too

Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jun 10, 2011 at 11:18 UTC 225a6f1068f71723a910e8565db4e252b3ca21fa
8 files changed +17 -10
archive-zip.c
+1 -1
@@ -97,7 +97,7 @@ static void *zlib_deflate(void *data, unsigned long size,
97
98 memset(&stream, 0, sizeof(stream));
99 git_deflate_init(&stream, compression_level);
100 - maxsize = deflateBound(&stream, size);
100 + maxsize = git_deflate_bound(&stream, size);
101 buffer = xmalloc(maxsize);
102
103 stream.next_in = data;
builtin/pack-objects.c
+1 -1
@@ -132,7 +132,7 @@ static unsigned long do_compress(void **pptr, unsigned long size)
132
133 memset(&stream, 0, sizeof(stream));
134 git_deflate_init(&stream, pack_compression_level);
135 - maxsize = deflateBound(&stream, size);
135 + maxsize = git_deflate_bound(&stream, size);
136
137 in = *pptr;
138 out = xmalloc(maxsize);
cache.h
+1 -3
@@ -16,9 +16,6 @@
16 #endif
17
18 #include <zlib.h>
19 -#if defined(NO_DEFLATE_BOUND) || ZLIB_VERNUM < 0x1200
20 -#define deflateBound(c,s) ((s) + (((s) + 7) >> 3) + (((s) + 63) >> 6) + 11)
21 -#endif
19
20 void git_inflate_init(z_streamp strm);
21 void git_inflate_init_gzip_only(z_streamp strm);
@@ -30,6 +27,7 @@ void git_deflate_init_gzip(z_streamp strm, int level);
27 void git_deflate_end(z_streamp strm);
28 int git_deflate_end_gently(z_streamp strm);
29 int git_deflate(z_streamp strm, int flush);
30 +unsigned long git_deflate_bound(z_streamp, unsigned long);
31
32 #if defined(DT_UNKNOWN) && !defined(NO_D_TYPE_IN_DIRENT)
33 #define DTYPE(de) ((de)->d_type)
diff.c
+1 -1
@@ -1733,7 +1733,7 @@ static unsigned char *deflate_it(char *data,
1733
1734 memset(&stream, 0, sizeof(stream));
1735 git_deflate_init(&stream, zlib_compression_level);
1736 - bound = deflateBound(&stream, size);
1736 + bound = git_deflate_bound(&stream, size);
1737 deflated = xmalloc(bound);
1738 stream.next_out = deflated;
1739 stream.avail_out = bound;
fast-import.c
+2 -2
@@ -1058,7 +1058,7 @@ static int store_object(
1058 s.next_in = (void *)dat->buf;
1059 s.avail_in = dat->len;
1060 }
1061 - s.avail_out = deflateBound(&s, s.avail_in);
1061 + s.avail_out = git_deflate_bound(&s, s.avail_in);
1062 s.next_out = out = xmalloc(s.avail_out);
1063 while (git_deflate(&s, Z_FINISH) == Z_OK)
1064 ; /* nothing */
@@ -1081,7 +1081,7 @@ static int store_object(
1081 git_deflate_init(&s, pack_compression_level);
1082 s.next_in = (void *)dat->buf;
1083 s.avail_in = dat->len;
1084 - s.avail_out = deflateBound(&s, s.avail_in);
1084 + s.avail_out = git_deflate_bound(&s, s.avail_in);
1085 s.next_out = out = xrealloc(out, s.avail_out);
1086 while (git_deflate(&s, Z_FINISH) == Z_OK)
1087 ; /* nothing */
http-push.c
+1 -1
@@ -360,7 +360,7 @@ static void start_put(struct transfer_request *request)
360 /* Set it up */
361 memset(&stream, 0, sizeof(stream));
362 git_deflate_init(&stream, zlib_compression_level);
363 - size = deflateBound(&stream, len + hdrlen);
363 + size = git_deflate_bound(&stream, len + hdrlen);
364 strbuf_init(&request->buffer.buf, size);
365 request->buffer.posn = 0;
366
remote-curl.c
+1 -1
@@ -476,7 +476,7 @@ static int post_rpc(struct rpc_state *rpc)
476
477 memset(&stream, 0, sizeof(stream));
478 git_deflate_init_gzip(&stream, Z_BEST_COMPRESSION);
479 - size = deflateBound(&stream, rpc->len);
479 + size = git_deflate_bound(&stream, rpc->len);
480 gzip_body = xmalloc(size);
481
482 stream.next_in = (unsigned char *)rpc->buf;
zlib.c
+9
@@ -78,6 +78,15 @@ int git_inflate(z_streamp strm, int flush)
78 return status;
79 }
80
81 +#if defined(NO_DEFLATE_BOUND) || ZLIB_VERNUM < 0x1200
82 +#define deflateBound(c,s) ((s) + (((s) + 7) >> 3) + (((s) + 63) >> 6) + 11)
83 +#endif
84 +
85 +unsigned long git_deflate_bound(z_streamp strm, unsigned long size)
86 +{
87 + return deflateBound(strm, size);
88 +}
89 +
90 void git_deflate_init(z_streamp strm, int level)
91 {
92 int status = deflateInit(strm, level);