From 8e600b78ca965117a053751f38ccaffa3e16780a Mon Sep 17 00:00:00 2001 From: Vindaar Date: Thu, 10 Jan 2019 13:44:44 +0100 Subject: [PATCH] add unsetControlCHook to remove a Ctrl-C hook after it was set (#7267) * add unsetControlCHook to remove a Ctrl-C hook after it was set Adds the inverse proc to setControlCHook in order to lift a Ctrl-C hook after it has been set. * remove check for noSignalHandler in system/excpt.nim --- lib/system.nim | 4 ++++ lib/system/embedded.nim | 1 + lib/system/excpt.nim | 5 +++++ 3 files changed, 10 insertions(+) diff --git a/lib/system.nim b/lib/system.nim index b8ff85f494..fb52ee9eb2 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -3458,6 +3458,10 @@ when not defined(JS): #and not defined(nimscript): ## allows you to override the behaviour of your application when CTRL+C ## is pressed. Only one such hook is supported. + when not defined(useNimRtl): + proc unsetControlCHook*() + ## reverts a call to setControlCHook + proc writeStackTrace*() {.tags: [], gcsafe.} ## writes the current stack trace to ``stderr``. This is only works ## for debug builds. Since it's usually used for debugging, this diff --git a/lib/system/embedded.nim b/lib/system/embedded.nim index 4d453fcca4..fb89e7f0f3 100644 --- a/lib/system/embedded.nim +++ b/lib/system/embedded.nim @@ -40,6 +40,7 @@ proc reraiseException() {.compilerRtl.} = proc writeStackTrace() = discard +proc unsetControlCHook() = discard proc setControlCHook(hook: proc () {.noconv.}) = discard proc closureIterSetupExc(e: ref Exception) {.compilerproc, inline.} = diff --git a/lib/system/excpt.nim b/lib/system/excpt.nim index 84a1da3438..3efefead4a 100644 --- a/lib/system/excpt.nim +++ b/lib/system/excpt.nim @@ -536,3 +536,8 @@ proc setControlCHook(hook: proc () {.noconv.}) = # ugly cast, but should work on all architectures: type SignalHandler = proc (sign: cint) {.noconv, benign.} c_signal(SIGINT, cast[SignalHandler](hook)) + +when not defined(useNimRtl): + proc unsetControlCHook() = + # proc to unset a hook set by setControlCHook + c_signal(SIGINT, signalHandler)