git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/3] khashl: fix ensemble lookups on empty table

From
EWEric Wong <e@80x24.org>
Date
Mar 28, 2024, 10:13 UTC
Message-ID
<20240328101356.300374-4-e@80x24.org>
In-Reply-To
<20240328101356.300374-1-e@80x24.org>

The ->bits field of regular khashl structs is invalid when the ->keys array is NULL. Thus the ensemble *_getp implementation must follow existing *_get and *_getp usage conventions and check the iterator against kh_end().

This fixes a fast-import crash on t3427-rebase-subtree.sh in an abandoned commit to use the ensemble implementation for oid_map and oid_pos. I've abandoned the aforementioned commit for now since it was more intrusive, more expensive for small tables, and realloc(3) on glibc is already optimized using mremap(2) for large hash resizes.

Signed-off-by: Eric Wong <e@80x24.org>
---
 khashl.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/khashl.h b/khashl.h
index 1e724bbf88..30f85dc5e2 100644
--- a/khashl.h
+++ b/khashl.h
@@ -265,7 +265,7 @@ typedef struct {
 		low = hash & ((1U<<g->bits) - 1); \
 		h = &g->sub[low]; \
 		ret = prefix##_sub_getp_core(h, key, hash); \
-		if (ret == 1U<<h->bits) r.sub = low, r.pos = (khint_t)-1; \
+		if (ret >= kh_end(h)) r.sub = low, r.pos = (khint_t)-1; \
 		else r.sub = low, r.pos = ret; \
 		return r; \
 	} \
Previous: Eric WongNext: Eric Wong
Message 4 of 7 in “switch to tombstone-free khashl table”
  1. 0/3 switch to tombstone-free khashl tableEric Wong, Mar 28, 2024
  2. 1/3 list-objects-filter: use kh_size APIEric Wong, Mar 28, 2024
  3. 2/3 treewide: switch to khashl for memory savingsEric Wong, Mar 28, 2024
  4. 3/3 khashl: fix ensemble lookups on empty tableEric Wong, Mar 28, 2024
  5. oops, forgot [v2]Eric Wong, Mar 28, 2024
  6. Junio C HamanoMar 28, 2024
  7. Eric WongMar 28, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.