Skip to content
Merged
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
8 changes: 8 additions & 0 deletions doc/manual/rl-next/repl-interrupt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
synopsis: Interrupting REPL commands works more than once
issues: [13481]
---

Previously, this only worked once per REPL session; further attempts would be ignored.
This issue is now fixed, so REPL commands such as `:b` or `:p` can be canceled consistently.
This is a cherry-pick of the change from the [Lix project](https://gerrit.lix.systems/c/lix/+/1097).
11 changes: 1 addition & 10 deletions src/libmain/shared.cc
Original file line number Diff line number Diff line change
Expand Up @@ -321,16 +321,7 @@ int handleExceptions(const std::string & programName, std::function<void()> fun)

std::string error = ANSI_RED "error:" ANSI_NORMAL " ";
try {
try {
fun();
} catch (...) {
/* Subtle: we have to make sure that any `interrupted'
condition is discharged before we reach printMsg()
below, since otherwise it will throw an (uncaught)
exception. */
setInterruptThrown();
throw;
}
fun();
} catch (Exit & e) {
return e.status;
} catch (UsageError & e) {
Expand Down
5 changes: 0 additions & 5 deletions src/libutil/include/nix/util/signals.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ static inline void setInterrupted(bool isInterrupted);
*/
static inline bool getInterrupted();

/**
* @note Does nothing on Windows
*/
void setInterruptThrown();

/**
* @note Does nothing on Windows
*/
Expand Down
12 changes: 1 addition & 11 deletions src/libutil/unix/signals.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,14 @@ using namespace unix;

std::atomic<bool> unix::_isInterrupted = false;

namespace unix {
static thread_local bool interruptThrown = false;
}

thread_local std::function<bool()> unix::interruptCheck;

void setInterruptThrown()
{
unix::interruptThrown = true;
}

void unix::_interrupted()
{
/* Block user interrupts while an exception is being handled.
Throwing an exception while another exception is being handled
kills the program! */
if (!interruptThrown && !std::uncaught_exceptions()) {
interruptThrown = true;
if (!std::uncaught_exceptions()) {
throw Interrupted("interrupted by the user");
}
}
Expand Down
5 changes: 0 additions & 5 deletions src/libutil/windows/include/nix/util/signals-impl.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ static inline bool getInterrupted()
return false;
}

inline void setInterruptThrown()
{
/* Do nothing for now */
}

static inline bool isInterrupted()
{
/* Do nothing for now */
Expand Down
Loading