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
  /* gzwrite.c -- zlib functions for writing gzip files
2
- * Copyright (C) 2004, 2005, 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
 
@@ -9,17 +9,19 @@
9
9
  local int gz_init OF((gz_statep));
10
10
  local int gz_comp OF((gz_statep, int));
11
11
  local int gz_zero OF((gz_statep, z_off64_t));
12
+ local z_size_t gz_write OF((gz_statep, voidpc, z_size_t));
12
13
 
13
14
  /* Initialize state for writing a gzip file. Mark initialization by setting
14
- state->size to non-zero. Return -1 on failure or 0 on success. */
15
+ state->size to non-zero. Return -1 on a memory allocation failure, or 0 on
16
+ success. */
15
17
  local int gz_init(state)
16
18
  gz_statep state;
17
19
  {
18
20
  int ret;
19
21
  z_streamp strm = &(state->strm);
20
22
 
21
- /* allocate input buffer */
22
- state->in = (unsigned char *)malloc(state->want);
23
+ /* allocate input buffer (double size for gzprintf) */
24
+ state->in = (unsigned char *)malloc(state->want << 1);
23
25
  if (state->in == NULL) {
24
26
  gz_error(state, Z_MEM_ERROR, "out of memory");
25
27
  return -1;
@@ -47,6 +49,7 @@ local int gz_init(state)
47
49
  gz_error(state, Z_MEM_ERROR, "out of memory");
48
50
  return -1;
49
51
  }
52
+ strm->next_in = NULL;
50
53
  }
51
54
 
52
55
  /* mark state as initialized */
@@ -62,17 +65,17 @@ local int gz_init(state)
62
65
  }
63
66
 
64
67
  /* Compress whatever is at avail_in and next_in and write to the output file.
65
- Return -1 if there is an error writing to the output file, otherwise 0.
66
- flush is assumed to be a valid deflate() flush value. If flush is Z_FINISH,
67
- then the deflate() state is reset to start a new gzip stream. If gz->direct
68
- is true, then simply write to the output file without compressing, and
69
- ignore flush. */
68
+ Return -1 if there is an error writing to the output file or if gz_init()
69
+ fails to allocate memory, otherwise 0. flush is assumed to be a valid
70
+ deflate() flush value. If flush is Z_FINISH, then the deflate() state is
71
+ reset to start a new gzip stream. If gz->direct is true, then simply write
72
+ to the output file without compressing, and ignore flush. */
70
73
  local int gz_comp(state, flush)
71
74
  gz_statep state;
72
75
  int flush;
