emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] emacs-26 b3e2073 4/4: Fix subproc listening when setting f


From: Noam Postavsky
Subject: [Emacs-diffs] emacs-26 b3e2073 4/4: Fix subproc listening when setting filter to non-t (Bug#36591)
Date: Thu, 25 Jul 2019 18:36:24 -0400 (EDT)

branch: emacs-26
commit b3e20737d83acbbbec372645e2a951293d84bd29
Author: Noam Postavsky <address@hidden>
Commit: Noam Postavsky <address@hidden>

    Fix subproc listening when setting filter to non-t (Bug#36591)
    
    * src/process.c (Fset_process_filter): Call add_process_read_fd
    according to the state of process filter before it's updated.  This
    restores the correct functioning as it was before 2016-02-16 "Allow
    setting the filter masks later".  Inline the set_process_filter_masks
    call instead of fixing it that function, because it is also called
    from connect_network_socket, and we don't want to change the behavior
    of that function so close to release.
    * test/src/process-tests.el (set-process-filter-t): New test.
---
 src/process.c             | 15 ++++++++++++---
 test/src/process-tests.el | 29 +++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/src/process.c b/src/process.c
index 2df51cf..b602507 100644
--- a/src/process.c
+++ b/src/process.c
@@ -1268,10 +1268,19 @@ The string argument is normally a multibyte string, 
except:
   if (NILP (filter))
     filter = Qinternal_default_process_filter;
 
-  pset_filter (p, filter);
-
   if (p->infd >= 0)
-    set_process_filter_masks (p);
+    {
+      /* If filter WILL be t, stop reading output.  */
+      if (EQ (filter, Qt) && !EQ (p->status, Qlisten))
+        delete_read_fd (p->infd);
+      else if (/* If filter WAS t, then resume reading output.  */
+               EQ (p->filter, Qt)
+               /* Network or serial process not stopped:  */
+               && !EQ (p->command, Qt))
+        add_process_read_fd (p->infd);
+    }
+
+  pset_filter (p, filter);
 
   if (NETCONN1_P (p) || SERIALCONN1_P (p) || PIPECONN1_P (p))
     pset_childp (p, Fplist_put (p->childp, QCfilter, filter));
diff --git a/test/src/process-tests.el b/test/src/process-tests.el
index 7cccc5a..7a6762a 100644
--- a/test/src/process-tests.el
+++ b/test/src/process-tests.el
@@ -144,6 +144,35 @@
     (should (equal "hello stderr!\n"
                   (mapconcat #'identity (nreverse stderr-output) "")))))
 
+(ert-deftest set-process-filter-t ()
+  "Test setting process filter to t and back." ;; Bug#36591
+  (with-temp-buffer
+    (let* ((print-level nil)
+           (print-length nil)
+           (proc (start-process
+                  "test proc" (current-buffer)
+                  (concat invocation-directory invocation-name)
+                  "-Q" "--batch" "--eval"
+                  (prin1-to-string
+                   '(let (s)
+                      (while (setq s (read-from-minibuffer "$ "))
+                        (princ s)
+                        (princ "\n")))))))
+      (set-process-query-on-exit-flag proc nil)
+      (send-string proc "one\n")
+      (should
+       (accept-process-output proc 1))  ; Read "one".
+      (should (equal (buffer-string) "$ one\n$ "))
+      (set-process-filter proc t)       ; Stop reading from proc.
+      (send-string proc "two\n")
+      (should-not
+       (accept-process-output proc 1))  ; Can't read "two" yet.
+      (should (equal (buffer-string) "$ one\n$ "))
+      (set-process-filter proc nil)     ; Resume reading from proc.
+      (should
+       (accept-process-output proc 1))  ; Read "two" from proc.
+      (should (equal (buffer-string) "$ one\n$ two\n$ ")))))
+
 (ert-deftest start-process-should-not-modify-arguments ()
   "`start-process' must not modify its arguments in-place."
   ;; See bug#21831.



reply via email to

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