grpc 1.3.4 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (286) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +581 -450
  3. data/include/grpc/census.h +49 -49
  4. data/include/grpc/grpc.h +16 -70
  5. data/include/grpc/grpc_security.h +59 -59
  6. data/include/grpc/grpc_security_constants.h +9 -9
  7. data/include/grpc/impl/codegen/atm.h +1 -1
  8. data/include/grpc/impl/codegen/atm_windows.h +4 -4
  9. data/include/grpc/impl/codegen/byte_buffer_reader.h +2 -2
  10. data/include/grpc/impl/codegen/compression_types.h +4 -5
  11. data/include/grpc/impl/codegen/gpr_slice.h +5 -5
  12. data/include/grpc/impl/codegen/gpr_types.h +6 -7
  13. data/include/grpc/impl/codegen/grpc_types.h +128 -59
  14. data/include/grpc/impl/codegen/port_platform.h +6 -0
  15. data/include/grpc/impl/codegen/propagation_bits.h +2 -2
  16. data/include/grpc/impl/codegen/slice.h +13 -12
  17. data/include/grpc/impl/codegen/status.h +23 -18
  18. data/include/grpc/impl/codegen/sync.h +1 -1
  19. data/include/grpc/load_reporting.h +6 -6
  20. data/include/grpc/slice.h +47 -25
  21. data/include/grpc/slice_buffer.h +18 -14
  22. data/include/grpc/support/alloc.h +7 -7
  23. data/include/grpc/support/cmdline.h +10 -10
  24. data/include/grpc/support/cpu.h +3 -3
  25. data/include/grpc/support/histogram.h +1 -1
  26. data/include/grpc/support/host_port.h +2 -2
  27. data/include/grpc/support/log.h +9 -9
  28. data/include/grpc/support/log_windows.h +1 -1
  29. data/include/grpc/support/string_util.h +3 -3
  30. data/include/grpc/support/subprocess.h +3 -3
  31. data/include/grpc/support/sync.h +31 -31
  32. data/include/grpc/support/thd.h +11 -11
  33. data/include/grpc/support/time.h +12 -12
  34. data/include/grpc/support/tls.h +1 -1
  35. data/include/grpc/support/tls_gcc.h +2 -2
  36. data/include/grpc/support/tls_msvc.h +1 -1
  37. data/include/grpc/support/tls_pthread.h +1 -1
  38. data/include/grpc/support/useful.h +2 -2
  39. data/include/grpc/support/workaround_list.h +46 -0
  40. data/src/core/ext/census/context.c +1 -1
  41. data/src/core/ext/census/intrusive_hash_map.c +319 -0
  42. data/src/core/ext/census/intrusive_hash_map.h +167 -0
  43. data/src/core/ext/census/intrusive_hash_map_internal.h +63 -0
  44. data/src/core/ext/census/resource.c +3 -1
  45. data/src/core/ext/filters/client_channel/channel_connectivity.c +1 -1
  46. data/src/core/ext/filters/client_channel/client_channel.c +173 -103
  47. data/src/core/ext/filters/client_channel/client_channel_plugin.c +3 -2
  48. data/src/core/ext/filters/client_channel/lb_policy.c +2 -1
  49. data/src/core/ext/filters/client_channel/lb_policy.h +8 -7
  50. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.c +153 -0
  51. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.h +42 -0
  52. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.c +405 -102
  53. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.c +133 -0
  54. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +65 -0
  55. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.c +90 -51
  56. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +7 -1
  57. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c +19 -8
  58. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +63 -34
  59. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.c +2 -1
  60. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.c +188 -294
  61. data/src/core/ext/filters/client_channel/lb_policy_factory.c +28 -5
  62. data/src/core/ext/filters/client_channel/lb_policy_factory.h +18 -4
  63. data/src/core/ext/filters/client_channel/parse_address.c +90 -59
  64. data/src/core/ext/filters/client_channel/parse_address.h +17 -8
  65. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.c +11 -7
  66. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.c +59 -14
  67. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +6 -0
  68. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.c +3 -3
  69. data/src/core/ext/filters/client_channel/subchannel.c +20 -17
  70. data/src/core/ext/filters/client_channel/subchannel.h +1 -0
  71. data/src/core/ext/filters/client_channel/subchannel_index.c +11 -1
  72. data/src/core/ext/filters/client_channel/uri_parser.c +36 -22
  73. data/src/core/ext/filters/client_channel/uri_parser.h +1 -1
  74. data/src/core/{lib/channel → ext/filters/deadline}/deadline_filter.c +42 -17
  75. data/src/core/{lib/channel → ext/filters/deadline}/deadline_filter.h +8 -9
  76. data/src/core/{lib/channel → ext/filters/http/client}/http_client_filter.c +19 -11
  77. data/src/core/{lib/channel → ext/filters/http/client}/http_client_filter.h +3 -6
  78. data/src/core/ext/filters/http/http_filters_plugin.c +104 -0
  79. data/src/core/{lib/channel/compress_filter.c → ext/filters/http/message_compress/message_compress_filter.c} +124 -23
  80. data/src/core/{lib/channel/compress_filter.h → ext/filters/http/message_compress/message_compress_filter.h} +5 -6
  81. data/src/core/{lib/channel → ext/filters/http/server}/http_server_filter.c +4 -6
  82. data/src/core/{lib/channel → ext/filters/http/server}/http_server_filter.h +3 -3
  83. data/src/core/ext/filters/load_reporting/load_reporting.c +2 -25
  84. data/src/core/ext/filters/load_reporting/load_reporting_filter.c +26 -1
  85. data/src/core/ext/filters/max_age/max_age_filter.c +14 -14
  86. data/src/core/{lib/channel → ext/filters/message_size}/message_size_filter.c +91 -47
  87. data/src/core/{lib/channel → ext/filters/message_size}/message_size_filter.h +3 -3
  88. data/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.c +223 -0
  89. data/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.h +40 -0
  90. data/src/core/ext/filters/workarounds/workaround_utils.c +65 -0
  91. data/src/core/ext/filters/workarounds/workaround_utils.h +52 -0
  92. data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +1 -1
  93. data/src/core/ext/transport/chttp2/server/chttp2_server.c +3 -2
  94. data/src/core/ext/transport/chttp2/transport/bin_decoder.c +2 -2
  95. data/src/core/ext/transport/chttp2/transport/bin_encoder.c +3 -3
  96. data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +319 -175
  97. data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +3 -2
  98. data/src/core/ext/transport/chttp2/transport/frame_data.c +203 -164
  99. data/src/core/ext/transport/chttp2/transport/frame_data.h +8 -14
  100. data/src/core/ext/transport/chttp2/transport/frame_goaway.c +1 -1
  101. data/src/core/ext/transport/chttp2/transport/frame_ping.c +1 -1
  102. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +1 -1
  103. data/src/core/ext/transport/chttp2/transport/frame_settings.c +5 -5
  104. data/src/core/ext/transport/chttp2/transport/frame_window_update.c +1 -1
  105. data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +4 -4
  106. data/src/core/ext/transport/chttp2/transport/hpack_parser.c +2 -4
  107. data/src/core/ext/transport/chttp2/transport/hpack_table.c +4 -3
  108. data/src/core/ext/transport/chttp2/transport/internal.h +50 -33
  109. data/src/core/ext/transport/chttp2/transport/parsing.c +10 -11
  110. data/src/core/ext/transport/chttp2/transport/writing.c +32 -13
  111. data/src/core/lib/channel/channel_args.c +30 -9
  112. data/src/core/lib/channel/channel_args.h +5 -1
  113. data/src/core/lib/channel/channel_stack.c +1 -1
  114. data/src/core/lib/channel/channel_stack.h +2 -2
  115. data/src/core/lib/channel/channel_stack_builder.c +13 -1
  116. data/src/core/lib/channel/channel_stack_builder.h +5 -1
  117. data/src/core/lib/channel/connected_channel.c +3 -1
  118. data/src/core/lib/channel/context.h +2 -2
  119. data/src/core/lib/compression/message_compress.c +2 -2
  120. data/src/core/lib/debug/trace.c +13 -6
  121. data/src/core/lib/debug/trace.h +27 -1
  122. data/src/core/lib/http/httpcli.c +1 -1
  123. data/src/core/lib/http/httpcli_security_connector.c +9 -11
  124. data/src/core/lib/http/parser.c +2 -2
  125. data/src/core/lib/http/parser.h +2 -1
  126. data/src/core/lib/iomgr/combiner.c +6 -6
  127. data/src/core/lib/iomgr/combiner.h +2 -1
  128. data/src/core/lib/iomgr/error.c +12 -5
  129. data/src/core/lib/iomgr/error.h +13 -13
  130. data/src/core/lib/iomgr/ev_epoll1_linux.c +984 -0
  131. data/src/core/lib/iomgr/ev_epoll1_linux.h +44 -0
  132. data/src/core/lib/iomgr/ev_epoll_limited_pollers_linux.c +2146 -0
  133. data/src/core/lib/iomgr/ev_epoll_limited_pollers_linux.h +43 -0
  134. data/src/core/lib/iomgr/ev_epoll_thread_pool_linux.c +1337 -0
  135. data/src/core/lib/iomgr/ev_epoll_thread_pool_linux.h +43 -0
  136. data/src/core/lib/iomgr/ev_epollex_linux.c +1511 -0
  137. data/src/core/lib/iomgr/ev_epollex_linux.h +43 -0
  138. data/src/core/lib/iomgr/{ev_epoll_linux.c → ev_epollsig_linux.c} +41 -33
  139. data/src/core/lib/iomgr/{ev_epoll_linux.h → ev_epollsig_linux.h} +4 -4
  140. data/src/core/lib/iomgr/ev_poll_posix.c +12 -27
  141. data/src/core/lib/iomgr/ev_poll_posix.h +2 -2
  142. data/src/core/lib/iomgr/ev_posix.c +22 -8
  143. data/src/core/lib/iomgr/ev_posix.h +4 -3
  144. data/src/core/lib/iomgr/ev_windows.c +43 -0
  145. data/src/core/lib/iomgr/exec_ctx.c +5 -0
  146. data/src/core/lib/iomgr/exec_ctx.h +2 -0
  147. data/src/core/lib/iomgr/iomgr.c +4 -0
  148. data/src/core/lib/iomgr/iomgr.h +3 -0
  149. data/src/core/lib/iomgr/is_epollexclusive_available.c +116 -0
  150. data/src/core/lib/iomgr/is_epollexclusive_available.h +41 -0
  151. data/src/core/lib/iomgr/lockfree_event.c +16 -0
  152. data/src/core/lib/iomgr/pollset.h +2 -5
  153. data/src/core/lib/iomgr/pollset_uv.c +1 -1
  154. data/src/core/lib/iomgr/pollset_windows.c +3 -3
  155. data/src/core/lib/iomgr/resource_quota.c +9 -8
  156. data/src/core/lib/iomgr/resource_quota.h +2 -1
  157. data/src/core/lib/iomgr/sockaddr_utils.h +1 -1
  158. data/src/core/lib/iomgr/socket_mutator.h +2 -0
  159. data/src/core/lib/iomgr/sys_epoll_wrapper.h +43 -0
  160. data/src/core/lib/iomgr/tcp_client_posix.c +6 -6
  161. data/src/core/lib/iomgr/tcp_client_uv.c +3 -3
  162. data/src/core/lib/iomgr/tcp_posix.c +7 -7
  163. data/src/core/lib/iomgr/tcp_posix.h +2 -1
  164. data/src/core/lib/iomgr/tcp_server_posix.c +1 -1
  165. data/src/core/lib/iomgr/tcp_uv.c +6 -6
  166. data/src/core/lib/iomgr/tcp_uv.h +2 -1
  167. data/src/core/lib/iomgr/tcp_windows.c +1 -1
  168. data/src/core/lib/iomgr/timer_generic.c +24 -25
  169. data/src/core/lib/iomgr/timer_manager.c +276 -0
  170. data/src/core/lib/iomgr/timer_manager.h +52 -0
  171. data/src/core/lib/iomgr/timer_uv.c +6 -0
  172. data/src/core/lib/iomgr/udp_server.c +42 -9
  173. data/src/core/lib/iomgr/udp_server.h +3 -1
  174. data/src/core/lib/security/credentials/credentials.c +0 -1
  175. data/src/core/lib/security/credentials/fake/fake_credentials.c +23 -0
  176. data/src/core/lib/security/credentials/fake/fake_credentials.h +12 -9
  177. data/src/core/lib/security/credentials/google_default/google_default_credentials.c +1 -1
  178. data/src/core/lib/security/credentials/jwt/jwt_credentials.c +1 -1
  179. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +1 -1
  180. data/src/core/lib/security/credentials/ssl/ssl_credentials.c +24 -53
  181. data/src/core/lib/security/transport/client_auth_filter.c +9 -3
  182. data/src/core/lib/security/transport/secure_endpoint.c +7 -7
  183. data/src/core/lib/security/transport/secure_endpoint.h +1 -1
  184. data/src/core/lib/security/transport/security_connector.c +45 -57
  185. data/src/core/lib/security/transport/security_connector.h +10 -14
  186. data/src/core/lib/security/transport/security_handshaker.c +123 -97
  187. data/src/core/lib/slice/b64.c +1 -1
  188. data/src/core/lib/slice/percent_encoding.c +3 -3
  189. data/src/core/lib/slice/slice.c +66 -33
  190. data/src/core/lib/slice/slice_buffer.c +25 -6
  191. data/src/core/lib/slice/slice_hash_table.c +33 -35
  192. data/src/core/lib/slice/slice_hash_table.h +7 -12
  193. data/src/core/lib/support/atomic.h +45 -0
  194. data/src/core/lib/support/atomic_with_atm.h +70 -0
  195. data/src/core/lib/support/atomic_with_std.h +48 -0
  196. data/src/core/lib/support/avl.c +14 -14
  197. data/src/core/lib/support/cmdline.c +3 -3
  198. data/src/core/lib/support/histogram.c +2 -2
  199. data/src/core/lib/support/host_port.c +1 -1
  200. data/src/core/lib/support/memory.h +74 -0
  201. data/src/core/lib/support/mpscq.c +36 -2
  202. data/src/core/lib/support/mpscq.h +28 -1
  203. data/src/core/lib/support/stack_lockfree.c +3 -36
  204. data/src/core/lib/support/string.c +12 -12
  205. data/src/core/lib/support/string_posix.c +1 -1
  206. data/src/core/lib/support/subprocess_posix.c +2 -2
  207. data/src/core/lib/support/thd_posix.c +1 -1
  208. data/src/core/lib/support/time_posix.c +8 -0
  209. data/src/core/lib/support/tmpfile_posix.c +10 -10
  210. data/src/core/lib/surface/alarm.c +3 -1
  211. data/src/core/lib/surface/api_trace.c +2 -1
  212. data/src/core/lib/surface/api_trace.h +2 -2
  213. data/src/core/lib/surface/byte_buffer_reader.c +1 -1
  214. data/src/core/lib/surface/call.c +65 -22
  215. data/src/core/lib/surface/call.h +4 -2
  216. data/src/core/lib/surface/channel_init.c +2 -19
  217. data/src/core/lib/surface/channel_stack_type.c +18 -0
  218. data/src/core/lib/surface/channel_stack_type.h +2 -0
  219. data/src/core/lib/surface/completion_queue.c +694 -247
  220. data/src/core/lib/surface/completion_queue.h +30 -13
  221. data/src/core/lib/surface/completion_queue_factory.c +24 -9
  222. data/src/core/lib/surface/init.c +1 -52
  223. data/src/core/lib/surface/{lame_client.c → lame_client.cc} +37 -26
  224. data/src/core/lib/surface/server.c +79 -110
  225. data/src/core/lib/surface/server.h +2 -1
  226. data/src/core/lib/surface/version.c +2 -2
  227. data/src/core/lib/transport/bdp_estimator.c +25 -9
  228. data/src/core/lib/transport/bdp_estimator.h +7 -1
  229. data/src/core/lib/transport/byte_stream.c +23 -9
  230. data/src/core/lib/transport/byte_stream.h +15 -6
  231. data/src/core/lib/transport/connectivity_state.c +6 -6
  232. data/src/core/lib/transport/connectivity_state.h +2 -1
  233. data/src/core/lib/transport/service_config.c +6 -13
  234. data/src/core/lib/transport/service_config.h +2 -2
  235. data/src/core/lib/transport/static_metadata.c +403 -389
  236. data/src/core/lib/transport/static_metadata.h +127 -114
  237. data/src/core/plugin_registry/grpc_plugin_registry.c +16 -0
  238. data/src/core/tsi/fake_transport_security.c +5 -4
  239. data/src/core/tsi/ssl_transport_security.c +71 -82
  240. data/src/core/tsi/ssl_transport_security.h +39 -61
  241. data/src/core/tsi/transport_security.c +83 -2
  242. data/src/core/tsi/transport_security.h +27 -2
  243. data/src/core/tsi/transport_security_adapter.c +236 -0
  244. data/src/core/tsi/transport_security_adapter.h +62 -0
  245. data/src/core/tsi/transport_security_interface.h +179 -66
  246. data/src/ruby/ext/grpc/extconf.rb +2 -1
  247. data/src/ruby/ext/grpc/rb_byte_buffer.c +8 -6
  248. data/src/ruby/ext/grpc/rb_call.c +56 -48
  249. data/src/ruby/ext/grpc/rb_call.h +3 -4
  250. data/src/ruby/ext/grpc/rb_call_credentials.c +23 -22
  251. data/src/ruby/ext/grpc/rb_channel.c +2 -3
  252. data/src/ruby/ext/grpc/rb_channel_args.c +11 -9
  253. data/src/ruby/ext/grpc/rb_channel_credentials.c +16 -12
  254. data/src/ruby/ext/grpc/rb_completion_queue.c +7 -9
  255. data/src/ruby/ext/grpc/rb_compression_options.c +7 -6
  256. data/src/ruby/ext/grpc/rb_event_thread.c +10 -12
  257. data/src/ruby/ext/grpc/rb_event_thread.h +1 -2
  258. data/src/ruby/ext/grpc/rb_grpc.c +11 -15
  259. data/src/ruby/ext/grpc/rb_grpc.h +2 -2
  260. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +16 -6
  261. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +25 -10
  262. data/src/ruby/ext/grpc/rb_server.c +26 -28
  263. data/src/ruby/lib/grpc/grpc.rb +1 -1
  264. data/src/ruby/lib/grpc/version.rb +1 -1
  265. data/third_party/cares/config_linux/ares_config.h +36 -2
  266. data/third_party/zlib/adler32.c +14 -7
  267. data/third_party/zlib/compress.c +24 -18
  268. data/third_party/zlib/crc32.c +29 -12
  269. data/third_party/zlib/deflate.c +499 -303
  270. data/third_party/zlib/deflate.h +19 -16
  271. data/third_party/zlib/gzguts.h +16 -7
  272. data/third_party/zlib/gzlib.c +17 -14
  273. data/third_party/zlib/gzread.c +108 -48
  274. data/third_party/zlib/gzwrite.c +210 -122
  275. data/third_party/zlib/infback.c +2 -2
  276. data/third_party/zlib/inffast.c +34 -51
  277. data/third_party/zlib/inflate.c +86 -37
  278. data/third_party/zlib/inflate.h +7 -4
  279. data/third_party/zlib/inftrees.c +12 -14
  280. data/third_party/zlib/trees.c +38 -61
  281. data/third_party/zlib/uncompr.c +66 -32
  282. data/third_party/zlib/zconf.h +32 -9
  283. data/third_party/zlib/zlib.h +298 -154
  284. data/third_party/zlib/zutil.c +25 -24
  285. data/third_party/zlib/zutil.h +35 -17
  286. metadata +63 -30
