emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 630e01a 2/2: Make message_to_stderr do one single f


From: Lars Ingebrigtsen
Subject: [Emacs-diffs] master 630e01a 2/2: Make message_to_stderr do one single fwrite
Date: Mon, 24 Jun 2019 18:49:03 -0400 (EDT)

branch: master
commit 630e01a70312d8e6ad47aeba370228fc05c789a9
Author: Lars Ingebrigtsen <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>

    Make message_to_stderr do one single fwrite
    
    * src/xdisp.c (message_to_stderr): When running as a batch
    process, the output from `message' goes to stderr, and has a
    newline appended.  Rewrite the code so that only one fwrite is
    performed to enable messages that are shorter than PIPE_BUF
    (usually 4096 on modern operating systems) are written out as one
    chunk, as this will ensure that the messages are not interleaved
    with messages from other processes that are writing at the same
    time.  This does not affect other stderr outputs, just the ones
    from `message'.
---
 src/xdisp.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/xdisp.c b/src/xdisp.c
index 5d70440..25e8932 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -10705,10 +10705,22 @@ message_to_stderr (Lisp_Object m)
       else
        s = m;
 
-      fwrite (SDATA (s), SBYTES (s), 1, stderr);
+      /* We want to write this out with a single fwrite call so that
+        output doesn't interleave with other processes writing to
+        stderr at the same time. */
+      {
+       int length = min (INT_MAX, SBYTES (s) + 1);
+       char *string = xmalloc (length);
+
+       memcpy (string, SSDATA (s), length - 1);
+       string[length - 1] = '\n';
+       fwrite (string, 1, length, stderr);
+       xfree (string);
+      }
     }
-  if (!cursor_in_echo_area)
+  else if (!cursor_in_echo_area)
     fputc ('\n', stderr);
+
   fflush (stderr);
 }
 



reply via email to

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