From ad011925aa1046e34b3fafd3680c2f1e28c1462c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Mon, 11 Nov 2024 13:31:54 +0100 Subject: [PATCH] Add version constraints for signal handler primitives in interpreter --- src/crystal/interpreter.cr | 14 ++++++++------ src/crystal/system/unix/signal.cr | 8 ++++---- src/kernel.cr | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/crystal/interpreter.cr b/src/crystal/interpreter.cr index 45a2bce699d1..bad67420f5f3 100644 --- a/src/crystal/interpreter.cr +++ b/src/crystal/interpreter.cr @@ -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 diff --git a/src/crystal/system/unix/signal.cr b/src/crystal/system/unix/signal.cr index 99fc30839a6d..ab094d2f3094 100644 --- a/src/crystal/system/unix/signal.cr +++ b/src/crystal/system/unix/signal.cr @@ -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 @@ -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 @@ -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) @@ -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 diff --git a/src/kernel.cr b/src/kernel.cr index f32f98e67c54..1203d1c66a7e 100644 --- a/src/kernel.cr +++ b/src/kernel.cr @@ -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 %}