v1-0001-Add-valgrind-safe-code-to-find-rightmost-bytes.patch

text/x-patch

Filename: v1-0001-Add-valgrind-safe-code-to-find-rightmost-bytes.patch
Type: text/x-patch
Part: 0
Message: Re: Change GUC hashtable to use simplehash?

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Series: patch v1-0001
Subject: Add valgrind-safe code to find a number of rightmost zero bytes.
File+
src/include/common/hashfn_unstable.h 10 1
From 7af05703e59fb8f1e51ec1d667ddc150c40756f0 Mon Sep 17 00:00:00 2001
From: "Anton A. Melnikov" <a.melnikov@postgrespro.ru>
Date: Thu, 16 Jan 2025 02:56:52 +0300
Subject: [PATCH] Add valgrind-safe code to find a number of rightmost zero
 bytes.

---
 src/include/common/hashfn_unstable.h | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/include/common/hashfn_unstable.h b/src/include/common/hashfn_unstable.h
index a09c0b7d5ce..7674c39b1ca 100644
--- a/src/include/common/hashfn_unstable.h
+++ b/src/include/common/hashfn_unstable.h
@@ -302,13 +302,22 @@ fasthash_accum_cstring_aligned(fasthash_state *hs, const char *str)
 		size_t		remainder;
 		uint64		mask;
 
+#if !defined(USE_VALGRIND)
 		/*
 		 * The byte corresponding to the NUL will be 0x80, so the rightmost
 		 * bit position will be in the range 15, 23, ..., 63. Turn this into
 		 * byte position by dividing by 8.
 		 */
 		remainder = pg_rightmost_one_pos64(zero_byte_low) / BITS_PER_BYTE;
-
+#else
+		/* valgrind-safe variant */
+		remainder = 0;
+		while ((zero_byte_low & 0xFF) == 0)
+		{
+			zero_byte_low >>= 8;
+			++remainder;
+		}
+#endif
 		/*
 		 * Create a mask for the remaining bytes so we can combine them into
 		 * the hash. This must have the same result as mixing the remaining
-- 
2.48.1