73
76
  {
74
- int ret, got;
75
- unsigned have;
77
+ int ret, writ;
78
+ unsigned have, put, max = ((unsigned)-1 >> 2) + 1;
76
79
  z_streamp strm = &(state->strm);
77
80
 
78
81
  /* allocate memory if this is the first time through */
@@ -81,12 +84,16 @@ local int gz_comp(state, flush)
81
84
 
82
85
  /* write directly if requested */
83
86
  if (state->direct) {
84
- got = write(state->fd, strm->next_in, strm->avail_in);
85
- if (got < 0 || (unsigned)got != strm->avail_in) {
86
- gz_error(state, Z_ERRNO, zstrerror());
87
- return -1;
87
+ while (strm->avail_in) {
88
+ put = strm->avail_in > max ? max : strm->avail_in;
89
+ writ = write(state->fd, strm->next_in, put);
90
+ if (writ < 0) {
91
+ gz_error(state, Z_ERRNO, zstrerror());
92
+ return -1;
93
+ }
94
+ strm->avail_in -= (unsigned)writ;
95
+ strm->next_in += writ;
88
96
  }
89
- strm->avail_in = 0;
90
97
  return 0;
91
98
  }
92
99
 
@@ -97,17 +104,21 @@ local int gz_comp(state, flush)
97
104
  doing Z_FINISH then don't write until we get to Z_STREAM_END */
98
105
  if (strm->avail_out == 0 || (flush != Z_NO_FLUSH &&
99
106
  (flush != Z_FINISH || ret == Z_STREAM_END))) {
100
- have = (unsigned)(strm->next_out - state->x.next);
101
- if (have && ((got = write(state->fd, state->x.next, have)) < 0 ||
102
- (unsigned)got != have)) {
103
- gz_error(state, Z_ERRNO, zstrerror());
104
- return -1;
107
+ while (strm->next_out > state->x.next) {
108
+ put = strm->next_out - state->x.next > (int)max ? max :
109
+ (unsigned)(strm->next_out - state->x.next);
110
+ writ = write(state->fd, state->x.next, put);
111
+ if (writ < 0) {
112
+ gz_error(state, Z_ERRNO, zstrerror());
113
+ return -1;
114
+ }
115
+ state->x.next += writ;
105
116
  }
106
117
  if (strm->avail_out == 0) {
107
118
  strm->avail_out = state->size;
108
119
  strm->next_out = state->out;
120
+ state->x.next = state->out;
109
121
  }
110
- state->x.next = strm->next_out;
111
122
  }
112
123
 
113
124
  /* compress */
@@ -129,7 +140,8 @@ local int gz_comp(state, flush)
129
140
  return 0;
130
141
  }
131
142
 
132
- /* Compress len zeros to output. Return -1 on error, 0 on success. */
143
+ /* Compress len zeros to output. Return -1 on a write error or memory
144
+ allocation failure by gz_comp(), or 0 on success. */
133
145
  local int gz_zero(state, len)
134
146
  gz_statep state;
135
147
  z_off64_t len;
@@ -161,32 +173,14 @@ local int gz_zero(state, len)
161
173
  return 0;
162
174
  }
163
175
 
164
- /* -- see zlib.h -- */
165
- int ZEXPORT gzwrite(file, buf, len)
166
- gzFile file;
176
+ /* Write len bytes from buf to file. Return the number of bytes written. If
177
+ the returned value is less than len, then there was an error. */
178
+ local z_size_t gz_write(state, buf, len)
179
+ gz_statep state;
167
180
  voidpc buf;
168
- unsigned len;
181
+ z_size_t len;
169
182
  {
170
- unsigned put = len;
171
- gz_statep state;
172
- z_streamp strm;
173
-
174
- /* get internal structure */
175
- if (file == NULL)
176
- return 0;
177
- state = (gz_statep)file;
178
- strm = &(state->strm);
179
-
180
- /* check that we're writing and that there's no error */
181
- if (state->mode != GZ_WRITE || state->err != Z_OK)
182
- return 0;
183
-
184
- /* since an int is returned, make sure len fits in one, otherwise return
185
- with an error (this avoids the flaw in the interface) */
186
- if ((int)len < 0) {
187
- gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
188
- return 0;
189
- }
183
+ z_size_t put = len;
190
184
 
191
185
  /* if len is zero, avoid unnecessary operations */
192
186
  if (len == 0)
@@ -209,14 +203,15 @@ int ZEXPORT gzwrite(file, buf, len)
209
203
  do {
210
204
  unsigned have, copy;
211
205
 
212
- if (strm->avail_in == 0)
213
- strm->next_in = state->in;
214
- have = (unsigned)((strm->next_in + strm->avail_in) - state->in);
206
+ if (state->strm.avail_in == 0)
207
+ state->strm.next_in = state->in;
208
+ have = (unsigned)((state->strm.next_in + state->strm.avail_in) -
209
+ state->in);
215
210
  copy = state->size - have;
216
211
  if (copy > len)
217
212
  copy = len;
218
213
  memcpy(state->in + have, buf, copy);
219
- strm->avail_in += copy;
214
+ state->strm.avail_in += copy;
220
215
  state->x.pos += copy;
221
216
  buf = (const char *)buf + copy;
222
217
  len -= copy;
@@ -226,19 +221,83 @@ int ZEXPORT gzwrite(file, buf, len)
226
221
  }
227
222
  else {
228
223
  /* consume whatever's left in the input buffer */
229
- if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
224
+ if (state->strm.avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
230
225
  return 0;
231
226
 
232
227
  /* directly compress user buffer to file */
233
- strm->avail_in = len;
234
- strm->next_in = (z_const Bytef *)buf;
235
- state->x.pos += len;
236
- if (gz_comp(state, Z_NO_FLUSH) == -1)
237
- return 0;
228
+ state->strm.next_in = (z_const Bytef *)buf;
229
+ do {
230
+ unsigned n = (unsigned)-1;
231
+ if (n > len)
232
+ n = len;
233
+ state->strm.avail_in = n;
234
+ state->x.pos += n;
235
+ if (gz_comp(state, Z_NO_FLUSH) == -1)
236
+ return 0;
237
+ len -= n;
238
+ } while (len);
239
+ }
240
+
241
+ /* input was all buffered or compressed */
242
+ return put;
243
+ }
244
+
245
+ /* -- see zlib.h -- */
246
+ int ZEXPORT gzwrite(file, buf, len)
247
+ gzFile file;
248
+ voidpc buf;
249
+ unsigned len;
250
+ {
251
+ gz_statep state;
252
+
253
+ /* get internal structure */
254
+ if (file == NULL)
255
+ return 0;
256
+ state = (gz_statep)file;
257
+
258
+ /* check that we're writing and that there's no error */
259
+ if (state->mode != GZ_WRITE || state->err != Z_OK)
260
+ return 0;
261
+
262
+ /* since an int is returned, make sure len fits in one, otherwise return
263
+ with an error (this avoids a flaw in the interface) */
264
+ if ((int)len < 0) {
265
+ gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
266
+ return 0;
267
+ }
268
+
269
+ /* write len bytes from buf (the return value will fit in an int) */
270
+ return (int)gz_write(state, buf, len);
271
+ }
272
+
273
+ /* -- see zlib.h -- */
274
+ z_size_t ZEXPORT gzfwrite(buf, size, nitems, file)
275
+ voidpc buf;
276
+ z_size_t size;
277
+ z_size_t nitems;
278
+ gzFile file;
279
+ {
280
+ z_size_t len;
281
+ gz_statep state;
282
+
283
+ /* get internal structure */
284
+ if (file == NULL)
285
+ return 0;
286
+ state = (gz_statep)file;
287
+
288
+ /* check that we're writing and that there's no error */
289
+ if (state->mode != GZ_WRITE || state->err != Z_OK)
290
+ return 0;
291
+
292
+ /* compute bytes to read -- error on overflow */
293
+ len = nitems * size;
294
+ if (size && len / size != nitems) {
295
+ gz_error(state, Z_STREAM_ERROR, "request does not fit in a size_t");
296
+ return 0;
238
297
  }
239
298
 
240
- /* input was all buffered or compressed (put will fit in int) */
241
- return (int)put;
299
+ /* write len bytes to buf, return the number of full items written */
300
+ return len ? gz_write(state, buf, len) / size : 0;
242
301
  }
243
302
 
244
303
  /* -- see zlib.h -- */
@@ -275,7 +334,7 @@ int ZEXPORT gzputc(file, c)
275
334
  strm->next_in = state->in;
276
335
  have = (unsigned)((strm->next_in + strm->avail_in) - state->in);
277
336
  if (have < state->size) {
278
- state->in[have] = c;
337
+ state->in[have] = (unsigned char)c;
279
338
  strm->avail_in++;
280
339
  state->x.pos++;
281
340
  return c & 0xff;
@@ -283,8 +342,8 @@ int ZEXPORT gzputc(file, c)
283
342
  }
284
343
 
285
344
  /* no room in buffer or not initialized, use gz_write() */
286
- buf[0] = c;
287
- if (gzwrite(file, buf, 1) != 1)
345
+ buf[0] = (unsigned char)c;
346
+ if (gz_write(state, buf, 1) != 1)
288
347
  return -1;
289
348
  return c & 0xff;
290
349
  }
@@ -295,11 +354,21 @@ int ZEXPORT gzputs(file, str)
295
354
  const char *str;
296
355
  {
297
356
  int ret;
298
- unsigned len;
357
+ z_size_t len;
358
+ gz_statep state;
359
+
360
+ /* get internal structure */
361
+ if (file == NULL)
362
+ return -1;
363
+ state = (gz_statep)file;
364
+
365
+ /* check that we're writing and that there's no error */
366
+ if (state->mode != GZ_WRITE || state->err != Z_OK)
367
+ return -1;
299
368
 
300
369
  /* write string */
301
- len = (unsigned)strlen(str);
302
- ret = gzwrite(file, str, len);
370
+ len = strlen(str);
371
+ ret = gz_write(state, str, len);
303
372
  return ret == 0 && len != 0 ? -1 : ret;
304
373
  }
305
374
 
@@ -309,63 +378,73 @@ int ZEXPORT gzputs(file, str)
309
378
  /* -- see zlib.h -- */
310
379
  int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va)
