bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#15045: Point jumps inappropriately around time of Semantic lexing


From: Barry OReilly
Subject: bug#15045: Point jumps inappropriately around time of Semantic lexing
Date: Thu, 17 Oct 2013 16:01:50 -0400

> I think there's a race-condition, here:
> - let's say we're at time < timeout.
> - we run sit-for, which does not run the timer since we're still <timeout.
> - time advances to > timeout.
> - we check (should (time-less-p (current-time) timeout))
> - we complain unjustly.

This statement isn't right:

> - we run sit-for, which does not run the timer since we're still <timeout.

If sit-for doesn't run the timer at any time in T+1s to T+10s, then
it's supposed to fail.

However, reconsidering the test, I don't think the timing is
necessary, so I've simplified it.

diff --git a/ChangeLog b/ChangeLog
index a755b5c..553abe2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2013-10-17  Barry O'Reilly  <address@hidden>
+
+    Don't run timers in input-pending-p.  Its new check-timers param
+    provides the prior behavior. (Bug#15045).
+    * src/keyboard.c (Finput_pending_p): Accept optional check-timers
+    param.
+    * lisp/subr.el (sit-for): Call (input-pending-p t) so as to behave
+    as before.
+    * test/automated/timer-tests.el: New file.  Tests that (sit-for 0)
+    allows another timer to run.
+
 2013-10-13  Glenn Morris  <address@hidden>
 
     * configure.ac [alpha]: Explicit error in non-ELF case.  (Bug#15601)
diff --git a/etc/NEWS b/etc/NEWS
index ddb9a9f..963c372 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -611,6 +611,9 @@ low-level libraries gfilenotify.c, inotify.c or w32notify.c.
 
 * Incompatible Lisp Changes in Emacs 24.4
 
+** `(input-pending-p)' no longer runs other timers which are ready to
+run.  The new optional CHECK-TIMERS param allows for the prior behavior.
+
 ** `defvar' and `defcustom' in a let-binding affect the "external" default.
 
 ** The syntax of ?» and ?« is now punctuation instead of matched parens.
diff --git a/lisp/subr.el b/lisp/subr.el
index 0d03e9a..952b9b6 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -2222,7 +2222,7 @@ floating point support."
    (noninteractive
     (sleep-for seconds)
     t)
-   ((input-pending-p)
+   ((input-pending-p t)
     nil)
    ((<= seconds 0)
     (or nodisp (redisplay)))
diff --git a/src/keyboard.c b/src/keyboard.c
index bb8fefa..85a1ce7 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -9947,12 +9947,13 @@ requeued_events_pending_p (void)
   return (!NILP (Vunread_command_events));
 }
 
-
-DEFUN ("input-pending-p", Finput_pending_p, Sinput_pending_p, 0, 0, 0,
+DEFUN ("input-pending-p", Finput_pending_p, Sinput_pending_p, 0, 1, 0,
        doc: /* Return t if command input is currently available with no wait.
 Actually, the value is nil only if we can be sure that no input is available;
-if there is a doubt, the value is t.  */)
-  (void)
+if there is a doubt, the value is t.
+
+If CHECK-TIMERS is non-nil, timers that are ready to run will do so.  */)
+  (Lisp_Object check_timers)
 {
   if (!NILP (Vunread_command_events)
       || !NILP (Vunread_post_input_method_events)
@@ -9962,8 +9963,9 @@ if there is a doubt, the value is t.  */)
   /* Process non-user-visible events (Bug#10195).  */
   process_special_events ();
 
-  return (get_input_pending (READABLE_EVENTS_DO_TIMERS_NOW
-                 | READABLE_EVENTS_FILTER_EVENTS)
+  return (get_input_pending ((NILP (check_timers)
+                              ? 0 : READABLE_EVENTS_DO_TIMERS_NOW)
+                             | READABLE_EVENTS_FILTER_EVENTS)
       ? Qt : Qnil);
 }
 
diff --git a/test/automated/timer-tests.el b/test/automated/timer-tests.el
new file mode 100644
index 0000000..71a9b96
--- /dev/null
+++ b/test/automated/timer-tests.el
@@ -0,0 +1,38 @@
+;;; timer-tests.el --- tests for timers -*- lexical-binding:t -*-
+
+;; Copyright (C) 2013 Free Software Foundation, Inc.
+
+;; This file is part of GNU Emacs.
+
+;; This program is free software: you can redistribute it and/or
+;; modify it under the terms of the GNU General Public License as
+;; published by the Free Software Foundation, either version 3 of the
+;; License, or (at your option) any later version.
+;;
+;; This program is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;; General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see `http://www.gnu.org/licenses/'.
+
+;;; Commentary:
+
+;;; Code:
+
+(ert-deftest timer-tests-sit-for ()
+  (let ((timer-ran nil)
+        ;; Want sit-for behavior when interactive
+        (noninteractive nil))
+    (run-at-time '(0 0 0 0)
+                 nil
+                 (lambda () (setq timer-ran t)))
+    ;; The test assumes run-at-time didn't take the liberty of firing
+    ;; the timer, so assert the test's assumption
+    (should (not timer-ran))
+    (sit-for 0 t)
+    (should timer-ran)))
+
+;;; timer-tests.el ends here
+


reply via email to

[Prev in Thread] Current Thread [Next in Thread]