rugged 0.21.4 → 0.22.0b1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (224) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -5
  3. data/ext/rugged/extconf.rb +9 -9
  4. data/ext/rugged/rugged.c +4 -2
  5. data/ext/rugged/rugged.h +3 -7
  6. data/ext/rugged/rugged_blob.c +57 -0
  7. data/ext/rugged/rugged_cred.c +23 -0
  8. data/ext/rugged/rugged_index.c +6 -2
  9. data/ext/rugged/rugged_remote.c +65 -52
  10. data/ext/rugged/rugged_remote_collection.c +59 -10
  11. data/ext/rugged/rugged_repo.c +345 -11
  12. data/ext/rugged/rugged_revwalk.c +10 -0
  13. data/ext/rugged/rugged_submodule.c +1042 -0
  14. data/ext/rugged/rugged_submodule_collection.c +236 -0
  15. data/ext/rugged/rugged_tag_collection.c +70 -2
  16. data/ext/rugged/rugged_tree.c +29 -10
  17. data/lib/rugged.rb +3 -0
  18. data/lib/rugged/attributes.rb +41 -0
  19. data/lib/rugged/blob.rb +28 -0
  20. data/lib/rugged/diff.rb +0 -1
  21. data/lib/rugged/diff/line.rb +1 -3
  22. data/lib/rugged/patch.rb +12 -2
  23. data/lib/rugged/repository.rb +7 -0
  24. data/lib/rugged/submodule_collection.rb +48 -0
  25. data/lib/rugged/version.rb +1 -1
  26. data/vendor/libgit2/CMakeLists.txt +27 -3
  27. data/vendor/libgit2/cmake/Modules/FindGSSAPI.cmake +324 -0
  28. data/vendor/libgit2/deps/http-parser/http_parser.h +2 -0
  29. data/vendor/libgit2/deps/zlib/adler32.c +39 -29
  30. data/vendor/libgit2/deps/zlib/crc32.c +33 -50
  31. data/vendor/libgit2/deps/zlib/crc32.h +1 -1
  32. data/vendor/libgit2/deps/zlib/deflate.c +198 -65
  33. data/vendor/libgit2/deps/zlib/deflate.h +8 -4
  34. data/vendor/libgit2/deps/zlib/infback.c +640 -0
  35. data/vendor/libgit2/deps/zlib/inffast.c +3 -3
  36. data/vendor/libgit2/deps/zlib/inffixed.h +3 -3
  37. data/vendor/libgit2/deps/zlib/inflate.c +84 -52
  38. data/vendor/libgit2/deps/zlib/inftrees.c +15 -39
  39. data/vendor/libgit2/deps/zlib/trees.c +18 -36
  40. data/vendor/libgit2/deps/zlib/zconf.h +4 -0
  41. data/vendor/libgit2/deps/zlib/zlib.h +250 -95
  42. data/vendor/libgit2/deps/zlib/zutil.c +13 -10
  43. data/vendor/libgit2/deps/zlib/zutil.h +41 -62
  44. data/vendor/libgit2/include/git2.h +4 -0
  45. data/vendor/libgit2/include/git2/annotated_commit.h +99 -0
  46. data/vendor/libgit2/include/git2/attr.h +16 -13
  47. data/vendor/libgit2/include/git2/branch.h +11 -0
  48. data/vendor/libgit2/include/git2/buffer.h +16 -0
  49. data/vendor/libgit2/include/git2/checkout.h +12 -12
  50. data/vendor/libgit2/include/git2/cherrypick.h +15 -15
  51. data/vendor/libgit2/include/git2/clone.h +77 -69
  52. data/vendor/libgit2/include/git2/common.h +13 -1
  53. data/vendor/libgit2/include/git2/config.h +0 -14
  54. data/vendor/libgit2/include/git2/describe.h +162 -0
  55. data/vendor/libgit2/include/git2/diff.h +13 -8
  56. data/vendor/libgit2/include/git2/errors.h +5 -0
  57. data/vendor/libgit2/include/git2/global.h +38 -0
  58. data/vendor/libgit2/include/git2/merge.h +38 -64
  59. data/vendor/libgit2/include/git2/net.h +2 -2
  60. data/vendor/libgit2/include/git2/notes.h +17 -0
  61. data/vendor/libgit2/include/git2/oid.h +8 -4
  62. data/vendor/libgit2/include/git2/oidarray.h +40 -0
  63. data/vendor/libgit2/include/git2/rebase.h +261 -0
  64. data/vendor/libgit2/include/git2/reflog.h +1 -1
  65. data/vendor/libgit2/include/git2/remote.h +25 -47
  66. data/vendor/libgit2/include/git2/repository.h +4 -1
  67. data/vendor/libgit2/include/git2/reset.h +10 -1
  68. data/vendor/libgit2/include/git2/revert.h +1 -1
  69. data/vendor/libgit2/include/git2/revwalk.h +28 -23
  70. data/vendor/libgit2/include/git2/status.h +19 -15
  71. data/vendor/libgit2/include/git2/submodule.h +18 -0
  72. data/vendor/libgit2/include/git2/sys/config.h +0 -1
  73. data/vendor/libgit2/{src → include/git2/sys}/hashsig.h +11 -7
  74. data/vendor/libgit2/include/git2/sys/refdb_backend.h +13 -0
  75. data/vendor/libgit2/include/git2/sys/refs.h +0 -11
  76. data/vendor/libgit2/include/git2/sys/repository.h +13 -0
  77. data/vendor/libgit2/include/git2/sys/transport.h +352 -0
  78. data/vendor/libgit2/include/git2/threads.h +10 -20
  79. data/vendor/libgit2/include/git2/transaction.h +111 -0
  80. data/vendor/libgit2/include/git2/transport.h +79 -313
  81. data/vendor/libgit2/include/git2/tree.h +4 -2
  82. data/vendor/libgit2/include/git2/types.h +77 -8
  83. data/vendor/libgit2/include/git2/version.h +2 -2
  84. data/vendor/libgit2/src/annotated_commit.c +121 -0
  85. data/vendor/libgit2/src/annotated_commit.h +22 -0
  86. data/vendor/libgit2/src/attr.c +8 -4
  87. data/vendor/libgit2/src/attr_file.c +24 -2
  88. data/vendor/libgit2/src/blame.c +0 -1
  89. data/vendor/libgit2/src/branch.c +32 -3
  90. data/vendor/libgit2/src/buf_text.c +9 -5
  91. data/vendor/libgit2/src/buf_text.h +3 -2
  92. data/vendor/libgit2/src/buffer.c +67 -10
  93. data/vendor/libgit2/src/buffer.h +4 -2
  94. data/vendor/libgit2/src/cache.c +9 -9
  95. data/vendor/libgit2/src/cache.h +1 -1
  96. data/vendor/libgit2/src/cc-compat.h +2 -0
  97. data/vendor/libgit2/src/checkout.c +263 -82
  98. data/vendor/libgit2/src/checkout.h +1 -0
  99. data/vendor/libgit2/src/cherrypick.c +41 -44
  100. data/vendor/libgit2/src/clone.c +96 -58
  101. data/vendor/libgit2/src/commit.c +5 -31
  102. data/vendor/libgit2/src/commit_list.h +3 -1
  103. data/vendor/libgit2/src/config.c +0 -17
  104. data/vendor/libgit2/src/config_cache.c +0 -2
  105. data/vendor/libgit2/src/config_file.c +12 -15
  106. data/vendor/libgit2/src/crlf.c +2 -1
  107. data/vendor/libgit2/src/describe.c +886 -0
  108. data/vendor/libgit2/src/diff.c +29 -3
  109. data/vendor/libgit2/src/diff_file.c +1 -0
  110. data/vendor/libgit2/src/diff_patch.c +2 -3
  111. data/vendor/libgit2/src/diff_print.c +11 -9
  112. data/vendor/libgit2/src/diff_tform.c +4 -4
  113. data/vendor/libgit2/src/errors.c +9 -7
  114. data/vendor/libgit2/src/fetch.c +6 -6
  115. data/vendor/libgit2/src/fetchhead.h +2 -4
  116. data/vendor/libgit2/src/filebuf.c +0 -2
  117. data/vendor/libgit2/src/filebuf.h +2 -3
  118. data/vendor/libgit2/src/fileops.c +9 -7
  119. data/vendor/libgit2/src/global.c +44 -35
  120. data/vendor/libgit2/src/global.h +2 -0
  121. data/vendor/libgit2/src/graph.c +2 -2
  122. data/vendor/libgit2/src/hash.h +3 -1
  123. data/vendor/libgit2/src/hash/hash_common_crypto.h +44 -0
  124. data/vendor/libgit2/src/hash/hash_win32.c +1 -1
  125. data/vendor/libgit2/src/hashsig.c +1 -1
  126. data/vendor/libgit2/src/ignore.c +5 -88
  127. data/vendor/libgit2/src/index.c +70 -57
  128. data/vendor/libgit2/src/index.h +1 -0
  129. data/vendor/libgit2/src/indexer.c +16 -5
  130. data/vendor/libgit2/src/iterator.c +70 -1
  131. data/vendor/libgit2/src/iterator.h +5 -1
  132. data/vendor/libgit2/src/map.h +0 -1
  133. data/vendor/libgit2/src/merge.c +203 -327
  134. data/vendor/libgit2/src/merge.h +3 -13
  135. data/vendor/libgit2/src/mwindow.c +119 -8
  136. data/vendor/libgit2/src/mwindow.h +9 -1
  137. data/vendor/libgit2/src/netops.c +7 -8
  138. data/vendor/libgit2/src/netops.h +6 -16
  139. data/vendor/libgit2/src/notes.c +31 -4
  140. data/vendor/libgit2/src/notes.h +3 -0
  141. data/vendor/libgit2/src/odb.c +23 -1
  142. data/vendor/libgit2/src/odb_loose.c +1 -1
  143. data/vendor/libgit2/src/odb_pack.c +6 -3
  144. data/vendor/libgit2/src/oid.c +9 -1
  145. data/vendor/libgit2/src/oid.h +11 -0
  146. data/vendor/libgit2/src/oidarray.c +21 -0
  147. data/vendor/libgit2/src/oidarray.h +18 -0
  148. data/vendor/libgit2/src/oidmap.h +16 -0
  149. data/vendor/libgit2/src/pack.c +20 -7
  150. data/vendor/libgit2/src/pack.h +3 -0
  151. data/vendor/libgit2/src/path.c +120 -293
  152. data/vendor/libgit2/src/path.h +21 -44
  153. data/vendor/libgit2/src/pathspec.c +1 -1
  154. data/vendor/libgit2/src/pool.c +5 -11
  155. data/vendor/libgit2/src/pool.h +0 -2
  156. data/vendor/libgit2/src/posix.c +6 -6
  157. data/vendor/libgit2/src/posix.h +48 -28
  158. data/vendor/libgit2/src/push.c +19 -48
  159. data/vendor/libgit2/src/push.h +2 -4
  160. data/vendor/libgit2/src/rebase.c +1125 -0
  161. data/vendor/libgit2/src/refdb.c +19 -0
  162. data/vendor/libgit2/src/refdb.h +2 -1
  163. data/vendor/libgit2/src/refdb_fs.c +101 -29
  164. data/vendor/libgit2/src/reflog.c +1 -1
  165. data/vendor/libgit2/src/refs.c +38 -3
  166. data/vendor/libgit2/src/refs.h +13 -2
  167. data/vendor/libgit2/src/refspec.c +20 -2
  168. data/vendor/libgit2/src/remote.c +288 -154
  169. data/vendor/libgit2/src/remote.h +5 -1
  170. data/vendor/libgit2/src/repository.c +75 -36
  171. data/vendor/libgit2/src/repository.h +3 -25
  172. data/vendor/libgit2/src/reset.c +5 -1
  173. data/vendor/libgit2/src/revert.c +4 -6
  174. data/vendor/libgit2/src/revparse.c +15 -18
  175. data/vendor/libgit2/src/revwalk.c +96 -22
  176. data/vendor/libgit2/src/revwalk.h +5 -4
  177. data/vendor/libgit2/src/settings.c +22 -0
  178. data/vendor/libgit2/src/signature.c +37 -2
  179. data/vendor/libgit2/src/signature.h +3 -0
  180. data/vendor/libgit2/src/stash.c +17 -12
  181. data/vendor/libgit2/src/status.c +13 -3
  182. data/vendor/libgit2/src/strnlen.h +2 -1
  183. data/vendor/libgit2/src/submodule.c +75 -35
  184. data/vendor/libgit2/src/thread-utils.h +4 -9
  185. data/vendor/libgit2/src/trace.h +9 -1
  186. data/vendor/libgit2/src/transaction.c +352 -0
  187. data/vendor/libgit2/src/transport.c +91 -97
  188. data/vendor/libgit2/src/transports/auth.c +71 -0
  189. data/vendor/libgit2/src/transports/auth.h +63 -0
  190. data/vendor/libgit2/src/transports/auth_negotiate.c +275 -0
  191. data/vendor/libgit2/src/transports/auth_negotiate.h +27 -0
  192. data/vendor/libgit2/src/transports/cred.c +58 -0
  193. data/vendor/libgit2/src/transports/cred.h +14 -0
  194. data/vendor/libgit2/src/transports/cred_helpers.c +3 -0
  195. data/vendor/libgit2/src/transports/git.c +1 -0
  196. data/vendor/libgit2/src/transports/http.c +208 -82
  197. data/vendor/libgit2/src/transports/local.c +2 -2
  198. data/vendor/libgit2/src/transports/smart.c +2 -0
  199. data/vendor/libgit2/src/transports/smart.h +2 -0
  200. data/vendor/libgit2/src/transports/smart_protocol.c +10 -10
  201. data/vendor/libgit2/src/transports/ssh.c +243 -57
  202. data/vendor/libgit2/src/transports/winhttp.c +139 -35
  203. data/vendor/libgit2/src/tree-cache.c +118 -31
  204. data/vendor/libgit2/src/tree-cache.h +12 -7
  205. data/vendor/libgit2/src/tree.c +83 -64
  206. data/vendor/libgit2/src/tree.h +2 -3
  207. data/vendor/libgit2/src/unix/map.c +8 -2
  208. data/vendor/libgit2/src/unix/posix.h +23 -9
  209. data/vendor/libgit2/src/unix/realpath.c +8 -7
  210. data/vendor/libgit2/src/userdiff.h +3 -3
  211. data/vendor/libgit2/src/util.c +2 -92
  212. data/vendor/libgit2/src/util.h +3 -15
  213. data/vendor/libgit2/src/win32/findfile.c +0 -1
  214. data/vendor/libgit2/src/win32/map.c +3 -2
  215. data/vendor/libgit2/src/win32/mingw-compat.h +5 -12
  216. data/vendor/libgit2/src/win32/msvc-compat.h +3 -32
  217. data/vendor/libgit2/src/win32/posix.h +20 -32
  218. data/vendor/libgit2/src/win32/posix_w32.c +103 -31
  219. data/vendor/libgit2/src/win32/utf-conv.c +6 -36
  220. data/vendor/libgit2/src/win32/utf-conv.h +39 -0
  221. data/vendor/libgit2/src/win32/w32_util.h +0 -1
  222. metadata +32 -7
  223. data/vendor/libgit2/src/win32/path_w32.c +0 -305
  224. data/vendor/libgit2/src/win32/path_w32.h +0 -82
