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

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

bug#46111: Reverting fns.c hash function due to OpenBSD/SPARC64 compile


From: Stefan Monnier
Subject: bug#46111: Reverting fns.c hash function due to OpenBSD/SPARC64 compile breaking
Date: Thu, 28 Jan 2021 11:17:31 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> And the backtrace shows we're hashing the string `DndProtocol` which
> comes from `lisp/x-dnd.el` which is indeed preloaded, so I think that's
> what's going on.

Could you try the patch below?


        Stefan


diff --git a/src/fns.c b/src/fns.c
index 7ab2e8f1a0..0c6bb770ef 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -4610,7 +4610,20 @@ hash_string (char const *ptr, ptrdiff_t len)
    * as `p <= end - 1`.  */
   while (p <= end - 1)
     {
+      /* Here `p` is *almost* always be properly aligned, so we want to
+         optimize for the aligned case, but we still need to support the
+         non-aligned case.  */
+      /* FIXME: Could we just always use `memcpy` and rely on GCC optimizing
+         it to a single word-sized memory access on all-but-sparc64?  */
+#ifdef __sparc64__  /* Arch that still insists on aligned memory accesses. */
+      EMACS_UINT c;
+      if (!((unsigned long)p) % sizeof (c))
+        c = *p;
+      else
+        memcpy (&c, (char const *)p, sizeof (c)); /* `p` is unaligned!  */
+#else
       EMACS_UINT c = *p;
+#fi
       p += step;
       hash = sxhash_combine (hash, c);
     }






reply via email to

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