Skip to content

Commit

Permalink
zlib 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
madler committed Sep 10, 2011
1 parent b8c9ecb commit 965fe72
Show file tree
Hide file tree
Showing 17 changed files with 262 additions and 68 deletions.
11 changes: 11 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@

ChangeLog file for zlib

Changes in 1.1 (24 Feb 98)
- do not return STREAM_END prematurely in inflate (John Bowler)
- revert to the zlib 1.0.8 inflate to avoid the gcc 2.8.0 bug (Jeremy Buhler)
- compile with -DFASTEST to get compression code optimized for speed only
- in minigzip, try mmap'ing the input file first (Miguel Albrecht)
- increase size of I/O buffers in minigzip.c and gzio.c (not a big gain
on Sun but significant on HP)

- add a pointer to experimental unzip library in README (Gilles Vollant)
- initialize variable gcc in configure (Chris Herborth)

Changes in 1.0.9 (17 Feb 1998)
- added gzputs and gzgets functions
- do not clear eof flag in gzseek (Mark Diekhans)
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ CFLAGS=-O
LDFLAGS=-L. -lz
LDSHARED=$(CC)

VER=1.0.9
VER=1.1.0
LIBS=libz.a
SHAREDLIB=libz.so

Expand Down
2 changes: 1 addition & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ CFLAGS=-O
LDFLAGS=-L. -lz
LDSHARED=$(CC)

VER=1.0.9
VER=1.1.0
LIBS=libz.a
SHAREDLIB=libz.so

Expand Down
31 changes: 15 additions & 16 deletions README
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
zlib 1.0.9 is a general purpose data compression library. All the code
zlib 1.1.0 is a general purpose data compression library. All the code
is thread safe. The data format used by the zlib library
is described by RFCs (Request for Comments) 1950 to 1952 in the files
ftp://ds.internic.net/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate
Expand All @@ -25,21 +25,15 @@ Mark Nelson wrote an article about zlib for the Jan. 1997 issue of
Dr. Dobb's Journal; a copy of the article is available in
http://web2.airmail.net/markn/articles/zlibtool/zlibtool.htm

The changes made in version 1.0.9 are documented in the file ChangeLog.
The main changes since 1.0.8 are:
The changes made in version 1.1.0 are documented in the file ChangeLog.
The main changes since 1.0.9 are:

- added gzputs and gzgets functions
- do not clear eof flag in gzseek (Mark Diekhans)
- fix gzseek for files in transparent mode (Mark Diekhans)
- do not assume that vsprintf returns the number of bytes written (Jens Krinke)
- replace EXPORT with ZEXPORT to avoid conflict with other programs
- added compress2 in zconf.h, zlib.def, zlib.dnt
- new asm code from Gilles Vollant in contrib/asm386
- simplify the inflate code (Mark):
. Replace ZALLOC's in huft_build() with single ZALLOC in inflate_blocks_new()
. ZALLOC the length list in inflate_trees_fixed() instead of using stack
. ZALLOC the value area for huft_build() instead of using stack
. Simplify Z_FINISH check in inflate()
- do not return STREAM_END prematurely in inflate (John Bowler)
- revert to the zlib 1.0.8 inflate to avoid the gcc 2.8.0 bug (Jeremy Buhler)
- compile with -DFASTEST to get compression code optimized for speed only
- in minigzip, try mmap'ing the input file first (Miguel Albrecht)
- increase size of I/O buffers in minigzip.c and gzio.c (not a big gain
on Sun but significant on HP)


Unsupported third party contributions are provided in directory "contrib".
Expand All @@ -56,6 +50,11 @@ A Python interface to zlib written by A.M. Kuchling <amk@magnet.com>
is available from the Python Software Association sites, such as:
ftp://ftp.python.org/pub/python/contrib/Encoding/zlib*.tar.gz

An experimental package to read files in .zip format, written on top of
zlib by Gilles Vollant <info@winimage.com>, is available at
http://www.winimage.com/zLibDll/unzip.html


Notes for some targets:

- To build a Windows DLL version, include in a DLL project zlib.def, zlib.rc
Expand Down Expand Up @@ -83,7 +82,7 @@ Notes for some targets:
writes to pointers are atomic. Also the functions zalloc and zfree passed
to deflateInit must be multi-threaded in this case.

- gzdopen is not supported on RISCOS, BEOS and Mac
- gzdopen is not supported on RISCOS, BEOS and by some Mac compilers.

- For Turbo C the small model is supported only with reduced performance to
avoid any far allocation; it was tested with -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3
Expand Down
19 changes: 18 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ prefix=${prefix-/usr/local}
exec_prefix=${exec_prefix-$prefix}
shared_ext='.so'
shared=0
gcc=0
old_cc="$CC"
old_cflags="$CFLAGS"

Expand Down Expand Up @@ -114,7 +115,6 @@ if test $shared -eq 0; then
LDSHARED="$CC"
echo Building static library $LIBS version $VER with $CC.
fi
rm -f $test.[co] $test$shared_ext