@@ -40,6 +40,8 @@ typedef __int64 int64_t;
40
40
  typedef unsigned __int64 uint64_t;
41
41
  typedef SIZE_T size_t;
42
42
  typedef SSIZE_T ssize_t;
43
+ #elif defined(__sun) || defined(__sun__)
44
+ #include <sys/inttypes.h>
43
45
  #else
44
46
  #include <stdint.h>
45
47
  #endif
@@ -1,5 +1,5 @@
1
1
  /* adler32.c -- compute the Adler-32 checksum of a data stream
2
- * Copyright (C) 1995-2007 Mark Adler
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 65521UL /* largest prime smaller than 65536 */
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
- # define MOD(a) \
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
- if (a >= (BASE << 16)) a -= (BASE << 16); \
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 MOD4(a) \
40
+ # define MOD(a) \
47
41
  do { \
48
- if (a >= (BASE << 4)) a -= (BASE << 4); \
49
- if (a >= (BASE << 3)) a -= (BASE << 3); \
50
- if (a >= (BASE << 2)) a -= (BASE << 2); \
51
- if (a >= (BASE << 1)) a -= (BASE << 1); \
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 MOD4(a) a %= BASE
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
- MOD4(sum2); /* only added so many BASE's */
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
- rem = (unsigned)(len2 % BASE);
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 unsigned long FAR crc_table[TBLS][256];
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 unsigned long FAR *));
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
- unsigned long c;
92
+ z_crc_t c;
111
93
  int n, k;
