binaryen 1.1.6.1 → 1.1.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f28c12d0f3983f4a8856a70bd62767df1021eac072a97edea0174b59648519d1
4
- data.tar.gz: 6973598a0a4d375e1445a6d463853b6a37a4343b735c191fa10b7457cdb4273e
3
+ metadata.gz: 502cfbb2e9e33d3b32d5ab1881bf097fc7321bcb8746e2ae4b4142a6dbe3727a
4
+ data.tar.gz: 20c543218c8b5c256012e3b386e4cf6ceda9461899f10d990edcba0b983dbc17
5
5
  SHA512:
6
- metadata.gz: 31693bb150232527b2ebae35f6a44f72d3af7a02ec3d6370df366226eb7e4b718375db2c832f6fe169a843c1c4b4ced9116d0d4e247a4805d473c01f8d9677a9
7
- data.tar.gz: feac4bb36b20f5b5e0d7907fb2cad013e2c90c23bb5cdb7b233ca0e74407ab558de9f765b2bd8adcbe9148976363b1dca9781b6dbf37dead3f0dac867c36eaad
6
+ metadata.gz: 2a9d8542c524badbeb6721a9b6e9fc6cd9531e3a44134bce6206cba23c99c1d069850f85e0e222a0749de571d647e57a6f122dba6992661ef819f884581c7bcf
7
+ data.tar.gz: e62fa41cc97a4d777e10872d4ec9df6690ca5a5c6d773d8e01de897b93e41880e6bd676a5756776bbdf91629977402c6dec8f7e269a2c32909f1b62143773ba5
@@ -18,6 +18,23 @@ module Binaryen
18
18
  "wasm-opt" => ["--output=-"],
19
19
  }.freeze
20
20
 
21
+ class TimeoutChecker
22
+ def initialize(end_time:, pid:)
23
+ @end_time = end_time
24
+ @pid = pid
25
+ end
26
+
27
+ def check!
28
+ now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
29
+ if now >= @end_time
30
+ Process.kill("KILL", @pid)
31
+ raise Timeout::Error, "Command timed out"
32
+ end
33
+ remaining_time = @end_time - now
34
+ remaining_time
35
+ end
36
+ end
37
+
21
38
  def initialize(cmd, timeout: 10, ignore_missing: false)
22
39
  @cmd = command_path(cmd, ignore_missing) || raise(ArgumentError, "command not found: #{cmd}")
23
40
  @timeout = timeout
@@ -25,58 +42,49 @@ module Binaryen
25
42
  end
26
43
 
27
44
  def run(*arguments, stdin: nil, stderr: File::NULL)
45
+ end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) + @timeout
28
46
  command = build_command(*arguments)
29
47
  pipe = IO.popen(command, "rb+", err: stderr)
30
48
  pid = pipe.pid
31
- start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
32
- remaining_timeout = @timeout
33
-
34
- if stdin
35
- start_time, remaining_timeout = write_to_pipe(pipe, stdin, start_time, remaining_timeout)
36
- end
49
+ timeout_checker = TimeoutChecker.new(end_time: end_time, pid: pid)
37
50
 
38
- output, remaining_timeout = read_from_pipe(pipe, start_time, remaining_timeout)
39
-
40
- wait_or_kill(pid, start_time, remaining_timeout)
51
+ write_to_pipe(pipe, stdin, timeout_checker) if stdin
52
+ output = read_from_pipe(pipe, timeout_checker)
53
+ wait_or_kill(pid, timeout_checker)
41
54
 
42
55
  output
43
56
  end
44
57
 
45
58
  private
46
59
 
47
- def write_to_pipe(pipe, stdin, start_time, remaining_timeout)
60
+ def write_to_pipe(pipe, stdin, timeout_checker)
48
61
  offset = 0
49
62
  length = stdin.bytesize
50
63
 
51
64
  while offset < length
52
- start_time, remaining_timeout = update_timeout(start_time, remaining_timeout)
53
- if IO.select(nil, [pipe], nil, remaining_timeout)
65
+ remaining_time = timeout_checker.check!
66
+
67
+ if IO.select(nil, [pipe], nil, remaining_time)
54
68
  written = pipe.write_nonblock(stdin.byteslice(offset, length), exception: false)
55
- case written
56
- when Integer
57
- offset += written
58
- when :wait_writable
59
- puts "wait"
60
- # If the pipe is not ready for writing, retry
61
- end
69
+ offset += written if written.is_a?(Integer)
62
70
  else
63
71
  raise Timeout::Error, "Command timed out"
64
72
  end
65
73
  end
66
74
 
67
75
  pipe.close_write
68
- [start_time, remaining_timeout]
69
76
  end
70
77
 
71
- def read_from_pipe(pipe, start_time, remaining_timeout)
78
+ def read_from_pipe(pipe, timeout_checker)
72
79
  output = +""
73
80
 
74
81
  while (result = pipe.read_nonblock(8192, exception: false))
75
- start_time, remaining_timeout = update_timeout(start_time, remaining_timeout)
82
+ remaining_time = timeout_checker.check!
83
+ raise Timeout::Error, "Command timed out" if remaining_time <= 0
76
84
 
77
85
  case result
78
86
  when :wait_readable
79
- IO.select([pipe], nil, nil, remaining_timeout)
87
+ IO.select([pipe], nil, nil, remaining_time)
80
88
  when nil
81
89
  break
82
90
  else
@@ -84,37 +92,22 @@ module Binaryen
84
92
  end
85
93
  end
86
94
 
87
- [output, remaining_timeout]
88
- end
89
-
90
- def update_timeout(start_time, remaining_timeout)
91
- elapsed_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time
92
- remaining_timeout -= elapsed_time
93
-
94
- raise Timeout::Error, "command timed out" if remaining_timeout <= 0
95
-
96
- start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
97
-
98
- [start_time, remaining_timeout]
95
+ output
99
96
  end
100
97
 
101
- def wait_or_kill(pid, start_time, remaining_timeout)
102
- while remaining_timeout > 0
103
- start_time, remaining_timeout = update_timeout(start_time, remaining_timeout)
98
+ def wait_or_kill(pid, timeout_checker)
99
+ loop do
100
+ remaining_time = timeout_checker.check!
101
+ raise Timeout::Error, "timed out waiting on process" if remaining_time <= 0
104
102
 
105
103
  if (_, status = Process.wait2(pid, Process::WNOHANG))
106
- if status.exitstatus != 0
107
- raise Binaryen::NonZeroExitStatus, "command exited with status #{status.exitstatus}"
108
- end
104
+ raise Binaryen::NonZeroExitStatus, "command exited with status #{status.exitstatus}" if status.exitstatus != 0
109
105
 
110
106
  return true
111
107
  else
112
108
  sleep(0.1)
113
109
  end
114
110
  end
115
-
116
- Process.kill("KILL", pid)
117
- raise Timeout::Error, "timed out waiting on process"
118
111
  end
119
112
 
120
113
  def build_command(*arguments)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Binaryen
4
- VERSION = "1.1.6.1"
4
+ VERSION = "1.1.6.2"
5
5
  BINARYEN_VERSION = "version_116"
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: binaryen
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6.1
4
+ version: 1.1.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-02 00:00:00.000000000 Z
11
+ date: 2023-12-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
94
  requirements: []
95
- rubygems_version: 3.4.21
95
+ rubygems_version: 3.4.22
96
96
  signing_key:
97
97
  specification_version: 4
98
98
  summary: Vendors binaryen libraries, headers, and executables for use in Ruby