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
  /* deflate.h -- internal compression state
2
- * Copyright (C) 1995-2012 Jean-loup Gailly
2
+ * Copyright (C) 1995-2016 Jean-loup Gailly
3
3
  * For conditions of distribution and use, see copyright notice in zlib.h
4
4
  */
5
5
 
@@ -51,13 +51,16 @@
51
51
  #define Buf_size 16
52
52
  /* size of bit buffer in bi_buf */
53
53
 
54
- #define INIT_STATE 42
55
- #define EXTRA_STATE 69
56
- #define NAME_STATE 73
57
- #define COMMENT_STATE 91
58
- #define HCRC_STATE 103
59
- #define BUSY_STATE 113
60
- #define FINISH_STATE 666
54
+ #define INIT_STATE 42 /* zlib header -> BUSY_STATE */
55
+ #ifdef GZIP
56
+ # define GZIP_STATE 57 /* gzip header -> BUSY_STATE | EXTRA_STATE */
57
+ #endif
58
+ #define EXTRA_STATE 69 /* gzip extra block -> NAME_STATE */
59
+ #define NAME_STATE 73 /* gzip file name -> COMMENT_STATE */
60
+ #define COMMENT_STATE 91 /* gzip comment -> HCRC_STATE */
61
+ #define HCRC_STATE 103 /* gzip header CRC -> BUSY_STATE */
62
+ #define BUSY_STATE 113 /* deflate -> FINISH_STATE */
63
+ #define FINISH_STATE 666 /* stream complete */
61
64
  /* Stream status */
62
65
 
63
66
 
@@ -83,7 +86,7 @@ typedef struct static_tree_desc_s static_tree_desc;
83
86
  typedef struct tree_desc_s {
84
87
  ct_data *dyn_tree; /* the dynamic tree */
85
88
  int max_code; /* largest code with non zero frequency */
86
- static_tree_desc *stat_desc; /* the corresponding static tree */
89
+ const static_tree_desc *stat_desc; /* the corresponding static tree */
87
90
  } FAR tree_desc;
88
91
 
89
92
  typedef ush Pos;
