binaryen 1.1.6.4 → 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: e0f235a249bcf6c38016c2033776997d2d636126cea0b37d47c98dc2b932dd08
4
- data.tar.gz: 3f123ebb5bdb0f24ebf004097e02ccab417d09838e9ec663a87e43ae472cb9a1
3
+ metadata.gz: 44bf5b373ce186bdee3006d16e8129bde2be3e952c1211d3ee550fb529cffbfe
4
+ data.tar.gz: c3ef7a60460cdc937e51b538ef4e6d94ebfba2167ff14821292881a9b91d6f1f
5
5
  SHA512:
6
- metadata.gz: 8d58caa196cbc38e9178dba6fa0efdcdde270d298ef5c3f34e523f5281630ae18c32bac9bd6da379fb7b758a536b94afc2c3c3faddb68118c5ccb64255c256da
7
- data.tar.gz: 85f826a48ba40d0e3d48e4806cc52faf265c058b53421af32efdc67eb811075f99c7e83488f6aab85b141478cac104c2d1031931374df75c650972107c8acd5a
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,43 +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
- write_to_pipe(stderr, err_output, timeout_checker, close_write: false)
57
+ write_to_pipe(stderr, err_output, timeout_checker, pid, close_write: false)
57
58
  end
58
59
  output = read_from_pipe(ord, timeout_checker)
59
- wait_or_kill(pid, timeout_checker, erd, stderr)
60
+ wait_or_kill(pid, timeout_checker)
60
61
 
61
62
  output
62
63
  end
63
64
 
64
65
  private
65
66
 
66
- def write_to_pipe(pipe, stdin, timeout_checker, close_write: true)
67
+ def write_to_pipe(pipe, stdin, timeout_checker, pid, close_write: true)
67
68
  offset = 0
68
69
  length = stdin.bytesize
69
70
 
70
71
  while offset < length
71
72
  remaining_time = timeout_checker.check!
72
73
 
73
- if IO.select(nil, [pipe], nil, remaining_time)
74
+ next unless IO.select(nil, [pipe], nil, remaining_time)
75
+
76
+ begin
74
77
  written = pipe.write_nonblock(stdin.byteslice(offset, length), exception: false)
75
78
  offset += written if written.is_a?(Integer)
76
- else
77
- raise Timeout::Error, "Command timed out"
79
+ rescue Errno::EPIPE
80
+ wait_or_kill(pid, timeout_checker, pid)
78
81
  end
79
82
  end
80
-
83
+ ensure
81
84
  pipe.close_write if close_write
82
85
  end
83
86
 
84
- def read_from_pipe(pipe, timeout_checker)
87
+ def read_from_pipe(pipe, timeout_checker, close_read: true)
85
88
  output = +""
86
89
 
87
90
  while (result = pipe.read_nonblock(8192, exception: false))
88
91
  remaining_time = timeout_checker.check!
89
- raise Timeout::Error, "Command timed out" if remaining_time <= 0
90
92
 
91
93
  case result
92
94
  when :wait_readable
@@ -99,15 +101,15 @@ module Binaryen
99
101
  end
100
102
 
101
103
  output
104
+ ensure
105
+ pipe.close_read if close_read
102
106
  end
103
107
 
104
- def wait_or_kill(pid, timeout_checker, err_read, err_write)
108
+ def wait_or_kill(pid, timeout_checker)
105
109
  loop do
106
- remaining_time = timeout_checker.check!
107
- raise Timeout::Error, "timed out waiting on process" if remaining_time <= 0
110
+ timeout_checker.check!
108
111
 
109
112
  if (_, status = Process.wait2(pid, Process::WNOHANG))
110
-
111
113
  raise Binaryen::NonZeroExitStatus,
112
114
  "command exited with status #{status.exitstatus}" if status.exitstatus != 0
113
115
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Binaryen
4
- VERSION = "1.1.6.4"
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.4
4
+ version: 1.1.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify Inc.