binaryen 1.1.6.5 → 1.1.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7ec6cd19949163f81747301353e37912f7d2924205816df9f6620f0cb6a266ce
4
- data.tar.gz: cfc6e449979a806440f5c893640618bd321597e1ae8848108fea8c7b9da88d72
3
+ metadata.gz: 44bf5b373ce186bdee3006d16e8129bde2be3e952c1211d3ee550fb529cffbfe
4
+ data.tar.gz: c3ef7a60460cdc937e51b538ef4e6d94ebfba2167ff14821292881a9b91d6f1f
5
5
  SHA512:
6
- metadata.gz: 9e83c357446ac3c2e04d6de7a575d8dca7b4164cd4050416edd87d23fe864165085f25b5e3f7a7f28d46debedcc7fa146f1416aa8a529376c5ea07dfd8f1713b
7
- data.tar.gz: 8f3e7d8a8582608436191bdea891aa8564cebc0ccceceb750bdbce38b563bd590c32e8b5025a9a63761eb6592347709e06983c023b950d377b016354da111b35
6
+ metadata.gz: 290897e4df9079e57df51b4b684fa5ae496ea414c44d801ed8d2be5c167d5347812533511ee26b8f59520d645df1072df5c6368d218ab824d89b38e07373e7b5
7
+ data.tar.gz: c30ed5adcb899a8d938d211b3aa3e98e875ec061f19054efd5d7a803b9be0392f9215cbac61283147841e23171ead48391f06695aa06841a64a6be05d5ba57aa
@@ -30,7 +30,7 @@ module Binaryen
30
30
  def check!
31
31
  now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
32
32
  if now >= @end_time
33
- Process.kill("KILL", @pid)
33
+ Process.kill("TERM", @pid)
34
34
  raise Timeout::Error, "Command timed out"
35
35
  end
36
36
  remaining_time = @end_time - now
@@ -50,47 +50,45 @@ module Binaryen
50
50
  pid, iwr, ord, erd = popen4(*command)
51
51
  timeout_checker = TimeoutChecker.new(end_time: end_time, pid: pid)
52
52
 
53
- write_to_pipe(iwr, stdin, timeout_checker) if stdin
53
+ write_to_pipe(iwr, stdin, timeout_checker, pid) if stdin
54
+
54
55
  if stderr
55
56
  err_output = read_from_pipe(erd, timeout_checker)
56
- begin
57
- write_to_pipe(stderr, err_output, timeout_checker, close_write: false)
58
- rescue Errno::EPIPE
59
- # ignore
60
- end
57
+ write_to_pipe(stderr, err_output, timeout_checker, pid, close_write: false)
61
58
  end
62
59
  output = read_from_pipe(ord, timeout_checker)
63
- wait_or_kill(pid, timeout_checker, erd, stderr)
60
+ wait_or_kill(pid, timeout_checker)
64
61
 
65
62
  output
66
63
  end
67
64
 
68
65
  private
69
66
 
70
- def write_to_pipe(pipe, stdin, timeout_checker, close_write: true)
67
+ def write_to_pipe(pipe, stdin, timeout_checker, pid, close_write: true)
71
68
  offset = 0
72
69
  length = stdin.bytesize
73
70
 
74
71
  while offset < length
75
72
  remaining_time = timeout_checker.check!
76
73
 
77
- if IO.select(nil, [pipe], nil, remaining_time)
74
+ next unless IO.select(nil, [pipe], nil, remaining_time)
75
+
76
+ begin
78
77
  written = pipe.write_nonblock(stdin.byteslice(offset, length), exception: false)
79
78
  offset += written if written.is_a?(Integer)
80
- else
81
- raise Timeout::Error, "Command timed out"
79
+ rescue Errno::EPIPE
80
+ wait_or_kill(pid, timeout_checker, pid)
82
81
  end
83
82
  end
84
-
83
+ ensure
85
84
  pipe.close_write if close_write
86
85
  end
87
86
 
88
- def read_from_pipe(pipe, timeout_checker)
87
+ def read_from_pipe(pipe, timeout_checker, close_read: true)
89
88
  output = +""
90
89
 
91
90
  while (result = pipe.read_nonblock(8192, exception: false))
92
91
  remaining_time = timeout_checker.check!
93
- raise Timeout::Error, "Command timed out" if remaining_time <= 0
94
92
 
95
93
  case result
96
94
  when :wait_readable
@@ -103,15 +101,15 @@ module Binaryen
103
101
  end
104
102
 
105
103
  output
104
+ ensure
105
+ pipe.close_read if close_read
106
106
  end
107
107
 
108
- def wait_or_kill(pid, timeout_checker, err_read, err_write)
108
+ def wait_or_kill(pid, timeout_checker)
109
109
  loop do
110
- remaining_time = timeout_checker.check!
111
- raise Timeout::Error, "timed out waiting on process" if remaining_time <= 0
110
+ timeout_checker.check!
112
111
 
113
112
  if (_, status = Process.wait2(pid, Process::WNOHANG))
114
-
115
113
  raise Binaryen::NonZeroExitStatus,
116
114
  "command exited with status #{status.exitstatus}" if status.exitstatus != 0
117
115
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Binaryen
4
- VERSION = "1.1.6.5"
4
+ VERSION = "1.1.6.6"
5
5
  BINARYEN_VERSION = "version_116"
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: binaryen
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6.5
4
+ version: 1.1.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify Inc.