aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2019-07-13 10:41:46 -0700
committerPaul Eggert2019-07-13 16:53:21 -0700
commit1178f98f2c0973dd1f8a66cbb4de20c0d7af3271 (patch)
tree0d85660fe6133895571ac48b6f1403cd8cdd58d9 /src
parenta8ffbb20da67b20a85ddca38e20c609144c3bef3 (diff)
downloademacs-1178f98f2c0973dd1f8a66cbb4de20c0d7af3271.tar.gz
emacs-1178f98f2c0973dd1f8a66cbb4de20c0d7af3271.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/fns.c19
-rw-r--r--src/lisp.h1
-rw-r--r--src/pdumper.c13
3 files changed, 22 insertions, 11 deletions
diff --git a/src/fns.c b/src/fns.c
index 6a7c3477282..54dafe07ac8 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -5040,18 +5040,27 @@ returns nil, then (funcall TEST x1 x2) also returns nil. */)
5040#include "sha256.h" 5040#include "sha256.h"
5041#include "sha512.h" 5041#include "sha512.h"
5042 5042
5043static Lisp_Object 5043/* Store into HEXBUF an unterminated hexadecimal character string
5044make_digest_string (Lisp_Object digest, int digest_size) 5044 representing DIGEST, which is binary data of size DIGEST_SIZE bytes.
5045 HEXBUF might equal DIGEST. */
5046void
5047hexbuf_digest (char *hexbuf, void const *digest, int digest_size)
5045{ 5048{
5046 unsigned char *p = SDATA (digest); 5049 unsigned char const *p = digest;
5047 5050
5048 for (int i = digest_size - 1; i >= 0; i--) 5051 for (int i = digest_size - 1; i >= 0; i--)
5049 { 5052 {
5050 static char const hexdigit[16] = "0123456789abcdef"; 5053 static char const hexdigit[16] = "0123456789abcdef";
5051 int p_i = p[i]; 5054 int p_i = p[i];
5052 p[2 * i] = hexdigit[p_i >> 4]; 5055 hexbuf[2 * i] = hexdigit[p_i >> 4];
5053 p[2 * i + 1] = hexdigit[p_i & 0xf]; 5056 hexbuf[2 * i + 1] = hexdigit[p_i & 0xf];
5054 } 5057 }
5058}
5059
5060static Lisp_Object
5061make_digest_string (Lisp_Object digest, int digest_size)
5062{
5063 hexbuf_digest (SSDATA (digest), SDATA (digest), digest_size);
5055 return digest; 5064 return digest;
5056} 5065}
5057 5066
diff --git a/src/lisp.h b/src/lisp.h
index e93a219625e..4885e26e3f3 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -3586,6 +3586,7 @@ extern ptrdiff_t list_length (Lisp_Object);
3586extern EMACS_INT next_almost_prime (EMACS_INT) ATTRIBUTE_CONST; 3586extern EMACS_INT next_almost_prime (EMACS_INT) ATTRIBUTE_CONST;
3587extern Lisp_Object larger_vector (Lisp_Object, ptrdiff_t, ptrdiff_t); 3587extern Lisp_Object larger_vector (Lisp_Object, ptrdiff_t, ptrdiff_t);
3588extern bool sweep_weak_table (struct Lisp_Hash_Table *, bool); 3588extern bool sweep_weak_table (struct Lisp_Hash_Table *, bool);
3589extern void hexbuf_digest (char *, void const *, int);
3589extern char *extract_data_from_object (Lisp_Object, ptrdiff_t *, ptrdiff_t *); 3590extern char *extract_data_from_object (Lisp_Object, ptrdiff_t *, ptrdiff_t *);
3590EMACS_UINT hash_string (char const *, ptrdiff_t); 3591EMACS_UINT hash_string (char const *, ptrdiff_t);
3591EMACS_UINT sxhash (Lisp_Object, int); 3592EMACS_UINT sxhash (Lisp_Object, int);
diff --git a/src/pdumper.c b/src/pdumper.c
index b80757c2071..03c00bf27b7 100644
--- a/src/pdumper.c
+++ b/src/pdumper.c
@@ -324,12 +324,13 @@ dump_reloc_set_offset (struct dump_reloc *reloc, dump_off offset)
324} 324}
325 325
326static void 326static void
327dump_fingerprint (const char *label, unsigned char const *xfingerprint) 327dump_fingerprint (char const *label,
328 unsigned char const xfingerprint[sizeof fingerprint])
328{ 329{
329 fprintf (stderr, "%s: ", label); 330 enum { hexbuf_size = 2 * sizeof fingerprint };
330 for (int i = 0; i < 32; ++i) 331 char hexbuf[hexbuf_size];
331 fprintf (stderr, "%02x", (unsigned) xfingerprint[i]); 332 hexbuf_digest (hexbuf, xfingerprint, sizeof fingerprint);
332 putc ('\n', stderr); 333 fprintf (stderr, "%s: %.*s\n", label, hexbuf_size, hexbuf);
333} 334}
334 335
335/* Format of an Emacs portable dump file. All offsets are relative to 336/* Format of an Emacs portable dump file. All offsets are relative to
@@ -355,7 +356,7 @@ struct dump_header
355 char magic[sizeof (dump_magic)]; 356 char magic[sizeof (dump_magic)];
356 357
357 /* Associated Emacs binary. */ 358 /* Associated Emacs binary. */
358 unsigned char fingerprint[32]; 359 unsigned char fingerprint[sizeof fingerprint];
359 360
360 /* Relocation table for the dump file; each entry is a 361 /* Relocation table for the dump file; each entry is a
361 struct dump_reloc. */ 362 struct dump_reloc. */