Merge changes I8456c47b,I48253f5f into main

* changes:
  repl: clear the interrupt before reading the next line
  libutil: remove the interrupt-blocking code
This commit is contained in:
alois31 2024-05-15 15:46:11 +00:00 committed by Gerrit Code Review
commit 0903a99bad
5 changed files with 12 additions and 22 deletions

View file

@ -0,0 +1,8 @@
---
synopsis: Interrupting builds in the REPL works more than once
cls: 1097
---
Builds in the REPL can be interrupted by pressing Ctrl+C.
Previously, this only worked once per REPL session; further attempts would be ignored.
This issue is now fixed, so that builds can be canceled consistently.

View file

@ -262,6 +262,8 @@ ReplExitStatus NixRepl::mainLoop()
std::string input;
while (true) {
_isInterrupted = false;
// When continuing input from previous lines, don't print a prompt, just align to the same
// number of chars as the prompt.
if (!interacter->getLine(input, input.empty() ? ReplPromptType::ReplPrompt : ReplPromptType::ContinuationPrompt)) {
@ -424,8 +426,6 @@ ProcessLineResult NixRepl::processLine(std::string line)
if (line.empty())
return ProcessLineResult::PromptAgain;
_isInterrupted = false;
std::string command, arg;
if (line[0] == ':') {

View file

@ -320,16 +320,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) {

View file

@ -9,21 +9,14 @@ namespace nix {
std::atomic<bool> _isInterrupted = false;
static thread_local bool interruptThrown = false;
thread_local std::function<bool()> interruptCheck;
void setInterruptThrown()
{
interruptThrown = true;
}
void _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");
}
}

View file

@ -22,8 +22,6 @@ extern std::atomic<bool> _isInterrupted;
extern thread_local std::function<bool()> interruptCheck;
void setInterruptThrown();
void _interrupted();
void inline checkInterrupt()