From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.devel Subject: `message' not outputting the newline "atomically" Date: Sat, 13 Jul 2019 17:42:45 -0700 Organization: UCLA Computer Science Department Message-ID: References: <07619925-e367-fb88-2dd8-27addb2e9052@grinta.net> <68b398b1-3790-b32f-535d-6ea2518f79b8@cs.ucla.edu> <83pnn1lkej.fsf@gnu.org> <83tvccjrpo.fsf@gnu.org> <83zhm3i285.fsf@gnu.org> <7a39d680-6234-1301-74e5-62d599f500f6@cs.ucla.edu> <838stfd0pp.fsf@gnu.org> <835zojd0fx.fsf@gnu.org> <834l43czz8.fsf@gnu.org> <5c979663-9ded-4273-11d1-483345053a6f@cs.ucla.edu> <831rz7cvoh.fsf@gnu.org> <540324b5-fad3-ded0-5018-6abb494ce126@cs.ucla.edu> <83blyaaq5l.fsf@gnu.org> <73e8afc0-2151-9c8b-26c5-454fcd2f361d@cs.ucla.edu> <83tvbx7v9l.fsf@gnu.org> <83y31740yg.fsf@gnu.org> <41d16c85-f541-a437-e9ce-12cb94c0d2cc@cs.ucla.edu> <83pnmj3vp9.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------FAE59654CFCF4ABBA81569AE" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="130754"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 Cc: larsi@gnus.org, daniele@grinta.net, Emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Jul 14 02:43:03 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hmSbX-000Xs0-10 for ged-emacs-devel@m.gmane.org; Sun, 14 Jul 2019 02:43:03 +0200 Original-Received: from localhost ([::1]:58534 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hmSbW-0002Bn-3F for ged-emacs-devel@m.gmane.org; Sat, 13 Jul 2019 20:43:02 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41467) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hmSbN-0002Bf-Sz for Emacs-devel@gnu.org; Sat, 13 Jul 2019 20:42:55 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hmSbM-000832-BR for Emacs-devel@gnu.org; Sat, 13 Jul 2019 20:42:53 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:41364) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hmSbM-0007zG-02; Sat, 13 Jul 2019 20:42:52 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 4B0B016169F; Sat, 13 Jul 2019 17:42:48 -0700 (PDT) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id JOFqaUoNxvdP; Sat, 13 Jul 2019 17:42:46 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id CEC8D161A3C; Sat, 13 Jul 2019 17:42:46 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id VETa5IMFBSSU; Sat, 13 Jul 2019 17:42:46 -0700 (PDT) Original-Received: from [192.168.1.9] (cpe-23-242-74-103.socal.res.rr.com [23.242.74.103]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 505A916169F; Sat, 13 Jul 2019 17:42:46 -0700 (PDT) In-Reply-To: <83pnmj3vp9.fsf@gnu.org> Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 131.179.128.68 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:238574 Archived-At: This is a multi-part message in MIME format. --------------FAE59654CFCF4ABBA81569AE Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Eli Zaretskii wrote: >> Because we now have a simpler solution. > > I don't think it's simpler: it causes 'message' write to a different > file descriptor, and thus introduces a backward incompatibility. I meant simpler to implement and easier to maintain. My email discussed the backward compatbility issue, which is negligible. >> Emacs uses stdout reasonably extensively for this sort of thing already; see >> 'write_stdout' and I can cite several other examples. > > write_stdout is used in exactly 10 places, which I wouldn't call "extensive". As I mentioned, write_stdout isn't the only place stdout is used for this sort of thing. Another example is w32con_write_glyphs. I'm not saying stdout is used as often as stderr; however, stdout is used in a reasonably large set of places, and nobody cares. In this sense, Emacs differs from typical Unix-like utilities. > It is used where AFAIU any other file descriptor would > be problematic. In the places where write_stdout is used, stderr is no more problematic than stdout is. Neither is guaranteed to be displayed to the user. > I don't understand how could you make these assertions. What are they > based on? You're asking me to prove a negative? OK, I concede; I can't do that. However, my statements were based on experience in using Emacs and in reading its source code and bug reports and complaints about it. > So I think your previous proposal for message_to_stderr and vmessage > should be okay to go in. But not the rest, sorry. OK, I put that proposal into master (with some minor improvements). Also, I installed the attached patches to fix the most-annoying remaining stderr interleaving problems without changing stderr buffering. This should be enough to address the interleaving problems on GNU/Linux, in areas where the OS lets us address them. Unfortunately, GNU Emacs master still suffers from interleaving problems on Solaris, AIX, and perhaps some other POSIXish platforms, because their fprintf implementations write "%s"-formatted strings separately. Although it's easy to fix that, no fix is likely to meet your standards. --------------FAE59654CFCF4ABBA81569AE Content-Type: text/x-patch; name="0001-Avoid-interleaving-stderr-in-dump_fingerprint.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Avoid-interleaving-stderr-in-dump_fingerprint.patch" >From 1178f98f2c0973dd1f8a66cbb4de20c0d7af3271 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 13 Jul 2019 10:41:46 -0700 Subject: [PATCH] Avoid interleaving stderr in dump_fingerprint * src/fns.c (hexbuf_digest): New function, containing most of the old make_digest_string. (make_digest_string): Use it. * src/pdumper.c (dump_fingerprint): Rewrite to use a single fprintf call, to avoid interleaving on GNU/Linux. --- src/fns.c | 19 ++++++++++++++----- src/lisp.h | 1 + src/pdumper.c | 13 +++++++------ 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/fns.c b/src/fns.c index 6a7c347728..54dafe07ac 100644 --- a/src/fns.c +++ b/src/fns.c @@ -5040,18 +5040,27 @@ returns nil, then (funcall TEST x1 x2) also returns nil. */) #include "sha256.h" #include "sha512.h" -static Lisp_Object -make_digest_string (Lisp_Object digest, int digest_size) +/* Store into HEXBUF an unterminated hexadecimal character string + representing DIGEST, which is binary data of size DIGEST_SIZE bytes. + HEXBUF might equal DIGEST. */ +void +hexbuf_digest (char *hexbuf, void const *digest, int digest_size) { - unsigned char *p = SDATA (digest); + unsigned char const *p = digest; for (int i = digest_size - 1; i >= 0; i--) { static char const hexdigit[16] = "0123456789abcdef"; int p_i = p[i]; - p[2 * i] = hexdigit[p_i >> 4]; - p[2 * i + 1] = hexdigit[p_i & 0xf]; + hexbuf[2 * i] = hexdigit[p_i >> 4]; + hexbuf[2 * i + 1] = hexdigit[p_i & 0xf]; } +} + +static Lisp_Object +make_digest_string (Lisp_Object digest, int digest_size) +{ + hexbuf_digest (SSDATA (digest), SDATA (digest), digest_size); return digest; } diff --git a/src/lisp.h b/src/lisp.h index e93a219625..4885e26e3f 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -3586,6 +3586,7 @@ extern ptrdiff_t list_length (Lisp_Object); extern EMACS_INT next_almost_prime (EMACS_INT) ATTRIBUTE_CONST; extern Lisp_Object larger_vector (Lisp_Object, ptrdiff_t, ptrdiff_t); extern bool sweep_weak_table (struct Lisp_Hash_Table *, bool); +extern void hexbuf_digest (char *, void const *, int); extern char *extract_data_from_object (Lisp_Object, ptrdiff_t *, ptrdiff_t *); EMACS_UINT hash_string (char const *, ptrdiff_t); EMACS_UINT sxhash (Lisp_Object, int); diff --git a/src/pdumper.c b/src/pdumper.c index b80757c207..03c00bf27b 100644 --- a/src/pdumper.c +++ b/src/pdumper.c @@ -324,12 +324,13 @@ dump_reloc_set_offset (struct dump_reloc *reloc, dump_off offset) } static void -dump_fingerprint (const char *label, unsigned char const *xfingerprint) +dump_fingerprint (char const *label, + unsigned char const xfingerprint[sizeof fingerprint]) { - fprintf (stderr, "%s: ", label); - for (int i = 0; i < 32; ++i) - fprintf (stderr, "%02x", (unsigned) xfingerprint[i]); - putc ('\n', stderr); + enum { hexbuf_size = 2 * sizeof fingerprint }; + char hexbuf[hexbuf_size]; + hexbuf_digest (hexbuf, xfingerprint, sizeof fingerprint); + fprintf (stderr, "%s: %.*s\n", label, hexbuf_size, hexbuf); } /* Format of an Emacs portable dump file. All offsets are relative to @@ -355,7 +356,7 @@ struct dump_header char magic[sizeof (dump_magic)]; /* Associated Emacs binary. */ - unsigned char fingerprint[32]; + unsigned char fingerprint[sizeof fingerprint]; /* Relocation table for the dump file; each entry is a struct dump_reloc. */ -- 2.17.1 --------------FAE59654CFCF4ABBA81569AE Content-Type: text/x-patch; name="0001-Avoid-interleaving-stderr-lines-when-shutting-down.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-Avoid-interleaving-stderr-lines-when-shutting-down.patc"; filename*1="h" >From 34810ab4f9990a8de1e503fdf6b485d8eeea1601 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 13 Jul 2019 16:42:18 -0700 Subject: [PATCH] Avoid interleaving stderr lines when shutting down * src/emacs.c (shut_down_emacs) [!DOS_NT]: Avoid interleaving to stderr in the usual case, by using a single write and by appending a newline. * src/sysdep.c (emacs_backtrace) [HAVE_BACKTRACE_SYMBOLS_FD]: Omit newline since shut_down_emacs now does that. --- src/emacs.c | 38 ++++++++++++++++++++++---------------- src/sysdep.c | 2 +- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/emacs.c b/src/emacs.c index 9c93748a0f..ad661a081b 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -2454,23 +2454,29 @@ shut_down_emacs (int sig, Lisp_Object stuff) /* If we are controlling the terminal, reset terminal modes. */ #ifndef DOS_NT - { - pid_t pgrp = getpgrp (); - pid_t tpgrp = tcgetpgrp (0); - if ((tpgrp != -1) && tpgrp == pgrp) - { - reset_all_sys_modes (); - if (sig && sig != SIGTERM) - { - static char const format[] = "Fatal error %d: "; - char buf[sizeof format - 2 + INT_STRLEN_BOUND (int)]; - int buflen = sprintf (buf, format, sig); - char const *sig_desc = safe_strsignal (sig); + pid_t tpgrp = tcgetpgrp (STDIN_FILENO); + if (tpgrp != -1 && tpgrp == getpgrp ()) + { + reset_all_sys_modes (); + if (sig && sig != SIGTERM) + { + static char const fmt[] = "Fatal error %d: %n%s\n"; + char buf[max ((sizeof fmt - sizeof "%d%n%s\n" + + INT_STRLEN_BOUND (int) + 1), + min (PIPE_BUF, MAX_ALLOCA))]; + char const *sig_desc = safe_strsignal (sig); + int nlen; + int buflen = snprintf (buf, sizeof buf, fmt, sig, &nlen, sig_desc); + if (0 <= buflen && buflen < sizeof buf) emacs_write (STDERR_FILENO, buf, buflen); - emacs_write (STDERR_FILENO, sig_desc, strlen (sig_desc)); - } - } - } + else + { + emacs_write (STDERR_FILENO, buf, nlen); + emacs_write (STDERR_FILENO, sig_desc, strlen (sig_desc)); + emacs_write (STDERR_FILENO, fmt + sizeof fmt - 2, 1); + } + } + } #else fflush (stdout); reset_all_sys_modes (); diff --git a/src/sysdep.c b/src/sysdep.c index 9301405943..f7478253a3 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -2436,7 +2436,7 @@ emacs_backtrace (int backtrace_limit) if (npointers) { - emacs_write (STDERR_FILENO, "\nBacktrace:\n", 12); + emacs_write (STDERR_FILENO, "Backtrace:\n", 11); backtrace_symbols_fd (buffer, npointers, STDERR_FILENO); if (bounded_limit < npointers) emacs_write (STDERR_FILENO, "...\n", 4); -- 2.17.1 --------------FAE59654CFCF4ABBA81569AE--