@matheusbsbs / matheus-bagliano / commits / b0613ce0f9
Fork 0

wrapper: give zlib wrappers their own translation unit

Programs using xmalloc() but not git_inflate() require -lz on the linker command line because git_inflate() is in the same translation unit as xmalloc(). Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Nieder committed Nov 6, 2010 at 06:47 UTC b0613ce0f9ef3fd111f8c75b84ddd12f9f04fc87
3 files changed +62 -60
Makefile
+1
@@ -662,6 +662,7 @@ LIB_OBJS += write_or_die.o
662 LIB_OBJS += ws.o
663 LIB_OBJS += wt-status.o
664 LIB_OBJS += xdiff-interface.o
665 +LIB_OBJS += zlib.o
666
667 BUILTIN_OBJS += builtin/add.o
668 BUILTIN_OBJS += builtin/annotate.o
wrapper.c
-60
@@ -327,66 +327,6 @@ int xmkstemp_mode(char *template, int mode)
327 return fd;
328 }
329
330 -/*
331 - * zlib wrappers to make sure we don't silently miss errors
332 - * at init time.
333 - */
334 -void git_inflate_init(z_streamp strm)
335 -{
336 - const char *err;
337 -
338 - switch (inflateInit(strm)) {
339 - case Z_OK:
340 - return;
341 -
342 - case Z_MEM_ERROR:
343 - err = "out of memory";
344 - break;
345 - case Z_VERSION_ERROR:
346 - err = "wrong version";
347 - break;
348 - default:
349 - err = "error";
350 - }
351 - die("inflateInit: %s (%s)", err, strm->msg ? strm->msg : "no message");
352 -}
353 -
354 -void git_inflate_end(z_streamp strm)
355 -{
356 - if (inflateEnd(strm) != Z_OK)
357 - error("inflateEnd: %s", strm->msg ? strm->msg : "failed");
358 -}
359 -
360 -int git_inflate(z_streamp strm, int flush)
361 -{
362 - int ret = inflate(strm, flush);
363 - const char *err;
364 -
365 - switch (ret) {
366 - /* Out of memory is fatal. */
367 - case Z_MEM_ERROR:
368 - die("inflate: out of memory");
369 -
370 - /* Data corruption errors: we may want to recover from them (fsck) */
371 - case Z_NEED_DICT:
372 - err = "needs dictionary"; break;
373 - case Z_DATA_ERROR:
374 - err = "data stream error"; break;
375 - case Z_STREAM_ERROR:
376 - err = "stream consistency error"; break;
377 - default:
378 - err = "unknown error"; break;
379 -
380 - /* Z_BUF_ERROR: normal, needs more space in the output buffer */
381 - case Z_BUF_ERROR:
382 - case Z_OK:
383 - case Z_STREAM_END:
384 - return ret;
385 - }
386 - error("inflate: %s (%s)", err, strm->msg ? strm->msg : "no message");
387 - return ret;
388 -}
389 -
330 static int warn_if_unremovable(const char *op, const char *file, int rc)
331 {
332 if (rc < 0) {
zlib.c new
+61
@@ -0,0 +1,61 @@
1 +/*
2 + * zlib wrappers to make sure we don't silently miss errors
3 + * at init time.
4 + */
5 +#include "cache.h"
6 +
7 +void git_inflate_init(z_streamp strm)
8 +{
9 + const char *err;
10 +
11 + switch (inflateInit(strm)) {
12 + case Z_OK:
13 + return;
14 +
15 + case Z_MEM_ERROR:
16 + err = "out of memory";
17 + break;
18 + case Z_VERSION_ERROR:
19 + err = "wrong version";
20 + break;
21 + default:
22 + err = "error";
23 + }
24 + die("inflateInit: %s (%s)", err, strm->msg ? strm->msg : "no message");
25 +}
26 +
27 +void git_inflate_end(z_streamp strm)
28 +{
29 + if (inflateEnd(strm) != Z_OK)
30 + error("inflateEnd: %s", strm->msg ? strm->msg : "failed");
31 +}
32 +
33 +int git_inflate(z_streamp strm, int flush)
34 +{
35 + int ret = inflate(strm, flush);
36 + const char *err;
37 +
38 + switch (ret) {
39 + /* Out of memory is fatal. */
40 + case Z_MEM_ERROR:
41 + die("inflate: out of memory");
42 +
43 + /* Data corruption errors: we may want to recover from them (fsck) */
44 + case Z_NEED_DICT:
45 + err = "needs dictionary"; break;
46 + case Z_DATA_ERROR:
47 + err = "data stream error"; break;
48 + case Z_STREAM_ERROR:
49 + err = "stream consistency error"; break;
50 + default:
51 + err = "unknown error"; break;
52 +
53 + /* Z_BUF_ERROR: normal, needs more space in the output buffer */
54 + case Z_BUF_ERROR:
55 + case Z_OK:
56 + case Z_STREAM_END:
57 + return ret;
58 + }
59 + error("inflate: %s (%s)", err, strm->msg ? strm->msg : "no message");
60 + return ret;
61 +}