@@ -100,10 +103,10 @@ typedef struct internal_state {
100
103
  Bytef *pending_buf; /* output still pending */
101
104
  ulg pending_buf_size; /* size of pending_buf */
102
105
  Bytef *pending_out; /* next pending byte to output to the stream */
103
- uInt pending; /* nb of bytes in the pending buffer */
106
+ ulg pending; /* nb of bytes in the pending buffer */
104
107
  int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
105
108
  gz_headerp gzhead; /* gzip header information to write */
106
- uInt gzindex; /* where in extra, name, or comment */
109
+ ulg gzindex; /* where in extra, name, or comment */
107
110
  Byte method; /* can only be DEFLATED */
108
111
  int last_flush; /* value of flush param for previous deflate call */
109
112
 
@@ -249,7 +252,7 @@ typedef struct internal_state {
249
252
  uInt matches; /* number of string matches in current block */
250
253
  uInt insert; /* bytes at end of window left to insert */
251
254
 
252
- #ifdef DEBUG
255
+ #ifdef ZLIB_DEBUG
253
256
  ulg compressed_len; /* total bit length of compressed file mod 2^32 */
254
257
  ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
255
258
  #endif
@@ -275,7 +278,7 @@ typedef struct internal_state {
275
278
  /* Output a byte on the stream.
276
279
  * IN assertion: there is enough room in pending_buf.
277
280
  */
278
- #define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
281
+ #define put_byte(s, c) {s->pending_buf[s->pending++] = (Bytef)(c);}
279
282
 
280
283
 
281
284
  #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
@@ -309,7 +312,7 @@ void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
309
312
  * used.
310
313
  */
311
314
 
312
- #ifndef DEBUG
315
+ #ifndef ZLIB_DEBUG
313
316
  /* Inline versions of _tr_tally for speed: */
314
317
 
315
318
  #if defined(GEN_TREES_H) || !defined(STDC)
@@ -328,8 +331,8 @@ void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
328
331
  flush = (s->last_lit == s->lit_bufsize-1); \
329
332
  }
330
333
  # define _tr_tally_dist(s, distance, length, flush) \
331
- { uch len = (length); \
332
- ush dist = (distance); \
334
+ { uch len = (uch)(length); \
335
+ ush dist = (ush)(distance); \
333
336
  s->d_buf[s->last_lit] = dist; \
334
337
  s->l_buf[s->last_lit++] = len; \
335
338
  dist--; \
@@ -1,5 +1,5 @@
1
1
  /* gzguts.h -- zlib internal header definitions for gz* operations
2
- * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler
2
+ * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013, 2016 Mark Adler
3
3
  * For conditions of distribution and use, see copyright notice in zlib.h
4
4
  */
5
5
 
@@ -25,6 +25,10 @@
25
25
  # include <stdlib.h>
26
26
  # include <limits.h>
27
27
  #endif
28
+
29
+ #ifndef _POSIX_SOURCE
30
+ # define _POSIX_SOURCE
31
+ #endif
28
32
  #include <fcntl.h>
29
33
 
30
34
  #ifdef _WIN32
@@ -35,6 +39,10 @@
35
39
  # include <io.h>
36
40
  #endif
37
41
 
42
+ #if defined(_WIN32) || defined(__CYGWIN__)
43
+ # define WIDECHAR
44
+ #endif
45
+
38
46
  #ifdef WINAPI_FAMILY
39
47
  # define open _open
40
48
  # define read _read
@@ -95,18 +103,19 @@
95
103
  # endif
96
104
  #endif
97
105
 
98
- /* unlike snprintf (which is required in C99, yet still not supported by
99
- Microsoft more than a decade later!), _snprintf does not guarantee null
100
- termination of the result -- however this is only used in gzlib.c where
106
+ /* unlike snprintf (which is required in C99), _snprintf does not guarantee
107
+ null termination of the result -- however this is only used in gzlib.c where
101
108
  the result is assured to fit in the space provided */
102
- #ifdef _MSC_VER
109
+ #if defined(_MSC_VER) && _MSC_VER < 1900
103
110
  # define snprintf _snprintf
104
111
  #endif
105
112
 
106
113
  #ifndef local
107
114
  # define local static
108
115
  #endif
109
- /* compile with -Dlocal if your debugger can't find static symbols */
116
+ /* since "static" is used to mean two completely different things in C, we
117
+ define "local" for the non-static meaning of "static", for readability
118
+ (compile with -Dlocal if your debugger can't find static symbols) */
110
119
 
111
120
  /* gz* functions always use library allocation functions */
112
121
  #ifndef STDC
@@ -170,7 +179,7 @@ typedef struct {
170
179
  char *path; /* path or fd for error messages */
171
180
  unsigned size; /* buffer size, zero if not allocated yet */
172
181
  unsigned want; /* requested buffer size, default is GZBUFSIZE */
173
- unsigned char *in; /* input buffer */
182
+ unsigned char *in; /* input buffer (double-sized when writing) */
174
183
  unsigned char *out; /* output buffer (double-sized when reading) */
175
184
  int direct; /* 0 if processing gzip, 1 if transparent */
176
185
  /* just for reading */
@@ -1,11 +1,11 @@
1
1
  /* gzlib.c -- zlib functions common to reading and writing gzip files
2
- * Copyright (C) 2004, 2010, 2011, 2012, 2013 Mark Adler
2
+ * Copyright (C) 2004-2017 Mark Adler
3
3
  * For conditions of distribution and use, see copyright notice in zlib.h
4
4
  */
5
5
 
6
6
  #include "gzguts.h"
7
7
 
8
- #if defined(_WIN32) && !defined(__BORLANDC__)
8
+ #if defined(_WIN32) && !defined(__BORLANDC__) && !defined(__MINGW32__)
9
9
  # define LSEEK _lseeki64
10
10
  #else
11
11
  #if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
@@ -94,7 +94,7 @@ local gzFile gz_open(path, fd, mode)
94
94
  const char *mode;
95
95
  {
96
96
  gz_statep state;
97
- size_t len;
97
+ z_size_t len;
98
98
  int oflag;
99
99
  #ifdef O_CLOEXEC
100
100
  int cloexec = 0;
@@ -188,10 +188,10 @@ local gzFile gz_open(path, fd, mode)
188
188
  }
189
189
 
190
190
  /* save the path name for error messages */
191
- #ifdef _WIN32
191
+ #ifdef WIDECHAR
192
192
  if (fd == -2) {
193
193
  len = wcstombs(NULL, path, 0);
194
- if (len == (size_t)-1)
194
+ if (len == (z_size_t)-1)
195
195
  len = 0;
196
196
  }
197
197
  else
@@ -202,7 +202,7 @@ local gzFile gz_open(path, fd, mode)
202
202
  free(state);
203
203
  return NULL;
204
204
  }
205
- #ifdef _WIN32
205
+ #ifdef WIDECHAR
206
206
  if (fd == -2)
207
207
  if (len)
208
208
  wcstombs(state->path, path, len + 1);
@@ -211,7 +211,7 @@ local gzFile gz_open(path, fd, mode)
211
211
  else
212
212
  #endif
213
213
  #if !defined(NO_snprintf) && !defined(NO_vsnprintf)
214
- snprintf(state->path, len + 1, "%s", (const char *)path);
214
+ (void)snprintf(state->path, len + 1, "%s", (const char *)path);
215
215
  #else
216
216
  strcpy(state->path, path);
217
217
  #endif
@@ -239,7 +239,7 @@ local gzFile gz_open(path, fd, mode)
239
239
 
240
240
  /* open the file with the appropriate flags (or just use fd) */
241
241
  state->fd = fd > -1 ? fd : (
242
- #ifdef _WIN32
242
+ #ifdef WIDECHAR
243
243
  fd == -2 ? _wopen(path, oflag, 0666) :
244
244
  #endif
245
245
  open((const char *)path, oflag, 0666));
@@ -248,8 +248,10 @@ local gzFile gz_open(path, fd, mode)
248
248
  free(state);
249
249
  return NULL;
250
250
  }
251
- if (state->mode == GZ_APPEND)
251
+ if (state->mode == GZ_APPEND) {
252
+ LSEEK(state->fd, 0, SEEK_END); /* so gzoffset() is correct */
252
253
  state->mode = GZ_WRITE; /* simplify later checks */
254
+ }
253
255
 
254
256
  /* save the current position for rewinding (only if reading) */
255
257
  if (state->mode == GZ_READ) {
@@ -291,7 +293,7 @@ gzFile ZEXPORT gzdopen(fd, mode)
291
293
  if (fd == -1 || (path = (char *)malloc(7 + 3 * sizeof(int))) == NULL)
292
294
  return NULL;
293
295
  #if !defined(NO_snprintf) && !defined(NO_vsnprintf)
294
- snprintf(path, 7 + 3 * sizeof(int), "<fd:%d>", fd); /* for debugging */
296
+ (void)snprintf(path, 7 + 3 * sizeof(int), "<fd:%d>", fd);
295
297
  #else
296
298
  sprintf(path, "<fd:%d>", fd); /* for debugging */
297
299
  #endif
@@ -301,7 +303,7 @@ gzFile ZEXPORT gzdopen(fd, mode)
301
303
  }
302
304
 
303
305
  /* -- see zlib.h -- */
304
- #ifdef _WIN32
306
+ #ifdef WIDECHAR
305
307
  gzFile ZEXPORT gzopen_w(path, mode)
306
308
  const wchar_t *path;
307
309
  const char *mode;
@@ -329,6 +331,8 @@ int ZEXPORT gzbuffer(file, size)
329
331
  return -1;
330
332
 
331
333
  /* check and set requested size */
334
+ if ((size << 1) < size)
335
+ return -1; /* need to be able to double it */
332
336
  if (size < 2)
333
337
  size = 2; /* need two bytes to check magic header */
334
338
  state->want = size;
@@ -604,14 +608,13 @@ void ZLIB_INTERNAL gz_error(state, err, msg)
604
608
  return;
605
609
  }
606
610
  #if !defined(NO_snprintf) && !defined(NO_vsnprintf)
607
- snprintf(state->msg, strlen(state->path) + strlen(msg) + 3,
608
- "%s%s%s", state->path, ": ", msg);
611
+ (void)snprintf(state->msg, strlen(state->path) + strlen(msg) + 3,
612
+ "%s%s%s", state->path, ": ", msg);
609
613
  #else
610
614
  strcpy(state->msg, state->path);
611
615
  strcat(state->msg, ": ");
612
616
  strcat(state->msg, msg);
613
617
  #endif
614
- return;
615
618
  }
616
619
 
617
620
  #ifndef INT_MAX
@@ -1,5 +1,5 @@
1
1
  /* gzread.c -- zlib functions for reading gzip files
2
- * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler
2
+ * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013, 2016 Mark Adler
3
3
  * For conditions of distribution and use, see copyright notice in zlib.h
4
4
  */
5
5
 
@@ -12,6 +12,7 @@ local int gz_look OF((gz_statep));
12
12
  local int gz_decomp OF((gz_statep));
13
13
  local int gz_fetch OF((gz_statep));
14
14
  local int gz_skip OF((gz_statep, z_off64_t));
15
+ local z_size_t gz_read OF((gz_statep, voidp, z_size_t));
15
16
 
16
17
  /* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from
17
18
  state->fd, and update state->eof, state->err, and state->msg as appropriate.
@@ -24,13 +25,17 @@ local int gz_load(state, buf, len, have)
24
25
  unsigned *have;
25
26
  {
26
27
  int ret;
28
+ unsigned get, max = ((unsigned)-1 >> 2) + 1;
27
29
 
28
30
  *have = 0;
29
31
  do {
30
- ret = read(state->fd, buf + *have, len - *have);
32
+ get = len - *have;
33
+ if (get > max)
34
+ get = max;
35
+ ret = read(state->fd, buf + *have, get);
31
36
  if (ret <= 0)
32
37
  break;
33
- *have += ret;
38
+ *have += (unsigned)ret;
34
39
  } while (*have < len);
35
40
  if (ret < 0) {
36
41
  gz_error(state, Z_ERRNO, zstrerror());
@@ -94,10 +99,8 @@ local int gz_look(state)
94
99
  state->in = (unsigned char *)malloc(state->want);
95
100
  state->out = (unsigned char *)malloc(state->want << 1);
96
101
  if (state->in == NULL || state->out == NULL) {
97
- if (state->out != NULL)
98
- free(state->out);
99
- if (state->in != NULL)
100
- free(state->in);
102
+ free(state->out);
103
+ free(state->in);
101
104
  gz_error(state, Z_MEM_ERROR, "out of memory");
102
105
  return -1;
103
106
  }
@@ -284,33 +287,17 @@ local int gz_skip(state, len)
284
287
  return 0;
285
288
  }
286
289
 
287
- /* -- see zlib.h -- */
288
- int ZEXPORT gzread(file, buf, len)
289
- gzFile file;
290
+ /* Read len bytes into buf from file, or less than len up to the end of the
291
+ input. Return the number of bytes read. If zero is returned, either the
292
+ end of file was reached, or there was an error. state->err must be
293
+ consulted in that case to determine which. */
294
+ local z_size_t gz_read(state, buf, len)
295
+ gz_statep state;
290
296
  voidp buf;
291
- unsigned len;
297
+ z_size_t len;
292
298
  {
293
- unsigned got, n;
294
- gz_statep state;
295
- z_streamp strm;
296
-
297
- /* get internal structure */
298
- if (file == NULL)
299
- return -1;
300
- state = (gz_statep)file;
301
- strm = &(state->strm);
302
-
303
- /* check that we're reading and that there's no (serious) error */
304
- if (state->mode != GZ_READ ||
305
- (state->err != Z_OK && state->err != Z_BUF_ERROR))
306
- return -1;
307
-
308
- /* since an int is returned, make sure len fits in one, otherwise return
309
- with an error (this avoids the flaw in the interface) */
310
- if ((int)len < 0) {
311
- gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
312
- return -1;
313
- }
299
+ z_size_t got;
300
+ unsigned n;
314
301
 
315
302
  /* if len is zero, avoid unnecessary operations */
316
303
  if (len == 0)
@@ -320,32 +307,38 @@ int ZEXPORT gzread(file, buf, len)
320
307
  if (state->seek) {
321
308
  state->seek = 0;
322
309
  if (gz_skip(state, state->skip) == -1)
323
- return -1;
310
+ return 0;
324
311
  }
325
312
 
326
313
  /* get len bytes to buf, or less than len if at the end */
327
314
  got = 0;
328
315
  do {
316
+ /* set n to the maximum amount of len that fits in an unsigned int */
317
+ n = -1;
318
+ if (n > len)
319
+ n = len;
320
+
329
321
  /* first just try copying data from the output buffer */
330
322
  if (state->x.have) {
331
- n = state->x.have > len ? len : state->x.have;
323
+ if (state->x.have < n)
324
+ n = state->x.have;
332
325
  memcpy(buf, state->x.next, n);
333
326
  state->x.next += n;
334
327
  state->x.have -= n;
335
328
  }
336
329
 
337
330
  /* output buffer empty -- return if we're at the end of the input */
338
- else if (state->eof && strm->avail_in == 0) {
331
+ else if (state->eof && state->strm.avail_in == 0) {
339
332
  state->past = 1; /* tried to read past end */
340
333
  break;
341
334
  }
342
335
 
343
336
  /* need output data -- for small len or new stream load up our output
344
337
  buffer */
345
- else if (state->how == LOOK || len < (state->size << 1)) {
338
+ else if (state->how == LOOK || n < (state->size << 1)) {
346
339
  /* get more output, looking for header if required */
347
340
  if (gz_fetch(state) == -1)
348
- return -1;
341
+ return 0;
349
342
  continue; /* no progress yet -- go back to copy above */
350
343
  /* the copy above assures that we will leave with space in the
351
344
  output buffer, allowing at least one gzungetc() to succeed */
@@ -353,16 +346,16 @@ int ZEXPORT gzread(file, buf, len)
353
346
 
354
347
  /* large len -- read directly into user buffer */
355
348
  else if (state->how == COPY) { /* read directly */
356
- if (gz_load(state, (unsigned char *)buf, len, &n) == -1)
357
- return -1;
349
+ if (gz_load(state, (unsigned char *)buf, n, &n) == -1)
350
+ return 0;
358
351
  }
359
352
 
360
353
  /* large len -- decompress directly into user buffer */
361
354
  else { /* state->how == GZIP */
362
- strm->avail_out = len;
363
- strm->next_out = (unsigned char *)buf;
355
+ state->strm.avail_out = n;
356
+ state->strm.next_out = (unsigned char *)buf;
364
357
  if (gz_decomp(state) == -1)
365
- return -1;
358
+ return 0;
366
359
  n = state->x.have;
367
360
  state->x.have = 0;
368
361
  }
@@ -374,8 +367,75 @@ int ZEXPORT gzread(file, buf, len)
374
367
  state->x.pos += n;
375
368
  } while (len);
376
369
 
377
- /* return number of bytes read into user buffer (will fit in int) */
378
- return (int)got;
370
+ /* return number of bytes read into user buffer */
371
+ return got;
372
+ }
373
+
374
+ /* -- see zlib.h -- */
375
+ int ZEXPORT gzread(file, buf, len)
376
+ gzFile file;
377
+ voidp buf;
378
+ unsigned len;
379
+ {
380
+ gz_statep state;
381
+
382
+ /* get internal structure */
383
+ if (file == NULL)
384
+ return -1;
385
+ state = (gz_statep)file;
386
+
387
+ /* check that we're reading and that there's no (serious) error */
388
+ if (state->mode != GZ_READ ||
389
+ (state->err != Z_OK && state->err != Z_BUF_ERROR))
390
+ return -1;
391
+
392
+ /* since an int is returned, make sure len fits in one, otherwise return
393
+ with an error (this avoids a flaw in the interface) */
394
+ if ((int)len < 0) {
395
+ gz_error(state, Z_STREAM_ERROR, "request does not fit in an int");
396
+ return -1;
397
+ }
398
+
399
+ /* read len or fewer bytes to buf */
400
+ len = gz_read(state, buf, len);
401
+
402
+ /* check for an error */
403
+ if (len == 0 && state->err != Z_OK && state->err != Z_BUF_ERROR)
404
+ return -1;
405
+
406
+ /* return the number of bytes read (this is assured to fit in an int) */
407
+ return (int)len;
408
+ }
409
+
410
+ /* -- see zlib.h -- */
411
+ z_size_t ZEXPORT gzfread(buf, size, nitems, file)
412
+ voidp buf;
413
+ z_size_t size;
414
+ z_size_t nitems;
415
+ gzFile file;
416
+ {
417
+ z_size_t len;
418
+ gz_statep state;
419
+
420
+ /* get internal structure */
421
+ if (file == NULL)
422
+ return 0;
423
+ state = (gz_statep)file;
424
+
425
+ /* check that we're reading and that there's no (serious) error */
426
+ if (state->mode != GZ_READ ||
427
+ (state->err != Z_OK && state->err != Z_BUF_ERROR))
428
+ return 0;
429
+
430
+ /* compute bytes to read -- error on overflow */
431
+ len = nitems * size;
432
+ if (size && len / size != nitems) {
433
+ gz_error(state, Z_STREAM_ERROR, "request does not fit in a size_t");
434
+ return 0;
435
+ }
436
+
437
+ /* read len or fewer bytes to buf, return the number of full items read */
438
+ return len ? gz_read(state, buf, len) / size : 0;
379
439
  }
380
440
 
381
441
  /* -- see zlib.h -- */
@@ -408,8 +468,8 @@ int ZEXPORT gzgetc(file)
408
468
  return *(state->x.next)++;
409
469
  }
410
470
 
411
- /* nothing there -- try gzread() */
412
- ret = gzread(file, buf, 1);
471
+ /* nothing there -- try gz_read() */
472
+ ret = gz_read(state, buf, 1);
413
473
  return ret < 1 ? -1 : buf[0];
414
474
  }
415
475
 
@@ -451,7 +511,7 @@ int ZEXPORT gzungetc(c, file)
451
511
  if (state->x.have == 0) {
452
512
  state->x.have = 1;
453
513
  state->x.next = state->out + (state->size << 1) - 1;
454
- state->x.next[0] = c;
514
+ state->x.next[0] = (unsigned char)c;
455
515
  state->x.pos--;
456
516
  state->past = 0;
457
517
  return c;
@@ -473,7 +533,7 @@ int ZEXPORT gzungetc(c, file)
473
533
  }
474
534
  state->x.have++;
475
535
  state->x.next--;
476
- state->x.next[0] = c;
536
+ state->x.next[0] = (unsigned char)c;
477
537
  state->x.pos--;
478
538
  state->past = 0;
479
539
  return c;