Skip to content

Commit

Permalink
Add version constraints for signal handler primitives in interpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota committed Nov 11, 2024
1 parent caf57c2 commit ad01192
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
14 changes: 8 additions & 6 deletions src/crystal/interpreter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ module Crystal
def self.fiber_resumable(context) : LibC::Long
end

@[Primitive(:interpreter_signal_descriptor)]
def self.signal_descriptor(fd : Int32) : Nil
end
{% if compare_versions(Crystal::VERSION, "1.15.0-dev") >= 0 %}
@[Primitive(:interpreter_signal_descriptor)]
def self.signal_descriptor(fd : Int32) : Nil
end

@[Primitive(:interpreter_signal)]
def self.signal(signum : Int32, handler : Int32) : Nil
end
@[Primitive(:interpreter_signal)]
def self.signal(signum : Int32, handler : Int32) : Nil
end
{% end %}
end
end
8 changes: 4 additions & 4 deletions src/crystal/system/unix/signal.cr
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module Crystal::System::Signal
@@mutex.synchronize do
unless @@handlers[signal]?
@@sigset << signal
{% if flag?(:interpreted) %}
{% if flag?(:interpreted) && Crystal::Interpreter.has_method?(:signal) %}
Crystal::Interpreter.signal(signal.value, 2)
{% else %}
action = LibC::Sigaction.new
Expand Down Expand Up @@ -66,7 +66,7 @@ module Crystal::System::Signal
else
@@mutex.synchronize do
@@handlers.delete(signal)
{% if flag?(:interpreted) %}
{% if flag?(:interpreted) && Crystal::Interpreter.has_method?(:signal) %}
h = case handler
when LibC::SIG_DFL then 0
when LibC::SIG_IGN then 1
Expand Down Expand Up @@ -131,7 +131,7 @@ module Crystal::System::Signal
::Signal.each do |signal|
next unless @@sigset.includes?(signal)

{% if flag?(:interpreted) %}
{% if flag?(:interpreted) && Crystal::Interpreter.has_method?(:signal) %}
Crystal::Interpreter.signal(signal.value, 0)
{% else %}
LibC.signal(signal, LibC::SIG_DFL)
Expand Down Expand Up @@ -203,7 +203,7 @@ module Crystal::System::Signal
@@sigset.clear
start_loop

{% if flag?(:interpreted) %}
{% if flag?(:interpreted) && Interpreter.has_method?(:signal_descriptor) %}
# replace the interpreter's writer pipe with the interpreted, so signals
# will be received by the interpreter, but handled by the interpreted
# signal loop
Expand Down
2 changes: 1 addition & 1 deletion src/kernel.cr
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,6 @@ end
end
{% end %}

{% if flag?(:interpreted) && flag?(:unix) %}
{% if flag?(:interpreted) && flag?(:unix) && Crystal::Interpreter.has_method?(:signal_descriptor) %}
Crystal::System::Signal.setup_default_handlers
{% end %}

0 comments on commit ad01192

Please sign in to comment.