311
380
  {
312
- int size, len;
381
+ int len;
382
+ unsigned left;
383
+ char *next;
313
384
  gz_statep state;
314
385
  z_streamp strm;
315
386
 
316
387
  /* get internal structure */
317
388
  if (file == NULL)
318
- return -1;
389
+ return Z_STREAM_ERROR;
319
390
  state = (gz_statep)file;
320
391
  strm = &(state->strm);
321
392
 
322
393
  /* check that we're writing and that there's no error */
323
394
  if (state->mode != GZ_WRITE || state->err != Z_OK)
324
- return 0;
395
+ return Z_STREAM_ERROR;
325
396
 
326
397
  /* make sure we have some buffer space */
327
398
  if (state->size == 0 && gz_init(state) == -1)
328
- return 0;
399
+ return state->err;
329
400
 
330
401
  /* check for seek request */
331
402
  if (state->seek) {
332
403
  state->seek = 0;
333
404
  if (gz_zero(state, state->skip) == -1)
334
- return 0;
405
+ return state->err;
335
406
  }
336
407
 
337
- /* consume whatever's left in the input buffer */
338
- if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
339
- return 0;
340
-
341
- /* do the printf() into the input buffer, put length in len */
342
- size = (int)(state->size);
343
- state->in[size - 1] = 0;
408
+ /* do the printf() into the input buffer, put length in len -- the input
409
+ buffer is double-sized just for this function, so there is guaranteed to
410
+ be state->size bytes available after the current contents */
411
+ if (strm->avail_in == 0)
412
+ strm->next_in = state->in;
413
+ next = (char *)(state->in + (strm->next_in - state->in) + strm->avail_in);
414
+ next[state->size - 1] = 0;
344
415
  #ifdef NO_vsnprintf
345
416
  # ifdef HAS_vsprintf_void
346
- (void)vsprintf((char *)(state->in), format, va);
347
- for (len = 0; len < size; len++)
348
- if (state->in[len] == 0) break;
417
+ (void)vsprintf(next, format, va);
418
+ for (len = 0; len < state->size; len++)
419
+ if (next[len] == 0) break;
349
420
  # else
350
- len = vsprintf((char *)(state->in), format, va);
421
+ len = vsprintf(next, format, va);
351
422
  # endif
352
423
  #else
353
424
  # ifdef HAS_vsnprintf_void
354
- (void)vsnprintf((char *)(state->in), size, format, va);
355
- len = strlen((char *)(state->in));
425
+ (void)vsnprintf(next, state->size, format, va);
426
+ len = strlen(next);
356
427
  # else
357
- len = vsnprintf((char *)(state->in), size, format, va);
428
+ len = vsnprintf(next, state->size, format, va);
358
429
  # endif
359
430
  #endif
360
431
 
361
432
  /* check that printf() results fit in buffer */
362
- if (len <= 0 || len >= (int)size || state->in[size - 1] != 0)
433
+ if (len == 0 || (unsigned)len >= state->size || next[state->size - 1] != 0)
363
434
  return 0;
364
435
 
365
- /* update buffer and position, defer compression until needed */
366
- strm->avail_in = (unsigned)len;
367
- strm->next_in = state->in;
436
+ /* update buffer and position, compress first half if past that */
437
+ strm->avail_in += (unsigned)len;
368
438
  state->x.pos += len;
439
+ if (strm->avail_in >= state->size) {
440
+ left = strm->avail_in - state->size;
441
+ strm->avail_in = state->size;
442
+ if (gz_comp(state, Z_NO_FLUSH) == -1)
443
+ return state->err;
444
+ memcpy(state->in, state->in + state->size, left);
445
+ strm->next_in = state->in;
446
+ strm->avail_in = left;
447
+ }
369
448
  return len;
370
449
  }
