diff src/regexp.c @ 29888:a63d3a0e9aba v9.0.0282

patch 9.0.0282: a nested timout stops the previous timeout Commit: https://github.com/vim/vim/commit/0f618386367ba9388e1f50bc665bc1add6c01567 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Aug 26 21:33:04 2022 +0100 patch 9.0.0282: a nested timout stops the previous timeout Problem: A nested timout stops the previous timeout. Solution: Ignore any nested timeout.
author Bram Moolenaar <Bram@vim.org>
date Fri, 26 Aug 2022 22:45:06 +0200
parents e7158d889784
children d3cfd12839ef
line wrap: on
line diff
--- a/src/regexp.c
+++ b/src/regexp.c
@@ -51,17 +51,32 @@ toggle_Magic(int x)
 }
 
 #ifdef FEAT_RELTIME
+static int timeout_nesting = 0;
+
+/*
+ * Start a timer that will cause the regexp to abort after "msec".
+ * This doesn't work well recursively.  In case it happens anyway, the first
+ * set timeout will prevail, nested ones are ignored.
+ * The caller must make sure there is a matching disable_regexp_timeout() call!
+ */
     void
 init_regexp_timeout(long msec)
 {
-    timeout_flag = start_timeout(msec);
+    if (timeout_nesting == 0)
+	timeout_flag = start_timeout(msec);
+    ++timeout_nesting;
 }
 
     void
 disable_regexp_timeout(void)
 {
-    stop_timeout();
-    timeout_flag = &dummy_timeout_flag;
+    if (timeout_nesting == 0)
+	iemsg("disable_regexp_timeout() called without active timer");
+    else if (--timeout_nesting == 0)
+    {
+	stop_timeout();
+	timeout_flag = &dummy_timeout_flag;
+    }
 }
 #endif