Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bypass signal handling in interpreted code #14019

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/interpreter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
test-interpreter-std_spec:
needs: build-interpreter
runs-on: ubuntu-22.04
timeout-minutes: 15
container:
image: crystallang/crystal:1.11.2-build
strategy:
Expand Down
18 changes: 9 additions & 9 deletions spec/interpreter_std_spec.cr

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 11 additions & 6 deletions spec/std/spec_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,17 @@ def compile_source(source, flags = %w(), file = __FILE__, &)
end

def compile_and_run_file(source_file, flags = %w(), runtime_args = %w(), file = __FILE__)
compile_file(source_file, flags: flags, file: file) do |executable_file|
output, error = IO::Memory.new, IO::Memory.new
status = Process.run executable_file, args: runtime_args, output: output, error: error

{status, output.to_s, error.to_s}
end
status, output, error = Process::Status.new(0), IO::Memory.new, IO::Memory.new
{% if flag?(:interpreted) %}
compiler = ENV["CRYSTAL_SPEC_COMPILER_BIN"]? || "bin/crystal"
args = ["i", source_file, "--", *runtime_args]
status = Process.run compiler, args: args, output: output, error: error
{% else %}
compile_file(source_file, flags: flags, file: file) do |executable_file|
status = Process.run executable_file, args: runtime_args, output: output, error: error
end
{% end %}
{status, output.to_s, error.to_s}
end

def compile_and_run_source(source, flags = %w(), runtime_args = %w(), file = __FILE__)
Expand Down
1 change: 1 addition & 0 deletions spec/std/time/format_spec.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "../spec_helper"
require "../../support/time"
require "spec/helpers/string"

def parse_time(format, string)
Expand Down
1 change: 1 addition & 0 deletions spec/std/time/time_spec.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "../spec_helper"
require "../../support/time"
require "spec/helpers/iterate"

CALENDAR_WEEK_TEST_DATA = [
Expand Down
18 changes: 18 additions & 0 deletions src/crystal/system/unix/process.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@ struct Crystal::System::Process
end

def wait
{% if flag?(:interpreted) %}
exit_code = uninitialized Int32
loop do
r_pid = LibC.waitpid(pid, pointerof(exit_code), LibC::WNOHANG)
case r_pid
when 0
sleep 1
when -1
raise RuntimeError.from_errno("waitpid") unless Errno.value == Errno::ECHILD
sleep 1
else
break
end
end

@channel.send(exit_code)
@channel.close
{% end %}
@channel.receive
end

Expand Down
7 changes: 7 additions & 0 deletions src/crystal/system/unix/signal.cr
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,13 @@ module Crystal::System::SignalChildHandler

def self.wait(pid : LibC::PidT) : Channel(Int32)
channel = Channel(Int32).new(1)
{% if flag?(:interpreted) %}
# Returns channel immediately when interpreted
# Waiting for child process in interpreted code
# does not rely on signal SIGCHLD and it's handled
# in ::Crystal::System::Process.wait
return channel
{% end %}

@@mutex.lock
if exit_code = @@pending.delete(pid)
Expand Down
Loading