X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/ef21f8dbffe6bad5c72add02f291a6e81b63ae60..0b76cd63ee0eacb95285dfb5d2cac2992e1794ef:/lib/zlib.c diff --git a/lib/zlib.c b/lib/zlib.c index ff689b1c..a4cf064e 100644 --- a/lib/zlib.c +++ b/lib/zlib.c @@ -7,7 +7,6 @@ * * Changes that have been made include: * - changed functions not used outside this file to "local" - * - added minCompression parameter to deflateInit2 * - added Z_PACKET_FLUSH (see zlib.h for details) * - added inflateIncomp * @@ -211,7 +210,6 @@ typedef struct deflate_state { int noheader; /* suppress zlib header and adler32 */ Byte data_type; /* UNKNOWN, BINARY or ASCII */ Byte method; /* STORED (for zip only) or DEFLATED */ - int minCompr; /* min size decrease for Z_FLUSH_NOSTORE */ /* used by deflate.c: */ @@ -254,7 +252,7 @@ typedef struct deflate_state { * hash_shift * MIN_MATCH >= hash_bits */ - long block_start; + Long block_start; /* Window position at the beginning of the current output block. Gets * negative when the window is moved backwards. */ @@ -568,21 +566,18 @@ int deflateInit (strm, level) z_stream *strm; int level; { - return deflateInit2 (strm, level, DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, - 0, 0); + return deflateInit2 (strm, level, DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, 0); /* To do: ignore strm->next_in if we use it as window */ } /* ========================================================================= */ -int deflateInit2 (strm, level, method, windowBits, memLevel, - strategy, minCompression) +int deflateInit2 (strm, level, method, windowBits, memLevel, strategy) z_stream *strm; int level; int method; int windowBits; int memLevel; int strategy; - int minCompression; { deflate_state *s; int noheader = 0; @@ -605,6 +600,7 @@ int deflateInit2 (strm, level, method, windowBits, memLevel, } s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state)); if (s == Z_NULL) return Z_MEM_ERROR; + bzero(s, sizeof(*s)); strm->state = (struct internal_state FAR *)s; s->strm = strm; @@ -642,7 +638,6 @@ int deflateInit2 (strm, level, method, windowBits, memLevel, s->level = level; s->strategy = strategy; s->method = (Byte)method; - s->minCompr = minCompression; s->blocks_in_packet = 0; return deflateReset(strm); @@ -1127,7 +1122,7 @@ local void fill_window(s) s->match_start -= wsize; s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ - s->block_start -= (long) wsize; + s->block_start -= (Long) wsize; /* Slide the hash table (could be avoided with 32 bit values at the expense of memory usage): @@ -1192,7 +1187,7 @@ local void fill_window(s) #define FLUSH_BLOCK_ONLY(s, flush) { \ ct_flush_block(s, (s->block_start >= 0L ? \ (charf *)&s->window[(unsigned)s->block_start] : \ - (charf *)Z_NULL), (long)s->strstart - s->block_start, (flush)); \ + (charf *)Z_NULL), (Long)s->strstart - s->block_start, (flush)); \ s->block_start = s->strstart; \ flush_pending(s->strm); \ Tracev((stderr,"[FLUSH]")); \ @@ -1912,8 +1907,8 @@ local void gen_bitlen(s, desc) if (m > max_code) continue; if (tree[m].Len != (unsigned) bits) { Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits)); - s->opt_len += ((long)bits - (long)tree[m].Len) - *(long)tree[m].Freq; + s->opt_len += ((Long)bits - (Long)tree[m].Len) + *(Long)tree[m].Freq; tree[m].Len = (ush)bits; } n--; @@ -2337,17 +2332,6 @@ local ulg ct_flush_block(s, buf, stored_len, flush) } else #endif /* STORED_FILE_OK */ - /* For Z_PACKET_FLUSH, if we don't achieve the required minimum - * compression, and this block contains all the data since the last - * time we used Z_PACKET_FLUSH, then just omit this block completely - * from the output. - */ - if (flush == Z_PACKET_FLUSH && s->blocks_in_packet == 1 - && opt_lenb > stored_len - s->minCompr) { - s->blocks_in_packet = 0; - /* output nothing */ - } else - #ifdef FORCE_STORED if (buf != (char*)0) /* force stored block */ #else @@ -2742,7 +2726,7 @@ struct internal_state { CHECK2, /* two check bytes to go */ CHECK1, /* one check byte to go */ DONE, /* finished check, done */ - BAD} /* got an error--stay here */ + ZBAD} /* got an error--stay here */ mode; /* current inflate mode */ /* mode dependent information */ @@ -2752,7 +2736,7 @@ struct internal_state { uLong was; /* computed check value */ uLong need; /* stream check value */ } check; /* if CHECK, check values to compare */ - uInt marker; /* if BAD, inflateSync's marker bytes count */ + uInt marker; /* if ZBAD, inflateSync's marker bytes count */ } sub; /* submode */ /* mode independent information */ @@ -2868,14 +2852,14 @@ int f; NEEDBYTE if (((z->state->sub.method = NEXTBYTE) & 0xf) != DEFLATED) { - z->state->mode = BAD; + z->state->mode = ZBAD; z->msg = "unknown compression method"; z->state->sub.marker = 5; /* can't try inflateSync */ break; } if ((z->state->sub.method >> 4) + 8 > z->state->wbits) { - z->state->mode = BAD; + z->state->mode = ZBAD; z->msg = "invalid window size"; z->state->sub.marker = 5; /* can't try inflateSync */ break; @@ -2885,14 +2869,14 @@ int f; NEEDBYTE if ((b = NEXTBYTE) & 0x20) { - z->state->mode = BAD; + z->state->mode = ZBAD; z->msg = "invalid reserved bit"; z->state->sub.marker = 5; /* can't try inflateSync */ break; } if (((z->state->sub.method << 8) + b) % 31) { - z->state->mode = BAD; + z->state->mode = ZBAD; z->msg = "incorrect header check"; z->state->sub.marker = 5; /* can't try inflateSync */ break; @@ -2905,7 +2889,7 @@ int f; r = inflate_packet_flush(z->state->blocks); if (r == Z_DATA_ERROR) { - z->state->mode = BAD; + z->state->mode = ZBAD; z->state->sub.marker = 0; /* can try inflateSync */ break; } @@ -2937,7 +2921,7 @@ int f; if (z->state->sub.check.was != z->state->sub.check.need) { - z->state->mode = BAD; + z->state->mode = ZBAD; z->msg = "incorrect data check"; z->state->sub.marker = 5; /* can't try inflateSync */ break; @@ -2946,7 +2930,7 @@ int f; z->state->mode = DONE; case DONE: return Z_STREAM_END; - case BAD: + case ZBAD: return Z_DATA_ERROR; default: return Z_STREAM_ERROR; @@ -2955,7 +2939,7 @@ int f; empty: if (f != Z_PACKET_FLUSH) return r; - z->state->mode = BAD; + z->state->mode = ZBAD; z->state->sub.marker = 0; /* can try inflateSync */ return Z_DATA_ERROR; } @@ -2989,9 +2973,9 @@ z_stream *z; /* set up */ if (z == Z_NULL || z->state == Z_NULL) return Z_STREAM_ERROR; - if (z->state->mode != BAD) + if (z->state->mode != ZBAD) { - z->state->mode = BAD; + z->state->mode = ZBAD; z->state->sub.marker = 0; } if ((n = z->avail_in) == 0) @@ -3106,9 +3090,9 @@ struct inflate_blocks_state { /* output bytes */ #define WAVAIL (qread?s->read-q-1:s->end-q) #define LOADOUT {q=s->write;m=WAVAIL;} -#define WRAP {if(q==s->end&&s->read!=s->window){q=s->window;m=WAVAIL;}} +#define ZWRAP {if(q==s->end&&s->read!=s->window){q=s->window;m=WAVAIL;}} #define FLUSH {UPDOUT r=inflate_flush(s,z,r); LOADOUT} -#define NEEDOUT {if(m==0){WRAP if(m==0){FLUSH WRAP if(m==0) LEAVE}}r=Z_OK;} +#define NEEDOUT {if(m==0){ZWRAP if(m==0){FLUSH ZWRAP if(m==0) LEAVE}}r=Z_OK;} #define OUTBYTE(a) {*q++=(Byte)(a);m--;} /* load local pointers */ #define LOAD {LOADIN LOADOUT} @@ -3569,7 +3553,7 @@ z_stream *z; n -= t; z->total_out += t; s->read = q; /* drag read pointer forward */ -/* WRAP */ /* expand WRAP macro by hand to handle s->read */ +/* ZWRAP */ /* expand ZWRAP macro by hand to handle s->read */ if (q == s->end) { s->read = q = s->window; m = WAVAIL; @@ -3960,7 +3944,9 @@ z_stream *z; /* for zfree function */ /* build fixed tables only once--keep them here */ -local int fixed_lock = 0; +#ifdef MULTI_THREADED +local volatile int fixed_lock = 0; +#endif local int fixed_built = 0; #define FIXEDH 530 /* number of hufts used by fixed tables */ local uInt fixed_left = FIXEDH; @@ -4001,8 +3987,10 @@ inflate_huft * FAR *tl; /* literal/length tree result */ inflate_huft * FAR *td; /* distance tree result */ { /* build fixed tables if not built already--lock out other instances */ +#ifdef MULTI_THREADED while (++fixed_lock > 1) fixed_lock--; +#endif if (!fixed_built) { int k; /* temporary variable */ @@ -4035,7 +4023,9 @@ inflate_huft * FAR *td; /* distance tree result */ /* done */ fixed_built = 1; } +#ifdef MULTI_THREADED fixed_lock--; +#endif *bl = fixed_bl; *bd = fixed_bd; *tl = fixed_tl; @@ -4588,8 +4578,8 @@ uLong adler32(adler, buf, len) Bytef *buf; uInt len; { - unsigned long s1 = adler & 0xffff; - unsigned long s2 = (adler >> 16) & 0xffff; + uLong s1 = adler & 0xffff; + uLong s2 = (adler >> 16) & 0xffff; int k; if (buf == Z_NULL) return 1L;