if test -f /usr/include/unistd.h; then
CFLAGS="$CFLAGS -DHAVE_UNISTD_H"
Expand All @@ -124,6 +124,23 @@ if test ! -f /usr/include/errno.h; then
CFLAGS="$CFLAGS -DNO_ERRNO_H"
fi

cat > $test.c <<EOF
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>
caddr_t hello() {
return mmap((caddr_t)0, (off_t)0, PROT_READ, MAP_SHARED, 0, (off_t)0);
}
EOF
if test "`($CC -c $CFLAGS $test.c) 2>&1`" = ""; then
CFLAGS="$CFLAGS -DUSE_MMAP"
echo Checking for mmap support... Yes.
else
echo Checking for mmap support... No.
fi

rm -f $test.[co] $test$shared_ext

# udpate Makefile
sed < Makefile.in "
/^CC *=/s%=.*%=$CC%
Expand Down
93 changes: 85 additions & 8 deletions deflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
#include "deflate.h"

const char deflate_copyright[] =
" deflate 1.0.9 Copyright 1995-1998 Jean-loup Gailly ";
" deflate 1.1.0 Copyright 1995-1998 Jean-loup Gailly ";
/*
If you use the zlib library in a product, an acknowledgment is welcome
in the documentation of your product. If for some reason you cannot
Expand Down Expand Up @@ -160,14 +160,23 @@ struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
* Insert string str in the dictionary and set match_head to the previous head
* of the hash chain (the most recent string with same hash key). Return
* the previous length of the hash chain.
* If this file is compiled with -DFASTEST, the compression level is forced
* to 1, and no hash chains are maintained.
* IN assertion: all calls to to INSERT_STRING are made with consecutive
* input characters and the first MIN_MATCH bytes of str are valid
* (except for the last MIN_MATCH-1 bytes of the input file).
*/
#ifdef FASTEST
#define INSERT_STRING(s, str, match_head) \
(UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
match_head = s->head[s->ins_h], \
s->head[s->ins_h] = (Pos)(str))
#else
#define INSERT_STRING(s, str, match_head) \
(UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
s->prev[(str) & s->w_mask] = match_head = s->head[s->ins_h], \
s->head[s->ins_h] = (Pos)(str))
#endif

/* ===========================================================================
* Initialize the hash table (avoiding 64K overflow for 16 bit systems).
Expand Down Expand Up @@ -224,6 +233,9 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
if (strm->zfree == Z_NULL) strm->zfree = zcfree;

if (level == Z_DEFAULT_COMPRESSION) level = 6;
#ifdef FASTEST
level = 1;
#endif

if (windowBits < 0) { /* undocumented feature: suppress zlib header */
noheader = 1;
Expand Down Expand Up @@ -708,6 +720,7 @@ local void lm_init (s)
/* For 80x86 and 680x0, an optimized version will be provided in match.asm or
* match.S. The code will be functionally equivalent.
*/
#ifndef FASTEST
local uInt longest_match(s, cur_match)
deflate_state *s;
IPos cur_match; /* current match */
Expand Down Expand Up @@ -845,6 +858,64 @@ local uInt longest_match(s, cur_match)
if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
return s->lookahead;
}

#else /* FASTEST */
/* ---------------------------------------------------------------------------
* Optimized version for level == 1 only
*/
local uInt longest_match(s, cur_match)
deflate_state *s;
IPos cur_match; /* current match */
{
register Bytef *scan = s->window + s->strstart; /* current string */
register Bytef *match; /* matched string */
register int len; /* length of current match */
register Bytef *strend = s->window + s->strstart + MAX_MATCH;

/* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
* It is easy to get rid of this optimization if necessary.
*/
Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");

Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");

Assert(cur_match < s->strstart, "no future");

match = s->window + cur_match;

/* Return failure if the match length is less than 2:
*/
if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1;

/* The check at best_len-1 can be removed because it will be made
* again later. (This heuristic is not always a win.)
* It is not necessary to compare scan[2] and match[2] since they
* are always equal when the other bytes match, given that
* the hash keys are equal and that HASH_BITS >= 8.
*/
scan += 2, match += 2;
Assert(*scan == *match, "match[2]?");

/* We check for insufficient lookahead only every 8th comparison;
* the 256th check will be made at strstart+258.
*/
do {
} while (*++scan == *++match && *++scan == *++match &&
*++scan == *++match && *++scan == *++match &&
*++scan == *++match && *++scan == *++match &&
*++scan == *++match && *++scan == *++match &&
scan < strend);

Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");

len = MAX_MATCH - (int)(strend - scan);

if (len < MIN_MATCH) return MIN_MATCH - 1;

s->match_start = cur_match;
return len <= s->lookahead ? len : s->lookahead;
}
#endif /* FASTEST */
#endif /* ASMV */

