From 52e4b0747885bf09b9968310fcbb768e8a0ab30e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Fri, 15 Mar 2024 16:04:45 +0100
Subject: [PATCH] Bytecode: use OCTAVE_QUIT macro under Octave for obeying
 Control-C interrupts

---
 mex/sources/bytecode/ErrorHandling.hh | 4 +++-
 mex/sources/bytecode/Evaluate.cc      | 4 ++++
 mex/sources/bytecode/Interpreter.cc   | 2 ++
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/mex/sources/bytecode/ErrorHandling.hh b/mex/sources/bytecode/ErrorHandling.hh
index 066c4f79c2..1443c227fd 100644
--- a/mex/sources/bytecode/ErrorHandling.hh
+++ b/mex/sources/bytecode/ErrorHandling.hh
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2007-2023 Dynare Team
+ * Copyright © 2007-2024 Dynare Team
  *
  * This file is part of Dynare.
  *
@@ -109,6 +109,8 @@ test_mxMalloc(void* z, int line, const string& file, const string& func, int amo
 
 #ifdef MATLAB_MEX_FILE
 extern "C" bool utIsInterruptPending();
+#else
+# include <octave/quit.h>
 #endif
 
 #endif
diff --git a/mex/sources/bytecode/Evaluate.cc b/mex/sources/bytecode/Evaluate.cc
index cf5591a0c2..8b631f1f4e 100644
--- a/mex/sources/bytecode/Evaluate.cc
+++ b/mex/sources/bytecode/Evaluate.cc
@@ -417,6 +417,8 @@ Evaluate::print_expression(const Evaluate::it_code_type& expr_begin,
 #ifdef MATLAB_MEX_FILE
       if (utIsInterruptPending())
         throw UserException {};
+#else
+      OCTAVE_QUIT;
 #endif
       switch ((*it_code)->tag)
         {
@@ -1004,6 +1006,8 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double* __restrict__ y, int y_size,
 #ifdef MATLAB_MEX_FILE
   if (utIsInterruptPending())
     throw UserException {};
+#else
+  OCTAVE_QUIT;
 #endif
 
   while (go_on)
diff --git a/mex/sources/bytecode/Interpreter.cc b/mex/sources/bytecode/Interpreter.cc
index 3422932800..aa7f77bdeb 100644
--- a/mex/sources/bytecode/Interpreter.cc
+++ b/mex/sources/bytecode/Interpreter.cc
@@ -3642,6 +3642,8 @@ Interpreter::Solve_ByteCode_Symbolic_Sparse_GaussianElimination(bool symbolic)
 #ifdef MATLAB_MEX_FILE
       if (utIsInterruptPending())
         throw UserException {};
+#else
+      OCTAVE_QUIT;
 #endif
 
       if (record && symbolic)
-- 
GitLab