371
450
 
@@ -390,73 +469,82 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
390
469
  int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
391
470
  a11, a12, a13, a14, a15, a16, a17, a18, a19, a20;
392
471
  {
393
- int size, len;
472
+ unsigned len, left;
473
+ char *next;
394
474
  gz_statep state;
395
475
  z_streamp strm;
396
476
 
397
477
  /* get internal structure */
398
478
  if (file == NULL)
399
- return -1;
479
+ return Z_STREAM_ERROR;
400
480
  state = (gz_statep)file;
401
481
  strm = &(state->strm);
402
482
 
403
483
  /* check that can really pass pointer in ints */
404
484
  if (sizeof(int) != sizeof(void *))
405
- return 0;
485
+ return Z_STREAM_ERROR;
406
486
 
407
487
  /* check that we're writing and that there's no error */
408
488
  if (state->mode != GZ_WRITE || state->err != Z_OK)
409
- return 0;
489
+ return Z_STREAM_ERROR;
410
490
 
411
491
  /* make sure we have some buffer space */
412
492
  if (state->size == 0 && gz_init(state) == -1)
413
- return 0;
493
+ return state->error;
414
494
 
415
495
  /* check for seek request */
416
496
  if (state->seek) {
417
497
  state->seek = 0;
418
498
  if (gz_zero(state, state->skip) == -1)
419
- return 0;
499
+ return state->error;
420
500
  }
421
501
 
422
- /* consume whatever's left in the input buffer */
423
- if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
424
- return 0;
425
-
426
- /* do the printf() into the input buffer, put length in len */
427
- size = (int)(state->size);
428
- state->in[size - 1] = 0;
502
+ /* do the printf() into the input buffer, put length in len -- the input
503
+ buffer is double-sized just for this function, so there is guaranteed to
504
+ be state->size bytes available after the current contents */
505
+ if (strm->avail_in == 0)
506
+ strm->next_in = state->in;
507
+ next = (char *)(strm->next_in + strm->avail_in);
508
+ next[state->size - 1] = 0;
429
509
  #ifdef NO_snprintf
430
510
  # ifdef HAS_sprintf_void
431
- sprintf((char *)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8,
432
- a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
511
+ sprintf(next, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12,
512
+ a13, a14, a15, a16, a17, a18, a19, a20);
433
513
  for (len = 0; len < size; len++)
434
- if (state->in[len] == 0) break;
514
+ if (next[len] == 0)
515
+ break;
435
516
  # else
436
- len = sprintf((char *)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8,
437
- a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
517
+ len = sprintf(next, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11,
518
+ a12, a13, a14, a15, a16, a17, a18, a19, a20);
438
519
  # endif
439
520
  #else
440
521
  # ifdef HAS_snprintf_void
441
- snprintf((char *)(state->in), size, format, a1, a2, a3, a4, a5, a6, a7, a8,
442
- a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
443
- len = strlen((char *)(state->in));
522
+ snprintf(next, state->size, format, a1, a2, a3, a4, a5, a6, a7, a8, a9,
523
+ a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
524
+ len = strlen(next);
444
525
  # else
445
- len = snprintf((char *)(state->in), size, format, a1, a2, a3, a4, a5, a6,
446
- a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18,
447
- a19, a20);
526
+ len = snprintf(next, state->size, format, a1, a2, a3, a4, a5, a6, a7, a8,
527
+ a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
448
528
  # endif
449
529
  #endif
450
530
 
451
531
  /* check that printf() results fit in buffer */
452
- if (len <= 0 || len >= (int)size || state->in[size - 1] != 0)
532
+ if (len == 0 || len >= state->size || next[state->size - 1] != 0)
453
533
  return 0;
454
534
 
455
- /* update buffer and position, defer compression until needed */
456
- strm->avail_in = (unsigned)len;
457
- strm->next_in = state->in;
535
+ /* update buffer and position, compress first half if past that */
536
+ strm->avail_in += len;
458
537
  state->x.pos += len;
459
- return len;
538
+ if (strm->avail_in >= state->size) {
539
+ left = strm->avail_in - state->size;
540
+ strm->avail_in = state->size;
541
+ if (gz_comp(state, Z_NO_FLUSH) == -1)
542
+ return state->err;
543
+ memcpy(state->in, state->in + state->size, left);
544
+ strm->next_in = state->in;
545
+ strm->avail_in = left;
546
+ }
547
+ return (int)len;
460
548
  }
461
549
 
462
550
  #endif
@@ -470,7 +558,7 @@ int ZEXPORT gzflush(file, flush)
470
558
 
471
559
  /* get internal structure */
472
560
  if (file == NULL)
473
- return -1;
561
+ return Z_STREAM_ERROR;
474
562
  state = (gz_statep)file;
475
563
 
476
564
  /* check that we're writing and that there's no error */
@@ -485,11 +573,11 @@ int ZEXPORT gzflush(file, flush)
485
573
  if (state->seek) {
486
574
  state->seek = 0;
487
575
  if (gz_zero(state, state->skip) == -1)
488
- return -1;
576
+ return state->err;
489
577
  }
490
578
 
491
579
  /* compress remaining data with requested flush */
492
- gz_comp(state, flush);
580
+ (void)gz_comp(state, flush);
493
581
  return state->err;
494
582
  }
495
583
 
@@ -520,13 +608,13 @@ int ZEXPORT gzsetparams(file, level, strategy)
520
608
  if (state->seek) {
521
609
  state->seek = 0;
522
610
  if (gz_zero(state, state->skip) == -1)
523
- return -1;
611
+ return state->err;
524
612
  }
525
613
 
526
614
  /* change compression parameters for subsequent input */
527
615
  if (state->size) {
528
616
  /* flush previous input with previous parameters before changing */
529
- if (strm->avail_in && gz_comp(state, Z_PARTIAL_FLUSH) == -1)
617
+ if (strm->avail_in && gz_comp(state, Z_BLOCK) == -1)
530
618
  return state->err;
531
619
  deflateParams(strm, level, strategy);
532
620
  }