#ifdef DEBUG
Expand Down Expand Up @@ -930,6 +1001,7 @@ local void fill_window(s)
} while (--n);

n = wsize;
#ifndef FASTEST
p = &s->prev[n];
do {
m = *--p;
Expand All @@ -938,6 +1010,7 @@ local void fill_window(s)
* its value will never be used.
*/
} while (--n);
#endif
more += wsize;
}
if (s->strm->avail_in == 0) return;
Expand Down Expand Up @@ -1105,14 +1178,15 @@ local block_state deflate_fast(s, flush)
if (s->match_length >= MIN_MATCH) {
check_match(s, s->strstart, s->match_start, s->match_length);

bflush = _tr_tally(s, s->strstart - s->match_start,
s->match_length - MIN_MATCH);
_tr_tally_dist(s, s->strstart - s->match_start,
s->match_length - MIN_MATCH, bflush);

s->lookahead -= s->match_length;

/* Insert new strings in the hash table only if the match length
* is not too large. This saves time but degrades compression.
*/
#ifndef FASTEST
if (s->match_length <= s->max_insert_length &&
s->lookahead >= MIN_MATCH) {
s->match_length--; /* string at strstart already in hash table */
Expand All @@ -1124,7 +1198,9 @@ local block_state deflate_fast(s, flush)
*/
} while (--s->match_length != 0);
s->strstart++;
} else {
} else
#endif
{
s->strstart += s->match_length;
s->match_length = 0;
s->ins_h = s->window[s->strstart];
Expand All @@ -1139,7 +1215,7 @@ local block_state deflate_fast(s, flush)
} else {
/* No match, output a literal byte */
Tracevv((stderr,"%c", s->window[s->strstart]));
bflush = _tr_tally (s, 0, s->window[s->strstart]);
_tr_tally_lit (s, s->window[s->strstart], bflush);
s->lookahead--;
s->strstart++;
}
Expand Down Expand Up @@ -1219,7 +1295,7 @@ local block_state deflate_slow(s, flush)
check_match(s, s->strstart-1, s->prev_match, s->prev_length);

bflush = _tr_tally(s, s->strstart -1 - s->prev_match,
s->prev_length - MIN_MATCH);
s->prev_length - MIN_MATCH);

/* Insert in hash table all strings up to the end of the match.
* strstart-1 and strstart are already inserted. If there is not
Expand All @@ -1245,7 +1321,8 @@ local block_state deflate_slow(s, flush)
* is longer, truncate the previous match to a single literal.
*/
Tracevv((stderr,"%c", s->window[s->strstart-1]));
if (_tr_tally (s, 0, s->window[s->strstart-1])) {
_tr_tally_lit(s, s->window[s->strstart-1], bflush);
if (bflush) {
FLUSH_BLOCK_ONLY(s, 0);
}
s->strstart++;
Expand All @@ -1263,7 +1340,7 @@ local block_state deflate_slow(s, flush)
Assert (flush != Z_NO_FLUSH, "no flush?");
if (s->match_available) {
Tracevv((stderr,"%c", s->window[s->strstart-1]));
_tr_tally (s, 0, s->window[s->strstart-1]);
_tr_tally_lit(s, s->window[s->strstart-1], bflush);
s->match_available = 0;
}
FLUSH_BLOCK(s, flush == Z_FINISH);
Expand Down
42 changes: 42 additions & 0 deletions deflate.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,46 @@ ulg _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
void _tr_align OF((deflate_state *s));
void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
int eof));

#define d_code(dist) \
((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
/* Mapping from a distance to a distance code. dist is the distance - 1 and
* must not have side effects. _dist_code[256] and _dist_code[257] are never
* used.
*/

#ifndef DEBUG
/* Inline versions of _tr_tally for speed: */

#if defined(GEN_TREES_H) || !defined(STDC)
extern uch _length_code[];
extern uch _dist_code[];
#else
extern const uch _length_code[];
extern const uch _dist_code[];
#endif

# define _tr_tally_lit(s, c, flush) \
{ uch cc = (c); \
s->d_buf[s->last_lit] = 0; \
s->l_buf[s->last_lit++] = cc; \
s->dyn_ltree[cc].Freq++; \
flush = (s->last_lit == s->lit_bufsize-1); \
}
# define _tr_tally_dist(s, distance, length, flush) \
{ uch len = (length); \
ush dist = (distance); \
s->d_buf[s->last_lit] = dist; \
s->l_buf[s->last_lit++] = len; \
dist--; \
s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
s->dyn_dtree[d_code(dist)].Freq++; \
flush = (s->last_lit == s->lit_bufsize-1); \
}
#else
# define _tr_tally_lit(s, c, flush) _tr_tally(s, 0, c, flush)
# define _tr_tally_dist(s, distance, length, flush) \
_tr_tally(s, distance, length, flush)
#endif

#endif
Loading

0 comments on commit 965fe72

Please sign in to comment.