rugged 0.21.4 → 0.22.0b1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -5
- data/ext/rugged/extconf.rb +9 -9
- data/ext/rugged/rugged.c +4 -2
- data/ext/rugged/rugged.h +3 -7
- data/ext/rugged/rugged_blob.c +57 -0
- data/ext/rugged/rugged_cred.c +23 -0
- data/ext/rugged/rugged_index.c +6 -2
- data/ext/rugged/rugged_remote.c +65 -52
- data/ext/rugged/rugged_remote_collection.c +59 -10
- data/ext/rugged/rugged_repo.c +345 -11
- data/ext/rugged/rugged_revwalk.c +10 -0
- data/ext/rugged/rugged_submodule.c +1042 -0
- data/ext/rugged/rugged_submodule_collection.c +236 -0
- data/ext/rugged/rugged_tag_collection.c +70 -2
- data/ext/rugged/rugged_tree.c +29 -10
- data/lib/rugged.rb +3 -0
- data/lib/rugged/attributes.rb +41 -0
- data/lib/rugged/blob.rb +28 -0
- data/lib/rugged/diff.rb +0 -1
- data/lib/rugged/diff/line.rb +1 -3
- data/lib/rugged/patch.rb +12 -2
- data/lib/rugged/repository.rb +7 -0
- data/lib/rugged/submodule_collection.rb +48 -0
- data/lib/rugged/version.rb +1 -1
- data/vendor/libgit2/CMakeLists.txt +27 -3
- data/vendor/libgit2/cmake/Modules/FindGSSAPI.cmake +324 -0
- data/vendor/libgit2/deps/http-parser/http_parser.h +2 -0
- data/vendor/libgit2/deps/zlib/adler32.c +39 -29
- data/vendor/libgit2/deps/zlib/crc32.c +33 -50
- data/vendor/libgit2/deps/zlib/crc32.h +1 -1
- data/vendor/libgit2/deps/zlib/deflate.c +198 -65
- data/vendor/libgit2/deps/zlib/deflate.h +8 -4
- data/vendor/libgit2/deps/zlib/infback.c +640 -0
- data/vendor/libgit2/deps/zlib/inffast.c +3 -3
- data/vendor/libgit2/deps/zlib/inffixed.h +3 -3
- data/vendor/libgit2/deps/zlib/inflate.c +84 -52
- data/vendor/libgit2/deps/zlib/inftrees.c +15 -39
- data/vendor/libgit2/deps/zlib/trees.c +18 -36
- data/vendor/libgit2/deps/zlib/zconf.h +4 -0
- data/vendor/libgit2/deps/zlib/zlib.h +250 -95
- data/vendor/libgit2/deps/zlib/zutil.c +13 -10
- data/vendor/libgit2/deps/zlib/zutil.h +41 -62
- data/vendor/libgit2/include/git2.h +4 -0
- data/vendor/libgit2/include/git2/annotated_commit.h +99 -0
- data/vendor/libgit2/include/git2/attr.h +16 -13
- data/vendor/libgit2/include/git2/branch.h +11 -0
- data/vendor/libgit2/include/git2/buffer.h +16 -0
- data/vendor/libgit2/include/git2/checkout.h +12 -12
- data/vendor/libgit2/include/git2/cherrypick.h +15 -15
- data/vendor/libgit2/include/git2/clone.h +77 -69
- data/vendor/libgit2/include/git2/common.h +13 -1
- data/vendor/libgit2/include/git2/config.h +0 -14
- data/vendor/libgit2/include/git2/describe.h +162 -0
- data/vendor/libgit2/include/git2/diff.h +13 -8
- data/vendor/libgit2/include/git2/errors.h +5 -0
- data/vendor/libgit2/include/git2/global.h +38 -0
- data/vendor/libgit2/include/git2/merge.h +38 -64
- data/vendor/libgit2/include/git2/net.h +2 -2
- data/vendor/libgit2/include/git2/notes.h +17 -0
- data/vendor/libgit2/include/git2/oid.h +8 -4
- data/vendor/libgit2/include/git2/oidarray.h +40 -0
- data/vendor/libgit2/include/git2/rebase.h +261 -0
- data/vendor/libgit2/include/git2/reflog.h +1 -1
- data/vendor/libgit2/include/git2/remote.h +25 -47
- data/vendor/libgit2/include/git2/repository.h +4 -1
- data/vendor/libgit2/include/git2/reset.h +10 -1
- data/vendor/libgit2/include/git2/revert.h +1 -1
- data/vendor/libgit2/include/git2/revwalk.h +28 -23
- data/vendor/libgit2/include/git2/status.h +19 -15
- data/vendor/libgit2/include/git2/submodule.h +18 -0
- data/vendor/libgit2/include/git2/sys/config.h +0 -1
- data/vendor/libgit2/{src → include/git2/sys}/hashsig.h +11 -7
- data/vendor/libgit2/include/git2/sys/refdb_backend.h +13 -0
- data/vendor/libgit2/include/git2/sys/refs.h +0 -11
- data/vendor/libgit2/include/git2/sys/repository.h +13 -0
- data/vendor/libgit2/include/git2/sys/transport.h +352 -0
- data/vendor/libgit2/include/git2/threads.h +10 -20
- data/vendor/libgit2/include/git2/transaction.h +111 -0
- data/vendor/libgit2/include/git2/transport.h +79 -313
- data/vendor/libgit2/include/git2/tree.h +4 -2
- data/vendor/libgit2/include/git2/types.h +77 -8
- data/vendor/libgit2/include/git2/version.h +2 -2
- data/vendor/libgit2/src/annotated_commit.c +121 -0
- data/vendor/libgit2/src/annotated_commit.h +22 -0
- data/vendor/libgit2/src/attr.c +8 -4
- data/vendor/libgit2/src/attr_file.c +24 -2
- data/vendor/libgit2/src/blame.c +0 -1
- data/vendor/libgit2/src/branch.c +32 -3
- data/vendor/libgit2/src/buf_text.c +9 -5
- data/vendor/libgit2/src/buf_text.h +3 -2
- data/vendor/libgit2/src/buffer.c +67 -10
- data/vendor/libgit2/src/buffer.h +4 -2
- data/vendor/libgit2/src/cache.c +9 -9
- data/vendor/libgit2/src/cache.h +1 -1
- data/vendor/libgit2/src/cc-compat.h +2 -0
- data/vendor/libgit2/src/checkout.c +263 -82
- data/vendor/libgit2/src/checkout.h +1 -0
- data/vendor/libgit2/src/cherrypick.c +41 -44
- data/vendor/libgit2/src/clone.c +96 -58
- data/vendor/libgit2/src/commit.c +5 -31
- data/vendor/libgit2/src/commit_list.h +3 -1
- data/vendor/libgit2/src/config.c +0 -17
- data/vendor/libgit2/src/config_cache.c +0 -2
- data/vendor/libgit2/src/config_file.c +12 -15
- data/vendor/libgit2/src/crlf.c +2 -1
- data/vendor/libgit2/src/describe.c +886 -0
- data/vendor/libgit2/src/diff.c +29 -3
- data/vendor/libgit2/src/diff_file.c +1 -0
- data/vendor/libgit2/src/diff_patch.c +2 -3
- data/vendor/libgit2/src/diff_print.c +11 -9
- data/vendor/libgit2/src/diff_tform.c +4 -4
- data/vendor/libgit2/src/errors.c +9 -7
- data/vendor/libgit2/src/fetch.c +6 -6
- data/vendor/libgit2/src/fetchhead.h +2 -4
- data/vendor/libgit2/src/filebuf.c +0 -2
- data/vendor/libgit2/src/filebuf.h +2 -3
- data/vendor/libgit2/src/fileops.c +9 -7
- data/vendor/libgit2/src/global.c +44 -35
- data/vendor/libgit2/src/global.h +2 -0
- data/vendor/libgit2/src/graph.c +2 -2
- data/vendor/libgit2/src/hash.h +3 -1
- data/vendor/libgit2/src/hash/hash_common_crypto.h +44 -0
- data/vendor/libgit2/src/hash/hash_win32.c +1 -1
- data/vendor/libgit2/src/hashsig.c +1 -1
- data/vendor/libgit2/src/ignore.c +5 -88
- data/vendor/libgit2/src/index.c +70 -57
- data/vendor/libgit2/src/index.h +1 -0
- data/vendor/libgit2/src/indexer.c +16 -5
- data/vendor/libgit2/src/iterator.c +70 -1
- data/vendor/libgit2/src/iterator.h +5 -1
- data/vendor/libgit2/src/map.h +0 -1
- data/vendor/libgit2/src/merge.c +203 -327
- data/vendor/libgit2/src/merge.h +3 -13
- data/vendor/libgit2/src/mwindow.c +119 -8
- data/vendor/libgit2/src/mwindow.h +9 -1
- data/vendor/libgit2/src/netops.c +7 -8
- data/vendor/libgit2/src/netops.h +6 -16
- data/vendor/libgit2/src/notes.c +31 -4
- data/vendor/libgit2/src/notes.h +3 -0
- data/vendor/libgit2/src/odb.c +23 -1
- data/vendor/libgit2/src/odb_loose.c +1 -1
- data/vendor/libgit2/src/odb_pack.c +6 -3
- data/vendor/libgit2/src/oid.c +9 -1
- data/vendor/libgit2/src/oid.h +11 -0
- data/vendor/libgit2/src/oidarray.c +21 -0
- data/vendor/libgit2/src/oidarray.h +18 -0
- data/vendor/libgit2/src/oidmap.h +16 -0
- data/vendor/libgit2/src/pack.c +20 -7
- data/vendor/libgit2/src/pack.h +3 -0
- data/vendor/libgit2/src/path.c +120 -293
- data/vendor/libgit2/src/path.h +21 -44
- data/vendor/libgit2/src/pathspec.c +1 -1
- data/vendor/libgit2/src/pool.c +5 -11
- data/vendor/libgit2/src/pool.h +0 -2
- data/vendor/libgit2/src/posix.c +6 -6
- data/vendor/libgit2/src/posix.h +48 -28
- data/vendor/libgit2/src/push.c +19 -48
- data/vendor/libgit2/src/push.h +2 -4
- data/vendor/libgit2/src/rebase.c +1125 -0
- data/vendor/libgit2/src/refdb.c +19 -0
- data/vendor/libgit2/src/refdb.h +2 -1
- data/vendor/libgit2/src/refdb_fs.c +101 -29
- data/vendor/libgit2/src/reflog.c +1 -1
- data/vendor/libgit2/src/refs.c +38 -3
- data/vendor/libgit2/src/refs.h +13 -2
- data/vendor/libgit2/src/refspec.c +20 -2
- data/vendor/libgit2/src/remote.c +288 -154
- data/vendor/libgit2/src/remote.h +5 -1
- data/vendor/libgit2/src/repository.c +75 -36
- data/vendor/libgit2/src/repository.h +3 -25
- data/vendor/libgit2/src/reset.c +5 -1
- data/vendor/libgit2/src/revert.c +4 -6
- data/vendor/libgit2/src/revparse.c +15 -18
- data/vendor/libgit2/src/revwalk.c +96 -22
- data/vendor/libgit2/src/revwalk.h +5 -4
- data/vendor/libgit2/src/settings.c +22 -0
- data/vendor/libgit2/src/signature.c +37 -2
- data/vendor/libgit2/src/signature.h +3 -0
- data/vendor/libgit2/src/stash.c +17 -12
- data/vendor/libgit2/src/status.c +13 -3
- data/vendor/libgit2/src/strnlen.h +2 -1
- data/vendor/libgit2/src/submodule.c +75 -35
- data/vendor/libgit2/src/thread-utils.h +4 -9
- data/vendor/libgit2/src/trace.h +9 -1
- data/vendor/libgit2/src/transaction.c +352 -0
- data/vendor/libgit2/src/transport.c +91 -97
- data/vendor/libgit2/src/transports/auth.c +71 -0
- data/vendor/libgit2/src/transports/auth.h +63 -0
- data/vendor/libgit2/src/transports/auth_negotiate.c +275 -0
- data/vendor/libgit2/src/transports/auth_negotiate.h +27 -0
- data/vendor/libgit2/src/transports/cred.c +58 -0
- data/vendor/libgit2/src/transports/cred.h +14 -0
- data/vendor/libgit2/src/transports/cred_helpers.c +3 -0
- data/vendor/libgit2/src/transports/git.c +1 -0
- data/vendor/libgit2/src/transports/http.c +208 -82
- data/vendor/libgit2/src/transports/local.c +2 -2
- data/vendor/libgit2/src/transports/smart.c +2 -0
- data/vendor/libgit2/src/transports/smart.h +2 -0
- data/vendor/libgit2/src/transports/smart_protocol.c +10 -10
- data/vendor/libgit2/src/transports/ssh.c +243 -57
- data/vendor/libgit2/src/transports/winhttp.c +139 -35
- data/vendor/libgit2/src/tree-cache.c +118 -31
- data/vendor/libgit2/src/tree-cache.h +12 -7
- data/vendor/libgit2/src/tree.c +83 -64
- data/vendor/libgit2/src/tree.h +2 -3
- data/vendor/libgit2/src/unix/map.c +8 -2
- data/vendor/libgit2/src/unix/posix.h +23 -9
- data/vendor/libgit2/src/unix/realpath.c +8 -7
- data/vendor/libgit2/src/userdiff.h +3 -3
- data/vendor/libgit2/src/util.c +2 -92
- data/vendor/libgit2/src/util.h +3 -15
- data/vendor/libgit2/src/win32/findfile.c +0 -1
- data/vendor/libgit2/src/win32/map.c +3 -2
- data/vendor/libgit2/src/win32/mingw-compat.h +5 -12
- data/vendor/libgit2/src/win32/msvc-compat.h +3 -32
- data/vendor/libgit2/src/win32/posix.h +20 -32
- data/vendor/libgit2/src/win32/posix_w32.c +103 -31
- data/vendor/libgit2/src/win32/utf-conv.c +6 -36
- data/vendor/libgit2/src/win32/utf-conv.h +39 -0
- data/vendor/libgit2/src/win32/w32_util.h +0 -1
- metadata +32 -7
- data/vendor/libgit2/src/win32/path_w32.c +0 -305
- data/vendor/libgit2/src/win32/path_w32.h +0 -82
@@ -1,5 +1,5 @@
|
|
1
1
|
/* adler32.c -- compute the Adler-32 checksum of a data stream
|
2
|
-
* Copyright (C) 1995-
|
2
|
+
* Copyright (C) 1995-2011 Mark Adler
|
3
3
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
4
4
|
*/
|
5
5
|
|
@@ -9,9 +9,9 @@
|
|
9
9
|
|
10
10
|
#define local static
|
11
11
|
|
12
|
-
local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2);
|
12
|
+
local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
|
13
13
|
|
14
|
-
#define BASE
|
14
|
+
#define BASE 65521 /* largest prime smaller than 65536 */
|
15
15
|
#define NMAX 5552
|
16
16
|
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
|
17
17
|
|
@@ -21,39 +21,44 @@ local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2);
|
|
21
21
|
#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
|
22
22
|
#define DO16(buf) DO8(buf,0); DO8(buf,8);
|
23
23
|
|
24
|
-
/* use NO_DIVIDE if your processor does not do division in hardware
|
24
|
+
/* use NO_DIVIDE if your processor does not do division in hardware --
|
25
|
+
try it both ways to see which is faster */
|
25
26
|
#ifdef NO_DIVIDE
|
26
|
-
|
27
|
+
/* note that this assumes BASE is 65521, where 65536 % 65521 == 15
|
28
|
+
(thank you to John Reiser for pointing this out) */
|
29
|
+
# define CHOP(a) \
|
30
|
+
do { \
|
31
|
+
unsigned long tmp = a >> 16; \
|
32
|
+
a &= 0xffffUL; \
|
33
|
+
a += (tmp << 4) - tmp; \
|
34
|
+
} while (0)
|
35
|
+
# define MOD28(a) \
|
27
36
|
do { \
|
28
|
-
|
29
|
-
if (a >= (BASE << 15)) a -= (BASE << 15); \
|
30
|
-
if (a >= (BASE << 14)) a -= (BASE << 14); \
|
31
|
-
if (a >= (BASE << 13)) a -= (BASE << 13); \
|
32
|
-
if (a >= (BASE << 12)) a -= (BASE << 12); \
|
33
|
-
if (a >= (BASE << 11)) a -= (BASE << 11); \
|
34
|
-
if (a >= (BASE << 10)) a -= (BASE << 10); \
|
35
|
-
if (a >= (BASE << 9)) a -= (BASE << 9); \
|
36
|
-
if (a >= (BASE << 8)) a -= (BASE << 8); \
|
37
|
-
if (a >= (BASE << 7)) a -= (BASE << 7); \
|
38
|
-
if (a >= (BASE << 6)) a -= (BASE << 6); \
|
39
|
-
if (a >= (BASE << 5)) a -= (BASE << 5); \
|
40
|
-
if (a >= (BASE << 4)) a -= (BASE << 4); \
|
41
|
-
if (a >= (BASE << 3)) a -= (BASE << 3); \
|
42
|
-
if (a >= (BASE << 2)) a -= (BASE << 2); \
|
43
|
-
if (a >= (BASE << 1)) a -= (BASE << 1); \
|
37
|
+
CHOP(a); \
|
44
38
|
if (a >= BASE) a -= BASE; \
|
45
39
|
} while (0)
|
46
|
-
# define
|
40
|
+
# define MOD(a) \
|
47
41
|
do { \
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
42
|
+
CHOP(a); \
|
43
|
+
MOD28(a); \
|
44
|
+
} while (0)
|
45
|
+
# define MOD63(a) \
|
46
|
+
do { /* this assumes a is not negative */ \
|
47
|
+
z_off64_t tmp = a >> 32; \
|
48
|
+
a &= 0xffffffffL; \
|
49
|
+
a += (tmp << 8) - (tmp << 5) + tmp; \
|
50
|
+
tmp = a >> 16; \
|
51
|
+
a &= 0xffffL; \
|
52
|
+
a += (tmp << 4) - tmp; \
|
53
|
+
tmp = a >> 16; \
|
54
|
+
a &= 0xffffL; \
|
55
|
+
a += (tmp << 4) - tmp; \
|
52
56
|
if (a >= BASE) a -= BASE; \
|
53
57
|
} while (0)
|
54
58
|
#else
|
55
59
|
# define MOD(a) a %= BASE
|
56
|
-
# define
|
60
|
+
# define MOD28(a) a %= BASE
|
61
|
+
# define MOD63(a) a %= BASE
|
57
62
|
#endif
|
58
63
|
|
59
64
|
/* ========================================================================= */
|
@@ -92,7 +97,7 @@ uLong ZEXPORT adler32(adler, buf, len)
|
|
92
97
|
}
|
93
98
|
if (adler >= BASE)
|
94
99
|
adler -= BASE;
|
95
|
-
|
100
|
+
MOD28(sum2); /* only added so many BASE's */
|
96
101
|
return adler | (sum2 << 16);
|
97
102
|
}
|
98
103
|
|
@@ -137,8 +142,13 @@ local uLong adler32_combine_(adler1, adler2, len2)
|
|
137
142
|
unsigned long sum2;
|
138
143
|
unsigned rem;
|
139
144
|
|
145
|
+
/* for negative len, return invalid adler32 as a clue for debugging */
|
146
|
+
if (len2 < 0)
|
147
|
+
return 0xffffffffUL;
|
148
|
+
|
140
149
|
/* the derivation of this formula is left as an exercise for the reader */
|
141
|
-
|
150
|
+
MOD63(len2); /* assumes len2 >= 0 */
|
151
|
+
rem = (unsigned)len2;
|
142
152
|
sum1 = adler1 & 0xffff;
|
143
153
|
sum2 = rem * sum1;
|
144
154
|
MOD(sum2);
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/* crc32.c -- compute the CRC-32 of a data stream
|
2
|
-
* Copyright (C) 1995-2006, 2010 Mark Adler
|
2
|
+
* Copyright (C) 1995-2006, 2010, 2011, 2012 Mark Adler
|
3
3
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
4
4
|
*
|
5
5
|
* Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster
|
@@ -17,6 +17,8 @@
|
|
17
17
|
of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should
|
18
18
|
first call get_crc_table() to initialize the tables before allowing more than
|
19
19
|
one thread to use crc32().
|
20
|
+
|
21
|
+
DYNAMIC_CRC_TABLE and MAKECRCH can be #defined to write out crc32.h.
|
20
22
|
*/
|
21
23
|
|
22
24
|
#ifdef MAKECRCH
|
@@ -30,31 +32,11 @@
|
|
30
32
|
|
31
33
|
#define local static
|
32
34
|
|
33
|
-
/* Find a four-byte integer type for crc32_little() and crc32_big(). */
|
34
|
-
#ifndef NOBYFOUR
|
35
|
-
# ifdef STDC /* need ANSI C limits.h to determine sizes */
|
36
|
-
# include <limits.h>
|
37
|
-
# define BYFOUR
|
38
|
-
# if (UINT_MAX == 0xffffffffUL)
|
39
|
-
typedef unsigned int u4;
|
40
|
-
# else
|
41
|
-
# if (ULONG_MAX == 0xffffffffUL)
|
42
|
-
typedef unsigned long u4;
|
43
|
-
# else
|
44
|
-
# if (USHRT_MAX == 0xffffffffUL)
|
45
|
-
typedef unsigned short u4;
|
46
|
-
# else
|
47
|
-
# undef BYFOUR /* can't find a four-byte integer type! */
|
48
|
-
# endif
|
49
|
-
# endif
|
50
|
-
# endif
|
51
|
-
# endif /* STDC */
|
52
|
-
#endif /* !NOBYFOUR */
|
53
|
-
|
54
35
|
/* Definitions for doing the crc four data bytes at a time. */
|
36
|
+
#if !defined(NOBYFOUR) && defined(Z_U4)
|
37
|
+
# define BYFOUR
|
38
|
+
#endif
|
55
39
|
#ifdef BYFOUR
|
56
|
-
# define REV(w) ((((w)>>24)&0xff)+(((w)>>8)&0xff00)+ \
|
57
|
-
(((w)&0xff00)<<8)+(((w)&0xff)<<24))
|
58
40
|
local unsigned long crc32_little OF((unsigned long,
|
59
41
|
const unsigned char FAR *, unsigned));
|
60
42
|
local unsigned long crc32_big OF((unsigned long,
|
@@ -68,16 +50,16 @@
|
|
68
50
|
local unsigned long gf2_matrix_times OF((unsigned long *mat,
|
69
51
|
unsigned long vec));
|
70
52
|
local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
|
71
|
-
local uLong crc32_combine_(uLong crc1, uLong crc2, z_off64_t len2);
|
53
|
+
local uLong crc32_combine_ OF((uLong crc1, uLong crc2, z_off64_t len2));
|
72
54
|
|
73
55
|
|
74
56
|
#ifdef DYNAMIC_CRC_TABLE
|
75
57
|
|
76
58
|
local volatile int crc_table_empty = 1;
|
77
|
-
local
|
59
|
+
local z_crc_t FAR crc_table[TBLS][256];
|
78
60
|
local void make_crc_table OF((void));
|
79
61
|
#ifdef MAKECRCH
|
80
|
-
local void write_table OF((FILE *, const
|
62
|
+
local void write_table OF((FILE *, const z_crc_t FAR *));
|
81
63
|
#endif /* MAKECRCH */
|
82
64
|
/*
|
83
65
|
Generate tables for a byte-wise 32-bit CRC calculation on the polynomial:
|
@@ -107,9 +89,9 @@ local void make_crc_table OF((void));
|
|
107
89
|
*/
|
108
90
|
local void make_crc_table()
|
109
91
|
{
|
110
|
-
|
92
|
+
z_crc_t c;
|
111
93
|
int n, k;
|
112
|
-
|
94
|
+
z_crc_t poly; /* polynomial exclusive-or pattern */
|
113
95
|
/* terms of polynomial defining this crc (except x^32): */
|
114
96
|
static volatile int first = 1; /* flag to limit concurrent making */
|
115
97
|
static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
|
@@ -121,13 +103,13 @@ local void make_crc_table()
|
|
121
103
|
first = 0;
|
122
104
|
|
123
105
|
/* make exclusive-or pattern from polynomial (0xedb88320UL) */
|
124
|
-
poly =
|
125
|
-
for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
|
126
|
-
poly |=
|
106
|
+
poly = 0;
|
107
|
+
for (n = 0; n < (int)(sizeof(p)/sizeof(unsigned char)); n++)
|
108
|
+
poly |= (z_crc_t)1 << (31 - p[n]);
|
127
109
|
|
128
110
|
/* generate a crc for every 8-bit value */
|
129
111
|
for (n = 0; n < 256; n++) {
|
130
|
-
c = (
|
112
|
+
c = (z_crc_t)n;
|
131
113
|
for (k = 0; k < 8; k++)
|
132
114
|
c = c & 1 ? poly ^ (c >> 1) : c >> 1;
|
133
115
|
crc_table[0][n] = c;
|
@@ -138,11 +120,11 @@ local void make_crc_table()
|
|
138
120
|
and then the byte reversal of those as well as the first table */
|
139
121
|
for (n = 0; n < 256; n++) {
|
140
122
|
c = crc_table[0][n];
|
141
|
-
crc_table[4][n] =
|
123
|
+
crc_table[4][n] = ZSWAP32(c);
|
142
124
|
for (k = 1; k < 4; k++) {
|
143
125
|
c = crc_table[0][c & 0xff] ^ (c >> 8);
|
144
126
|
crc_table[k][n] = c;
|
145
|
-
crc_table[k + 4][n] =
|
127
|
+
crc_table[k + 4][n] = ZSWAP32(c);
|
146
128
|
}
|
147
129
|
}
|
148
130
|
#endif /* BYFOUR */
|
@@ -164,7 +146,7 @@ local void make_crc_table()
|
|
164
146
|
if (out == NULL) return;
|
165
147
|
fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
|
166
148
|
fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
|
167
|
-
fprintf(out, "local const
|
149
|
+
fprintf(out, "local const z_crc_t FAR ");
|
168
150
|
fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
|
169
151
|
write_table(out, crc_table[0]);
|
170
152
|
# ifdef BYFOUR
|
@@ -184,12 +166,13 @@ local void make_crc_table()
|
|
184
166
|
#ifdef MAKECRCH
|
185
167
|
local void write_table(out, table)
|
186
168
|
FILE *out;
|
187
|
-
const
|
169
|
+
const z_crc_t FAR *table;
|
188
170
|
{
|
189
171
|
int n;
|
190
172
|
|
191
173
|
for (n = 0; n < 256; n++)
|
192
|
-
fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ",
|
174
|
+
fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ",
|
175
|
+
(unsigned long)(table[n]),
|
193
176
|
n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
|
194
177
|
}
|
195
178
|
#endif /* MAKECRCH */
|
@@ -204,13 +187,13 @@ local void write_table(out, table)
|
|
204
187
|
/* =========================================================================
|
205
188
|
* This function can be used by asm versions of crc32()
|
206
189
|
*/
|
207
|
-
const
|
190
|
+
const z_crc_t FAR * ZEXPORT get_crc_table()
|
208
191
|
{
|
209
192
|
#ifdef DYNAMIC_CRC_TABLE
|
210
193
|
if (crc_table_empty)
|
211
194
|
make_crc_table();
|
212
195
|
#endif /* DYNAMIC_CRC_TABLE */
|
213
|
-
return (const
|
196
|
+
return (const z_crc_t FAR *)crc_table;
|
214
197
|
}
|
215
198
|
|
216
199
|
/* ========================================================================= */
|
@@ -232,7 +215,7 @@ unsigned long ZEXPORT crc32(crc, buf, len)
|
|
232
215
|
|
233
216
|
#ifdef BYFOUR
|
234
217
|
if (sizeof(void *) == sizeof(ptrdiff_t)) {
|
235
|
-
|
218
|
+
z_crc_t endian;
|
236
219
|
|
237
220
|
endian = 1;
|
238
221
|
if (*((unsigned char *)(&endian)))
|
@@ -266,17 +249,17 @@ local unsigned long crc32_little(crc, buf, len)
|
|
266
249
|
const unsigned char FAR *buf;
|
267
250
|
unsigned len;
|
268
251
|
{
|
269
|
-
register
|
270
|
-
register const
|
252
|
+
register z_crc_t c;
|
253
|
+
register const z_crc_t FAR *buf4;
|
271
254
|
|
272
|
-
c = (
|
255
|
+
c = (z_crc_t)crc;
|
273
256
|
c = ~c;
|
274
257
|
while (len && ((ptrdiff_t)buf & 3)) {
|
275
258
|
c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
|
276
259
|
len--;
|
277
260
|
}
|
278
261
|
|
279
|
-
buf4 = (const
|
262
|
+
buf4 = (const z_crc_t FAR *)(const void FAR *)buf;
|
280
263
|
while (len >= 32) {
|
281
264
|
DOLIT32;
|
282
265
|
len -= 32;
|
@@ -306,17 +289,17 @@ local unsigned long crc32_big(crc, buf, len)
|
|
306
289
|
const unsigned char FAR *buf;
|
307
290
|
unsigned len;
|
308
291
|
{
|
309
|
-
register
|
310
|
-
register const
|
292
|
+
register z_crc_t c;
|
293
|
+
register const z_crc_t FAR *buf4;
|
311
294
|
|
312
|
-
c =
|
295
|
+
c = ZSWAP32((z_crc_t)crc);
|
313
296
|
c = ~c;
|
314
297
|
while (len && ((ptrdiff_t)buf & 3)) {
|
315
298
|
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
|
316
299
|
len--;
|
317
300
|
}
|
318
301
|
|
319
|
-
buf4 = (const
|
302
|
+
buf4 = (const z_crc_t FAR *)(const void FAR *)buf;
|
320
303
|
buf4--;
|
321
304
|
while (len >= 32) {
|
322
305
|
DOBIG32;
|
@@ -333,7 +316,7 @@ local unsigned long crc32_big(crc, buf, len)
|
|
333
316
|
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
|
334
317
|
} while (--len);
|
335
318
|
c = ~c;
|
336
|
-
return (unsigned long)(
|
319
|
+
return (unsigned long)(ZSWAP32(c));
|
337
320
|
}
|
338
321
|
|
339
322
|
#endif /* BYFOUR */
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/* deflate.c -- compress data using the deflation algorithm
|
2
|
-
* Copyright (C) 1995-
|
2
|
+
* Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler
|
3
3
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
4
4
|
*/
|
5
5
|
|
@@ -37,7 +37,7 @@
|
|
37
37
|
* REFERENCES
|
38
38
|
*
|
39
39
|
* Deutsch, L.P.,"DEFLATE Compressed Data Format Specification".
|
40
|
-
* Available in http://
|
40
|
+
* Available in http://tools.ietf.org/html/rfc1951
|
41
41
|
*
|
42
42
|
* A description of the Rabin and Karp algorithm is given in the book
|
43
43
|
* "Algorithms" by R. Sedgewick, Addison-Wesley, p252.
|
@@ -52,7 +52,7 @@
|
|
52
52
|
#include "deflate.h"
|
53
53
|
|
54
54
|
const char deflate_copyright[] =
|
55
|
-
" deflate 1.2.
|
55
|
+
" deflate 1.2.8 Copyright 1995-2013 Jean-loup Gailly and Mark Adler ";
|
56
56
|
/*
|
57
57
|
If you use the zlib library in a product, an acknowledgment is welcome
|
58
58
|
in the documentation of your product. If for some reason you cannot
|
@@ -155,6 +155,9 @@ local const config configuration_table[10] = {
|
|
155
155
|
struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
|
156
156
|
#endif
|
157
157
|
|
158
|
+
/* rank Z_BLOCK between Z_NO_FLUSH and Z_PARTIAL_FLUSH */
|
159
|
+
#define RANK(f) (((f) << 1) - ((f) > 4 ? 9 : 0))
|
160
|
+
|
158
161
|
/* ===========================================================================
|
159
162
|
* Update a hash value with the given input byte
|
160
163
|
* IN assertion: all calls to to UPDATE_HASH are made with consecutive
|
@@ -235,10 +238,19 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
|
|
235
238
|
|
236
239
|
strm->msg = Z_NULL;
|
237
240
|
if (strm->zalloc == (alloc_func)0) {
|
241
|
+
#ifdef Z_SOLO
|
242
|
+
return Z_STREAM_ERROR;
|
243
|
+
#else
|
238
244
|
strm->zalloc = zcalloc;
|
239
245
|
strm->opaque = (voidpf)0;
|
246
|
+
#endif
|
240
247
|
}
|
241
|
-
if (strm->zfree == (free_func)0)
|
248
|
+
if (strm->zfree == (free_func)0)
|
249
|
+
#ifdef Z_SOLO
|
250
|
+
return Z_STREAM_ERROR;
|
251
|
+
#else
|
252
|
+
strm->zfree = zcfree;
|
253
|
+
#endif
|
242
254
|
|
243
255
|
#ifdef FASTEST
|
244
256
|
if (level != 0) level = 1;
|
@@ -293,7 +305,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
|
|
293
305
|
if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
|
294
306
|
s->pending_buf == Z_NULL) {
|
295
307
|
s->status = FINISH_STATE;
|
296
|
-
strm->msg =
|
308
|
+
strm->msg = ERR_MSG(Z_MEM_ERROR);
|
297
309
|
deflateEnd (strm);
|
298
310
|
return Z_MEM_ERROR;
|
299
311
|
}
|
@@ -314,43 +326,70 @@ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
|
|
314
326
|
uInt dictLength;
|
315
327
|
{
|
316
328
|
deflate_state *s;
|
317
|
-
uInt
|
318
|
-
|
319
|
-
|
329
|
+
uInt str, n;
|
330
|
+
int wrap;
|
331
|
+
unsigned avail;
|
332
|
+
z_const unsigned char *next;
|
320
333
|
|
321
|
-
if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL
|
322
|
-
strm->state->wrap == 2 ||
|
323
|
-
(strm->state->wrap == 1 && strm->state->status != INIT_STATE))
|
334
|
+
if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL)
|
324
335
|
return Z_STREAM_ERROR;
|
325
|
-
|
326
336
|
s = strm->state;
|
327
|
-
|
328
|
-
|
337
|
+
wrap = s->wrap;
|
338
|
+
if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead)
|
339
|
+
return Z_STREAM_ERROR;
|
329
340
|
|
330
|
-
|
331
|
-
if (
|
332
|
-
|
333
|
-
|
341
|
+
/* when using zlib wrappers, compute Adler-32 for provided dictionary */
|
342
|
+
if (wrap == 1)
|
343
|
+
strm->adler = adler32(strm->adler, dictionary, dictLength);
|
344
|
+
s->wrap = 0; /* avoid computing Adler-32 in read_buf */
|
345
|
+
|
346
|
+
/* if dictionary would fill window, just replace the history */
|
347
|
+
if (dictLength >= s->w_size) {
|
348
|
+
if (wrap == 0) { /* already empty otherwise */
|
349
|
+
CLEAR_HASH(s);
|
350
|
+
s->strstart = 0;
|
351
|
+
s->block_start = 0L;
|
352
|
+
s->insert = 0;
|
353
|
+
}
|
354
|
+
dictionary += dictLength - s->w_size; /* use the tail */
|
355
|
+
dictLength = s->w_size;
|
334
356
|
}
|
335
|
-
zmemcpy(s->window, dictionary, length);
|
336
|
-
s->strstart = length;
|
337
|
-
s->block_start = (long)length;
|
338
357
|
|
339
|
-
/*
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
358
|
+
/* insert dictionary into window and hash */
|
359
|
+
avail = strm->avail_in;
|
360
|
+
next = strm->next_in;
|
361
|
+
strm->avail_in = dictLength;
|
362
|
+
strm->next_in = (z_const Bytef *)dictionary;
|
363
|
+
fill_window(s);
|
364
|
+
while (s->lookahead >= MIN_MATCH) {
|
365
|
+
str = s->strstart;
|
366
|
+
n = s->lookahead - (MIN_MATCH-1);
|
367
|
+
do {
|
368
|
+
UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
|
369
|
+
#ifndef FASTEST
|
370
|
+
s->prev[str & s->w_mask] = s->head[s->ins_h];
|
371
|
+
#endif
|
372
|
+
s->head[s->ins_h] = (Pos)str;
|
373
|
+
str++;
|
374
|
+
} while (--n);
|
375
|
+
s->strstart = str;
|
376
|
+
s->lookahead = MIN_MATCH-1;
|
377
|
+
fill_window(s);
|
347
378
|
}
|
348
|
-
|
379
|
+
s->strstart += s->lookahead;
|
380
|
+
s->block_start = (long)s->strstart;
|
381
|
+
s->insert = s->lookahead;
|
382
|
+
s->lookahead = 0;
|
383
|
+
s->match_length = s->prev_length = MIN_MATCH-1;
|
384
|
+
s->match_available = 0;
|
385
|
+
strm->next_in = next;
|
386
|
+
strm->avail_in = avail;
|
387
|
+
s->wrap = wrap;
|
349
388
|
return Z_OK;
|
350
389
|
}
|
351
390
|
|
352
391
|
/* ========================================================================= */
|
353
|
-
int ZEXPORT
|
392
|
+
int ZEXPORT deflateResetKeep (strm)
|
354
393
|
z_streamp strm;
|
355
394
|
{
|
356
395
|
deflate_state *s;
|
@@ -380,11 +419,22 @@ int ZEXPORT deflateReset (strm)
|
|
380
419
|
s->last_flush = Z_NO_FLUSH;
|
381
420
|
|
382
421
|
_tr_init(s);
|
383
|
-
lm_init(s);
|
384
422
|
|
385
423
|
return Z_OK;
|
386
424
|
}
|
387
425
|
|
426
|
+
/* ========================================================================= */
|
427
|
+
int ZEXPORT deflateReset (strm)
|
428
|
+
z_streamp strm;
|
429
|
+
{
|
430
|
+
int ret;
|
431
|
+
|
432
|
+
ret = deflateResetKeep(strm);
|
433
|
+
if (ret == Z_OK)
|
434
|
+
lm_init(strm->state);
|
435
|
+
return ret;
|
436
|
+
}
|
437
|
+
|
388
438
|
/* ========================================================================= */
|
389
439
|
int ZEXPORT deflateSetHeader (strm, head)
|
390
440
|
z_streamp strm;
|
@@ -396,15 +446,43 @@ int ZEXPORT deflateSetHeader (strm, head)
|
|
396
446
|
return Z_OK;
|
397
447
|
}
|
398
448
|
|
449
|
+
/* ========================================================================= */
|
450
|
+
int ZEXPORT deflatePending (strm, pending, bits)
|
451
|
+
unsigned *pending;
|
452
|
+
int *bits;
|
453
|
+
z_streamp strm;
|
454
|
+
{
|
455
|
+
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
|
456
|
+
if (pending != Z_NULL)
|
457
|
+
*pending = strm->state->pending;
|
458
|
+
if (bits != Z_NULL)
|
459
|
+
*bits = strm->state->bi_valid;
|
460
|
+
return Z_OK;
|
461
|
+
}
|
462
|
+
|
399
463
|
/* ========================================================================= */
|
400
464
|
int ZEXPORT deflatePrime (strm, bits, value)
|
401
465
|
z_streamp strm;
|
402
466
|
int bits;
|
403
467
|
int value;
|
404
468
|
{
|
469
|
+
deflate_state *s;
|
470
|
+
int put;
|
471
|
+
|
405
472
|
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
|
406
|
-
strm->state
|
407
|
-
|
473
|
+
s = strm->state;
|
474
|
+
if ((Bytef *)(s->d_buf) < s->pending_out + ((Buf_size + 7) >> 3))
|
475
|
+
return Z_BUF_ERROR;
|
476
|
+
do {
|
477
|
+
put = Buf_size - s->bi_valid;
|
478
|
+
if (put > bits)
|
479
|
+
put = bits;
|
480
|
+
s->bi_buf |= (ush)((value & ((1 << put) - 1)) << s->bi_valid);
|
481
|
+
s->bi_valid += put;
|
482
|
+
_tr_flush_bits(s);
|
483
|
+
value >>= put;
|
484
|
+
bits -= put;
|
485
|
+
} while (bits);
|
408
486
|
return Z_OK;
|
409
487
|
}
|
410
488
|
|
@@ -435,6 +513,8 @@ int ZEXPORT deflateParams(strm, level, strategy)
|
|
435
513
|
strm->total_in != 0) {
|
436
514
|
/* Flush the last buffer: */
|
437
515
|
err = deflate(strm, Z_BLOCK);
|
516
|
+
if (err == Z_BUF_ERROR && s->pending == 0)
|
517
|
+
err = Z_OK;
|
438
518
|
}
|
439
519
|
if (s->level != level) {
|
440
520
|
s->level = level;
|
@@ -562,19 +642,22 @@ local void putShortMSB (s, b)
|
|
562
642
|
local void flush_pending(strm)
|
563
643
|
z_streamp strm;
|
564
644
|
{
|
565
|
-
unsigned len
|
645
|
+
unsigned len;
|
646
|
+
deflate_state *s = strm->state;
|
566
647
|
|
648
|
+
_tr_flush_bits(s);
|
649
|
+
len = s->pending;
|
567
650
|
if (len > strm->avail_out) len = strm->avail_out;
|
568
651
|
if (len == 0) return;
|
569
652
|
|
570
|
-
zmemcpy(strm->next_out,
|
653
|
+
zmemcpy(strm->next_out, s->pending_out, len);
|
571
654
|
strm->next_out += len;
|
572
|
-
|
655
|
+
s->pending_out += len;
|
573
656
|
strm->total_out += len;
|
574
657
|
strm->avail_out -= len;
|
575
|
-
|
576
|
-
if (
|
577
|
-
|
658
|
+
s->pending -= len;
|
659
|
+
if (s->pending == 0) {
|
660
|
+
s->pending_out = s->pending_buf;
|
578
661
|
}
|
579
662
|
}
|
580
663
|
|
@@ -801,7 +884,7 @@ int ZEXPORT deflate (strm, flush)
|
|
801
884
|
* flushes. For repeated and useless calls with Z_FINISH, we keep
|
802
885
|
* returning Z_STREAM_END instead of Z_BUF_ERROR.
|
803
886
|
*/
|
804
|
-
} else if (strm->avail_in == 0 && flush <= old_flush &&
|
887
|
+
} else if (strm->avail_in == 0 && RANK(flush) <= RANK(old_flush) &&
|
805
888
|
flush != Z_FINISH) {
|
806
889
|
ERR_RETURN(strm, Z_BUF_ERROR);
|
807
890
|
}
|
@@ -850,6 +933,7 @@ int ZEXPORT deflate (strm, flush)
|
|
850
933
|
if (s->lookahead == 0) {
|
851
934
|
s->strstart = 0;
|
852
935
|
s->block_start = 0L;
|
936
|
+
s->insert = 0;
|
853
937
|
}
|
854
938
|
}
|
855
939
|
}
|
@@ -945,12 +1029,12 @@ int ZEXPORT deflateCopy (dest, source)
|
|
945
1029
|
|
946
1030
|
ss = source->state;
|
947
1031
|
|
948
|
-
zmemcpy(dest, source, sizeof(z_stream));
|
1032
|
+
zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
|
949
1033
|
|
950
1034
|
ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
|
951
1035
|
if (ds == Z_NULL) return Z_MEM_ERROR;
|
952
1036
|
dest->state = (struct internal_state FAR *) ds;
|
953
|
-
zmemcpy(ds, ss, sizeof(deflate_state));
|
1037
|
+
zmemcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state));
|
954
1038
|
ds->strm = dest;
|
955
1039
|
|
956
1040
|
ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
|
@@ -966,8 +1050,8 @@ int ZEXPORT deflateCopy (dest, source)
|
|
966
1050
|
}
|
967
1051
|
/* following zmemcpy do not work for 16-bit MSDOS */
|
968
1052
|
zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
|
969
|
-
zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
|
970
|
-
zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
|
1053
|
+
zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos));
|
1054
|
+
zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos));
|
971
1055
|
zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
|
972
1056
|
|
973
1057
|
ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
|
@@ -1001,15 +1085,15 @@ local int read_buf(strm, buf, size)
|
|
1001
1085
|
|
1002
1086
|
strm->avail_in -= len;
|
1003
1087
|
|
1088
|
+
zmemcpy(buf, strm->next_in, len);
|
1004
1089
|
if (strm->state->wrap == 1) {
|
1005
|
-
strm->adler = adler32(strm->adler,
|
1090
|
+
strm->adler = adler32(strm->adler, buf, len);
|
1006
1091
|
}
|
1007
1092
|
#ifdef GZIP
|
1008
1093
|
else if (strm->state->wrap == 2) {
|
1009
|
-
strm->adler = crc32(strm->adler,
|
1094
|
+
strm->adler = crc32(strm->adler, buf, len);
|
1010
1095
|
}
|
1011
1096
|
#endif
|
1012
|
-
zmemcpy(buf, strm->next_in, len);
|
1013
1097
|
strm->next_in += len;
|
1014
1098
|
strm->total_in += len;
|
1015
1099
|
|
@@ -1036,6 +1120,7 @@ local void lm_init (s)
|
|
1036
1120
|
s->strstart = 0;
|
1037
1121
|
s->block_start = 0L;
|
1038
1122
|
s->lookahead = 0;
|
1123
|
+
s->insert = 0;
|
1039
1124
|
s->match_length = s->prev_length = MIN_MATCH-1;
|
1040
1125
|
s->match_available = 0;
|
1041
1126
|
s->ins_h = 0;
|
@@ -1310,6 +1395,8 @@ local void fill_window(s)
|
|
1310
1395
|
unsigned more; /* Amount of free space at the end of the window. */
|
1311
1396
|
uInt wsize = s->w_size;
|
1312
1397
|
|
1398
|
+
Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
|
1399
|
+
|
1313
1400
|
do {
|
1314
1401
|
more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
|
1315
1402
|
|
@@ -1362,7 +1449,7 @@ local void fill_window(s)
|
|
1362
1449
|
#endif
|
1363
1450
|
more += wsize;
|
1364
1451
|
}
|
1365
|
-
if (s->strm->avail_in == 0)
|
1452
|
+
if (s->strm->avail_in == 0) break;
|
1366
1453
|
|
1367
1454
|
/* If there was no sliding:
|
1368
1455
|
* strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
|
@@ -1381,12 +1468,24 @@ local void fill_window(s)
|
|
1381
1468
|
s->lookahead += n;
|
1382
1469
|
|
1383
1470
|
/* Initialize the hash value now that we have some input: */
|
1384
|
-
if (s->lookahead >= MIN_MATCH) {
|
1385
|
-
|
1386
|
-
|
1471
|
+
if (s->lookahead + s->insert >= MIN_MATCH) {
|
1472
|
+
uInt str = s->strstart - s->insert;
|
1473
|
+
s->ins_h = s->window[str];
|
1474
|
+
UPDATE_HASH(s, s->ins_h, s->window[str + 1]);
|
1387
1475
|
#if MIN_MATCH != 3
|
1388
1476
|
Call UPDATE_HASH() MIN_MATCH-3 more times
|
1389
1477
|
#endif
|
1478
|
+
while (s->insert) {
|
1479
|
+
UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
|
1480
|
+
#ifndef FASTEST
|
1481
|
+
s->prev[str & s->w_mask] = s->head[s->ins_h];
|
1482
|
+
#endif
|
1483
|
+
s->head[s->ins_h] = (Pos)str;
|
1484
|
+
str++;
|
1485
|
+
s->insert--;
|
1486
|
+
if (s->lookahead + s->insert < MIN_MATCH)
|
1487
|
+
break;
|
1488
|
+
}
|
1390
1489
|
}
|
1391
1490
|
/* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
|
1392
1491
|
* but this is not important since only literal bytes will be emitted.
|
@@ -1427,6 +1526,9 @@ local void fill_window(s)
|
|
1427
1526
|
s->high_water += init;
|
1428
1527
|
}
|
1429
1528
|
}
|
1529
|
+
|
1530
|
+
Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
|
1531
|
+
"not enough room for search");
|
1430
1532
|
}
|
1431
1533
|
|
1432
1534
|
/* ===========================================================================
|
@@ -1506,8 +1608,14 @@ local block_state deflate_stored(s, flush)
|
|
1506
1608
|
FLUSH_BLOCK(s, 0);
|
1507
1609
|
}
|
1508
1610
|
}
|
1509
|
-
|
1510
|
-
|
1611
|
+
s->insert = 0;
|
1612
|
+
if (flush == Z_FINISH) {
|
1613
|
+
FLUSH_BLOCK(s, 1);
|
1614
|
+
return finish_done;
|
1615
|
+
}
|
1616
|
+
if ((long)s->strstart > s->block_start)
|
1617
|
+
FLUSH_BLOCK(s, 0);
|
1618
|
+
return block_done;
|
1511
1619
|
}
|
1512
1620
|
|
1513
1621
|
/* ===========================================================================
|
@@ -1603,8 +1711,14 @@ local block_state deflate_fast(s, flush)
|
|
1603
1711
|
}
|
1604
1712
|
if (bflush) FLUSH_BLOCK(s, 0);
|
1605
1713
|
}
|
1606
|
-
|
1607
|
-
|
1714
|
+
s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
|
1715
|
+
if (flush == Z_FINISH) {
|
1716
|
+
FLUSH_BLOCK(s, 1);
|
1717
|
+
return finish_done;
|
1718
|
+
}
|
1719
|
+
if (s->last_lit)
|
1720
|
+
FLUSH_BLOCK(s, 0);
|
1721
|
+
return block_done;
|
1608
1722
|
}
|
1609
1723
|
|
1610
1724
|
#ifndef FASTEST
|
@@ -1728,8 +1842,14 @@ local block_state deflate_slow(s, flush)
|
|
1728
1842
|
_tr_tally_lit(s, s->window[s->strstart-1], bflush);
|
1729
1843
|
s->match_available = 0;
|
1730
1844
|
}
|
1731
|
-
|
1732
|
-
|
1845
|
+
s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
|
1846
|
+
if (flush == Z_FINISH) {
|
1847
|
+
FLUSH_BLOCK(s, 1);
|
1848
|
+
return finish_done;
|
1849
|
+
}
|
1850
|
+
if (s->last_lit)
|
1851
|
+
FLUSH_BLOCK(s, 0);
|
1852
|
+
return block_done;
|
1733
1853
|
}
|
1734
1854
|
#endif /* FASTEST */
|
1735
1855
|
|
@@ -1749,11 +1869,11 @@ local block_state deflate_rle(s, flush)
|
|
1749
1869
|
for (;;) {
|
1750
1870
|
/* Make sure that we always have enough lookahead, except
|
1751
1871
|
* at the end of the input file. We need MAX_MATCH bytes
|
1752
|
-
* for the longest
|
1872
|
+
* for the longest run, plus one for the unrolled loop.
|
1753
1873
|
*/
|
1754
|
-
if (s->lookahead
|
1874
|
+
if (s->lookahead <= MAX_MATCH) {
|
1755
1875
|
fill_window(s);
|
1756
|
-
if (s->lookahead
|
1876
|
+
if (s->lookahead <= MAX_MATCH && flush == Z_NO_FLUSH) {
|
1757
1877
|
return need_more;
|
1758
1878
|
}
|
1759
1879
|
if (s->lookahead == 0) break; /* flush the current block */
|
@@ -1776,6 +1896,7 @@ local block_state deflate_rle(s, flush)
|
|
1776
1896
|
if (s->match_length > s->lookahead)
|
1777
1897
|
s->match_length = s->lookahead;
|
1778
1898
|
}
|
1899
|
+
Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan");
|
1779
1900
|
}
|
1780
1901
|
|
1781
1902
|
/* Emit match if have run of MIN_MATCH or longer, else emit literal */
|
@@ -1796,8 +1917,14 @@ local block_state deflate_rle(s, flush)
|
|
1796
1917
|
}
|
1797
1918
|
if (bflush) FLUSH_BLOCK(s, 0);
|
1798
1919
|
}
|
1799
|
-
|
1800
|
-
|
1920
|
+
s->insert = 0;
|
1921
|
+
if (flush == Z_FINISH) {
|
1922
|
+
FLUSH_BLOCK(s, 1);
|
1923
|
+
return finish_done;
|
1924
|
+
}
|
1925
|
+
if (s->last_lit)
|
1926
|
+
FLUSH_BLOCK(s, 0);
|
1927
|
+
return block_done;
|
1801
1928
|
}
|
1802
1929
|
|
1803
1930
|
/* ===========================================================================
|
@@ -1829,6 +1956,12 @@ local block_state deflate_huff(s, flush)
|
|
1829
1956
|
s->strstart++;
|
1830
1957
|
if (bflush) FLUSH_BLOCK(s, 0);
|
1831
1958
|
}
|
1832
|
-
|
1833
|
-
|
1959
|
+
s->insert = 0;
|
1960
|
+
if (flush == Z_FINISH) {
|
1961
|
+
FLUSH_BLOCK(s, 1);
|
1962
|
+
return finish_done;
|
1963
|
+
}
|
1964
|
+
if (s->last_lit)
|
1965
|
+
FLUSH_BLOCK(s, 0);
|
1966
|
+
return block_done;
|
1834
1967
|
}
|