@@ -1,5 +1,5 @@
1
1
  /* inflate.h -- internal inflate state definition
2
- * Copyright (C) 1995-2009 Mark Adler
2
+ * Copyright (C) 1995-2016 Mark Adler
3
3
  * For conditions of distribution and use, see copyright notice in zlib.h
4
4
  */
5
5
 
@@ -18,7 +18,7 @@
18
18
 
19
19
  /* Possible inflate modes between inflate() calls */
20
20
  typedef enum {
21
- HEAD, /* i: waiting for magic header */
21
+ HEAD = 16180, /* i: waiting for magic header */
22
22
  FLAGS, /* i: waiting for method and flags (gzip) */
23
23
  TIME, /* i: waiting for modification time (gzip) */
24
24
  OS, /* i: waiting for extra flags and operating system (gzip) */
@@ -77,11 +77,14 @@ typedef enum {
77
77
  CHECK -> LENGTH -> DONE
78
78
  */
79
79
 
80
- /* state maintained between inflate() calls. Approximately 10K bytes. */
80
+ /* State maintained between inflate() calls -- approximately 7K bytes, not
81
+ including the allocated sliding window, which is up to 32K bytes. */
81
82
  struct inflate_state {
83
+ z_streamp strm; /* pointer back to this zlib stream */
82
84
  inflate_mode mode; /* current inflate mode */
83
85
  int last; /* true if processing last block */
84
- int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
86
+ int wrap; /* bit 0 true for zlib, bit 1 true for gzip,
87
+ bit 2 true to validate check value */
85
88
  int havedict; /* true if dictionary provided */
86
89
  int flags; /* gzip header method and flags (0 if zlib) */
87
90
  unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
@@ -1,5 +1,5 @@
1
1
  /* inftrees.c -- generate Huffman trees for efficient decoding
2
- * Copyright (C) 1995-2013 Mark Adler
2
+ * Copyright (C) 1995-2017 Mark Adler
3
3
  * For conditions of distribution and use, see copyright notice in zlib.h
4
4
  */
5
5
 
@@ -9,7 +9,7 @@
9
9
  #define MAXBITS 15
10
10
 
11
11
  const char inflate_copyright[] =
12
- " inflate 1.2.8 Copyright 1995-2013 Mark Adler ";
12
+ " inflate 1.2.11 Copyright 1995-2017 Mark Adler ";
13
13
  /*
14
14
  If you use the zlib library in a product, an acknowledgment is welcome
15
15
  in the documentation of your product. If for some reason you cannot
@@ -54,7 +54,7 @@ unsigned short FAR *work;
54
54
  code FAR *next; /* next available space in table */
55
55
  const unsigned short FAR *base; /* base value table to use */
56
56
  const unsigned short FAR *extra; /* extra bits table to use */
57
- int end; /* use base and extra for symbol > end */
57
+ unsigned match; /* use base and extra for symbol >= match */
58
58
  unsigned short count[MAXBITS+1]; /* number of codes of each length */
59
59
  unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
60
60
  static const unsigned short lbase[31] = { /* Length codes 257..285 base */
@@ -62,7 +62,7 @@ unsigned short FAR *work;
62
62
  35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
63
63
  static const unsigned short lext[31] = { /* Length codes 257..285 extra */
64
64
  16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
65
- 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78};
65
+ 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 77, 202};
66
66
  static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
67
67
  1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
68
68
  257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
@@ -181,19 +181,17 @@ unsigned short FAR *work;
181
181
  switch (type) {
182
182
  case CODES:
183
183
  base = extra = work; /* dummy value--not used */
184
- end = 19;
184
+ match = 20;
185
185
  break;
186
186
  case LENS:
187
187
  base = lbase;
188
- base -= 257;
189
188
  extra = lext;
190
- extra -= 257;
191
- end = 256;
189
+ match = 257;
192
190
  break;
193
- default: /* DISTS */
191
+ default: /* DISTS */
194
192
  base = dbase;
195
193
  extra = dext;
196
- end = -1;
194
+ match = 0;
197
195
  }
198
196
 
199
197
  /* initialize state for loop */
@@ -216,13 +214,13 @@ unsigned short FAR *work;
216
214
  for (;;) {
217
215
  /* create table entry */
218
216
  here.bits = (unsigned char)(len - drop);
219
- if ((int)(work[sym]) < end) {
217
+ if (work[sym] + 1U < match) {
220
218
  here.op = (unsigned char)0;
221
219
  here.val = work[sym];
222
220
  }
223
- else if ((int)(work[sym]) > end) {
224
- here.op = (unsigned char)(extra[work[sym]]);
225
- here.val = base[work[sym]];
221
+ else if (work[sym] >= match) {
222
+ here.op = (unsigned char)(extra[work[sym] - match]);
223
+ here.val = base[work[sym] - match];
226
224
  }
227
225
  else {
228
226
  here.op = (unsigned char)(32 + 64); /* end of block */
@@ -1,5 +1,5 @@
1
1
  /* trees.c -- output deflated data using Huffman coding
2
- * Copyright (C) 1995-2012 Jean-loup Gailly
2
+ * Copyright (C) 1995-2017 Jean-loup Gailly
3
3
  * detect_data_type() function provided freely by Cosmin Truta, 2006
4
4
  * For conditions of distribution and use, see copyright notice in zlib.h
5
5
  */
@@ -36,7 +36,7 @@
36
36
 
37
37
  #include "deflate.h"
38
38
 
39
- #ifdef DEBUG
39
+ #ifdef ZLIB_DEBUG
40
40
  # include <ctype.h>
41
41
  #endif
42
42
 
@@ -122,13 +122,13 @@ struct static_tree_desc_s {
122
122
  int max_length; /* max bit length for the codes */
123
123
  };
124
124
 
125
- local static_tree_desc static_l_desc =
125
+ local const static_tree_desc static_l_desc =
126
126
  {static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
127
127
 
128
- local static_tree_desc static_d_desc =
128
+ local const static_tree_desc static_d_desc =
129
129
  {static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
130
130
 
131
- local static_tree_desc static_bl_desc =
131
+ local const static_tree_desc static_bl_desc =
132
132
  {(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
133
133
 
134
134
  /* ===========================================================================
@@ -152,18 +152,16 @@ local int detect_data_type OF((deflate_state *s));
152
152
  local unsigned bi_reverse OF((unsigned value, int length));
153
153
  local void bi_windup OF((deflate_state *s));
154
154
  local void bi_flush OF((deflate_state *s));
155
- local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
156
- int header));
157
155
 
158
156
  #ifdef GEN_TREES_H
159
157
  local void gen_trees_header OF((void));
160
158
  #endif
161
159
 
162
- #ifndef DEBUG
160
+ #ifndef ZLIB_DEBUG
163
161
  # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
164
162
  /* Send a code of the given tree. c and tree must not have side effects */
165
163
 
166
- #else /* DEBUG */
164
+ #else /* !ZLIB_DEBUG */
167
165
  # define send_code(s, c, tree) \
168
166
  { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
169
167
  send_bits(s, tree[c].Code, tree[c].Len); }
@@ -182,7 +180,7 @@ local void gen_trees_header OF((void));
182
180
  * Send a value on a given number of bits.
183
181
  * IN assertion: length <= 16 and value fits in length bits.
184
182
  */
185
- #ifdef DEBUG
183
+ #ifdef ZLIB_DEBUG
186
184
  local void send_bits OF((deflate_state *s, int value, int length));
187
185
 
188
186
  local void send_bits(s, value, length)
@@ -208,12 +206,12 @@ local void send_bits(s, value, length)
208
206
  s->bi_valid += length;
209
207
  }
210
208
  }
211
- #else /* !DEBUG */
209
+ #else /* !ZLIB_DEBUG */
212
210
 
213
211
  #define send_bits(s, value, length) \
214
212
  { int len = length;\
215
213
  if (s->bi_valid > (int)Buf_size - len) {\
216
- int val = value;\
214
+ int val = (int)value;\
217
215
  s->bi_buf |= (ush)val << s->bi_valid;\
218
216
  put_short(s, s->bi_buf);\
219
217
  s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
@@ -223,7 +221,7 @@ local void send_bits(s, value, length)
223
221
  s->bi_valid += len;\
224
222
  }\
225
223
  }
226
- #endif /* DEBUG */
224
+ #endif /* ZLIB_DEBUG */
227
225
 
228
226
 
229
227
  /* the arguments must not have side effects */
@@ -317,7 +315,7 @@ local void tr_static_init()
317
315
  * Genererate the file trees.h describing the static trees.
318
316
  */
319
317
  #ifdef GEN_TREES_H
320
- # ifndef DEBUG
318
+ # ifndef ZLIB_DEBUG
321
319
  # include <stdio.h>
322
320
  # endif
323
321
 
@@ -394,7 +392,7 @@ void ZLIB_INTERNAL _tr_init(s)
394
392
 
395
393
  s->bi_buf = 0;
396
394
  s->bi_valid = 0;
397
- #ifdef DEBUG
395
+ #ifdef ZLIB_DEBUG
398
396
  s->compressed_len = 0L;
399
397
  s->bits_sent = 0L;
400
398
  #endif
@@ -522,12 +520,12 @@ local void gen_bitlen(s, desc)
522
520
  xbits = 0;
523
521
  if (n >= base) xbits = extra[n-base];
524
522
  f = tree[n].Freq;
525
- s->opt_len += (ulg)f * (bits + xbits);
526
- if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
523
+ s->opt_len += (ulg)f * (unsigned)(bits + xbits);
524
+ if (stree) s->static_len += (ulg)f * (unsigned)(stree[n].Len + xbits);
527
525
  }
528
526
  if (overflow == 0) return;
529
527
 
530
- Trace((stderr,"\nbit length overflow\n"));
528
+ Tracev((stderr,"\nbit length overflow\n"));
531
529
  /* This happens for example on obj2 and pic of the Calgary corpus */
532
530
 
533
531
  /* Find the first bit length which could increase: */
@@ -554,9 +552,8 @@ local void gen_bitlen(s, desc)
554
552
  m = s->heap[--h];
555
553
  if (m > max_code) continue;
556
554
  if ((unsigned) tree[m].Len != (unsigned) bits) {
557
- Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
558
- s->opt_len += ((long)bits - (long)tree[m].Len)
559
- *(long)tree[m].Freq;
555
+ Tracev((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
556
+ s->opt_len += ((ulg)bits - tree[m].Len) * tree[m].Freq;
560
557
  tree[m].Len = (ush)bits;
561
558
  }
562
559
  n--;
@@ -578,7 +575,7 @@ local void gen_codes (tree, max_code, bl_count)
578
575
  ushf *bl_count; /* number of codes at each bit length */
579
576
  {
580
577
  ush next_code[MAX_BITS+1]; /* next code value for each bit length */
581
- ush code = 0; /* running code value */
578
+ unsigned code = 0; /* running code value */
582
579
  int bits; /* bit index */
583
580
  int n; /* code index */
584
581
 
@@ -586,7 +583,8 @@ local void gen_codes (tree, max_code, bl_count)
586
583
  * without bit reversal.
587
584
  */
588
585
  for (bits = 1; bits <= MAX_BITS; bits++) {
589
- next_code[bits] = code = (code + bl_count[bits-1]) << 1;
586
+ code = (code + bl_count[bits-1]) << 1;
587
+ next_code[bits] = (ush)code;
590
588
  }
591
589
  /* Check that the bit counts in bl_count are consistent. The last code
592
590
  * must be all ones.
@@ -599,7 +597,7 @@ local void gen_codes (tree, max_code, bl_count)
599
597
  int len = tree[n].Len;
600
598
  if (len == 0) continue;
601
599
  /* Now reverse the bits */
602
- tree[n].Code = bi_reverse(next_code[len]++, len);
600
+ tree[n].Code = (ush)bi_reverse(next_code[len]++, len);
603
601
 
604
602
  Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
605
603
  n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
@@ -821,7 +819,7 @@ local int build_bl_tree(s)
821
819
  if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
822
820
  }
823
821
  /* Update opt_len to include the bit length tree and counts */
824
- s->opt_len += 3*(max_blindex+1) + 5+5+4;
822
+ s->opt_len += 3*((ulg)max_blindex+1) + 5+5+4;
825
823
  Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
826
824
  s->opt_len, s->static_len));
827
825
 
@@ -869,11 +867,17 @@ void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last)
869
867
  int last; /* one if this is the last block for a file */
870
868
  {
871
869
  send_bits(s, (STORED_BLOCK<<1)+last, 3); /* send block type */
872
- #ifdef DEBUG
870
+ bi_windup(s); /* align on byte boundary */
871
+ put_short(s, (ush)stored_len);
872
+ put_short(s, (ush)~stored_len);
873
+ zmemcpy(s->pending_buf + s->pending, (Bytef *)buf, stored_len);
874
+ s->pending += stored_len;
875
+ #ifdef ZLIB_DEBUG
873
876
  s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
874
877
  s->compressed_len += (stored_len + 4) << 3;
878
+ s->bits_sent += 2*16;
879
+ s->bits_sent += stored_len<<3;
875
880
  #endif
876
- copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
877
881
  }
878
882
 
879
883
  /* ===========================================================================
@@ -894,7 +898,7 @@ void ZLIB_INTERNAL _tr_align(s)
894
898
  {
895
899
  send_bits(s, STATIC_TREES<<1, 3);
896
900
  send_code(s, END_BLOCK, static_ltree);
897
- #ifdef DEBUG
901
+ #ifdef ZLIB_DEBUG
898
902
  s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
899
903
  #endif
900
904
  bi_flush(s);
@@ -902,7 +906,7 @@ void ZLIB_INTERNAL _tr_align(s)
902
906
 
903
907
  /* ===========================================================================
904
908
  * Determine the best encoding for the current block: dynamic trees, static
905
- * trees or store, and output the encoded block to the zip file.
909
+ * trees or store, and write out the encoded block.
906
910
  */
907
911
  void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
908
912
  deflate_state *s;
@@ -974,7 +978,7 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
974
978
  send_bits(s, (STATIC_TREES<<1)+last, 3);
975
979
  compress_block(s, (const ct_data *)static_ltree,
976
980
  (const ct_data *)static_dtree);
977
- #ifdef DEBUG
981
+ #ifdef ZLIB_DEBUG
978
982
  s->compressed_len += 3 + s->static_len;
979
983
  #endif
980
984
  } else {
@@ -983,7 +987,7 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
983
987
  max_blindex+1);
984
988
  compress_block(s, (const ct_data *)s->dyn_ltree,
985
989
  (const ct_data *)s->dyn_dtree);
986
- #ifdef DEBUG
990
+ #ifdef ZLIB_DEBUG
987
991
  s->compressed_len += 3 + s->opt_len;
988
992
  #endif
989
993
  }
@@ -995,7 +999,7 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
995
999
 
996
1000
  if (last) {
997
1001
  bi_windup(s);
998
- #ifdef DEBUG
1002
+ #ifdef ZLIB_DEBUG
999
1003
  s->compressed_len += 7; /* align on byte boundary */
1000
1004
  #endif
1001
1005
  }
@@ -1090,7 +1094,7 @@ local void compress_block(s, ltree, dtree)
1090
1094
  send_code(s, code, dtree); /* send the distance code */
1091
1095
  extra = extra_dbits[code];
1092
1096
  if (extra != 0) {
1093
- dist -= base_dist[code];
1097
+ dist -= (unsigned)base_dist[code];
1094
1098
  send_bits(s, dist, extra); /* send the extra distance bits */
1095
1099
  }
1096
1100
  } /* literal or match pair ? */
@@ -1193,34 +1197,7 @@ local void bi_windup(s)
1193
1197
  }
1194
1198
  s->bi_buf = 0;
1195
1199
  s->bi_valid = 0;
1196
- #ifdef DEBUG
1200
+ #ifdef ZLIB_DEBUG
1197
1201
  s->bits_sent = (s->bits_sent+7) & ~7;
1198
1202
  #endif
1199
1203
  }
1200
-
1201
- /* ===========================================================================
1202
- * Copy a stored block, storing first the length and its
1203
- * one's complement if requested.
1204
- */
1205
- local void copy_block(s, buf, len, header)
1206
- deflate_state *s;
1207
- charf *buf; /* the input data */
1208
- unsigned len; /* its length */
1209
- int header; /* true if block header must be written */
1210
- {
1211
- bi_windup(s); /* align on byte boundary */
1212
-
1213
- if (header) {
1214
- put_short(s, (ush)len);
1215
- put_short(s, (ush)~len);
1216
- #ifdef DEBUG
1217
- s->bits_sent += 2*16;
1218
- #endif
1219
- }
1220
- #ifdef DEBUG
1221
- s->bits_sent += (ulg)len<<3;
1222
- #endif
1223
- while (len--) {
1224
- put_byte(s, *buf++);
1225
- }
1226
- }
@@ -1,5 +1,5 @@
1
1
  /* uncompr.c -- decompress a memory buffer
2
- * Copyright (C) 1995-2003, 2010 Jean-loup Gailly.
2
+ * Copyright (C) 1995-2003, 2010, 2014, 2016 Jean-loup Gailly, Mark Adler
3
3
  * For conditions of distribution and use, see copyright notice in zlib.h
4
4
  */
5
5
 
@@ -9,51 +9,85 @@
9
9
  #include "zlib.h"
10
10
 
11
11
  /* ===========================================================================
12
- Decompresses the source buffer into the destination buffer. sourceLen is
13
- the byte length of the source buffer. Upon entry, destLen is the total
14
- size of the destination buffer, which must be large enough to hold the
15
- entire uncompressed data. (The size of the uncompressed data must have
16
- been saved previously by the compressor and transmitted to the decompressor
17
- by some mechanism outside the scope of this compression library.)
18
- Upon exit, destLen is the actual size of the compressed buffer.
19
-
20
- uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
21
- enough memory, Z_BUF_ERROR if there was not enough room in the output
22
- buffer, or Z_DATA_ERROR if the input data was corrupted.
12
+ Decompresses the source buffer into the destination buffer. *sourceLen is
13
+ the byte length of the source buffer. Upon entry, *destLen is the total size
14
+ of the destination buffer, which must be large enough to hold the entire
15
+ uncompressed data. (The size of the uncompressed data must have been saved
16
+ previously by the compressor and transmitted to the decompressor by some
17
+ mechanism outside the scope of this compression library.) Upon exit,
18
+ *destLen is the size of the decompressed data and *sourceLen is the number
19
+ of source bytes consumed. Upon return, source + *sourceLen points to the
20
+ first unused input byte.
21
+
22
+ uncompress returns Z_OK if success, Z_MEM_ERROR if there was not enough
23
+ memory, Z_BUF_ERROR if there was not enough room in the output buffer, or
24
+ Z_DATA_ERROR if the input data was corrupted, including if the input data is
25
+ an incomplete zlib stream.
23
26
  */
24
- int ZEXPORT uncompress (dest, destLen, source, sourceLen)
27
+ int ZEXPORT uncompress2 (dest, destLen, source, sourceLen)
25
28
  Bytef *dest;
26
29
  uLongf *destLen;
27
30
  const Bytef *source;
28
- uLong sourceLen;
31
+ uLong *sourceLen;
29
32
  {
30
33
  z_stream stream;
31
34
  int err;
35
+ const uInt max = (uInt)-1;
36
+ uLong len, left;
37
+ Byte buf[1]; /* for detection of incomplete stream when *destLen == 0 */
32
38
 
33
- stream.next_in = (z_const Bytef *)source;
34
- stream.avail_in = (uInt)sourceLen;
35
- /* Check for source > 64K on 16-bit machine: */
36
- if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
37
-
38
- stream.next_out = dest;
39
- stream.avail_out = (uInt)*destLen;
40
- if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
39
+ len = *sourceLen;
40
+ if (*destLen) {
41
+ left = *destLen;
42
+ *destLen = 0;
43
+ }
44
+ else {
45
+ left = 1;
46
+ dest = buf;
47
+ }
41
48
 
49
+ stream.next_in = (z_const Bytef *)source;
50
+ stream.avail_in = 0;
42
51
  stream.zalloc = (alloc_func)0;
43
52
  stream.zfree = (free_func)0;
53
+ stream.opaque = (voidpf)0;
44
54
 
45
55
  err = inflateInit(&stream);
46
56
  if (err != Z_OK) return err;
47
57
 
48
- err = inflate(&stream, Z_FINISH);
49
- if (err != Z_STREAM_END) {
50
- inflateEnd(&stream);
51
- if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))
52
- return Z_DATA_ERROR;
53
- return err;
54
- }
55
- *destLen = stream.total_out;
58
+ stream.next_out = dest;
59
+ stream.avail_out = 0;
56
60
 
57
- err = inflateEnd(&stream);
58
- return err;
61
+ do {
62
+ if (stream.avail_out == 0) {
63
+ stream.avail_out = left > (uLong)max ? max : (uInt)left;
64
+ left -= stream.avail_out;
65
+ }
66
+ if (stream.avail_in == 0) {
67
+ stream.avail_in = len > (uLong)max ? max : (uInt)len;
68
+ len -= stream.avail_in;
69
+ }
70
+ err = inflate(&stream, Z_NO_FLUSH);
71
+ } while (err == Z_OK);
72
+
73
+ *sourceLen -= len + stream.avail_in;
74
+ if (dest != buf)
75
+ *destLen = stream.total_out;
76
+ else if (stream.total_out && err == Z_BUF_ERROR)
77
+ left = 1;
78
+
79
+ inflateEnd(&stream);
80
+ return err == Z_STREAM_END ? Z_OK :
81
+ err == Z_NEED_DICT ? Z_DATA_ERROR :
82
+ err == Z_BUF_ERROR && left + stream.avail_out ? Z_DATA_ERROR :
83
+ err;
84
+ }
85
+
86
+ int ZEXPORT uncompress (dest, destLen, source, sourceLen)
87
+ Bytef *dest;
88
+ uLongf *destLen;
89
+ const Bytef *source;
90
+ uLong sourceLen;
91
+ {
92
+ return uncompress2(dest, destLen, source, &sourceLen);
59
93
  }