112
- unsigned long poly; /* polynomial exclusive-or pattern */
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 = 0UL;
125
- for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
126
- poly |= 1UL << (31 - p[n]);
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 = (unsigned long)n;
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] = REV(c);
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] = REV(c);
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 unsigned long FAR ");
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 unsigned long FAR *table;
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 ? "" : " ", table[n],
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 unsigned long FAR * ZEXPORT get_crc_table()
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 unsigned long FAR *)crc_table;
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
- u4 endian;
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 u4 c;
270
- register const u4 FAR *buf4;
252
+ register z_crc_t c;
253
+ register const z_crc_t FAR *buf4;
271
254
 
272
- c = (u4)crc;
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 u4 FAR *)(const void FAR *)buf;
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 u4 c;
310
- register const u4 FAR *buf4;
292
+ register z_crc_t c;
293
+ register const z_crc_t FAR *buf4;
311
294
 
312
- c = REV((u4)crc);
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 u4 FAR *)(const void FAR *)buf;
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)(REV(c));
319
+ return (unsigned long)(ZSWAP32(c));
337
320
  }
338
321
 
339
322
  #endif /* BYFOUR */
@@ -2,7 +2,7 @@
2
2
  * Generated automatically by crc32.c
3
3
  */
4
4
 
5
- local const unsigned long FAR crc_table[TBLS][256] =
5
+ local const z_crc_t FAR crc_table[TBLS][256] =
6
6
  {
7
7
  {
8
8
  0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
@@ -1,5 +1,5 @@
1
1
  /* deflate.c -- compress data using the deflation algorithm
2
- * Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler
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://www.ietf.org/rfc/rfc1951.txt
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.5 Copyright 1995-2010 Jean-loup Gailly and Mark Adler ";
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) strm->zfree = zcfree;
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 = (char*)ERR_MSG(Z_MEM_ERROR);
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 length = dictLength;
318
- uInt n;
319
- IPos hash_head = 0;
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
- if (s->wrap)
328
- strm->adler = adler32(strm->adler, dictionary, dictLength);
337
+ wrap = s->wrap;
338
+ if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead)
339
+ return Z_STREAM_ERROR;
329
340
 
330
- if (length < MIN_MATCH) return Z_OK;
331
- if (length > s->w_size) {
332
- length = s->w_size;
333
- dictionary += dictLength - length; /* use the tail of the dictionary */
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
- /* Insert all strings in the hash table (except for the last two bytes).
340
- * s->lookahead stays null, so s->ins_h will be recomputed at the next
341
- * call of fill_window.
342
- */
343
- s->ins_h = s->window[0];
344
- UPDATE_HASH(s, s->ins_h, s->window[1]);
345
- for (n = 0; n <= length - MIN_MATCH; n++) {
346
- INSERT_STRING(s, n, hash_head);
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
- if (hash_head) hash_head = 0; /* to make compiler happy */
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 deflateReset (strm)
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->bi_valid = bits;
407
- strm->state->bi_buf = (ush)(value & ((1 << bits) - 1));
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 = strm->state->pending;
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, strm->state->pending_out, len);
653
+ zmemcpy(strm->next_out, s->pending_out, len);
571
654
  strm->next_out += len;
572
- strm->state->pending_out += len;
655
+ s->pending_out += len;
573
656
  strm->total_out += len;
574
657
  strm->avail_out -= len;
575
- strm->state->pending -= len;
576
- if (strm->state->pending == 0) {
577
- strm->state->pending_out = strm->state->pending_buf;
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, strm->next_in, len);
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, strm->next_in, len);
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) return;
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
- s->ins_h = s->window[s->strstart];
1386
- UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
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
- FLUSH_BLOCK(s, flush == Z_FINISH);
1510
- return flush == Z_FINISH ? finish_done : block_done;
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
- FLUSH_BLOCK(s, flush == Z_FINISH);
1607
- return flush == Z_FINISH ? finish_done : block_done;
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
- FLUSH_BLOCK(s, flush == Z_FINISH);
1732
- return flush == Z_FINISH ? finish_done : block_done;
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 encodable run.
1872
+ * for the longest run, plus one for the unrolled loop.
1753
1873
  */
1754
- if (s->lookahead < MAX_MATCH) {
1874
+ if (s->lookahead <= MAX_MATCH) {
1755
1875
  fill_window(s);
1756
- if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) {
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
- FLUSH_BLOCK(s, flush == Z_FINISH);
1800
- return flush == Z_FINISH ? finish_done : block_done;
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
- FLUSH_BLOCK(s, flush == Z_FINISH);
1833
- return flush == Z_FINISH ? finish_done : block_done;
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
  }