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

Re: [PATCH 1/2] oidmap: make oidmap_free independent of struct layout

From
Jeff King <peff@peff.net>
Date
Apr 8, 2020, 21:54 UTC
Message-ID
<20200408215423.GA3468797@coredump.intra.peff.net>
In-Reply-To
<20200408040659.14511-1-abhishekkumar8222@gmail.com>
On Wed, Apr 08, 2020 at 09:36:58AM +0530, Abhishek Kumar wrote:
Show 6 quoted lines
> c8e424c introduced hashmap_free_entries, which can free any struct
> pointer, regardless of the hashmap_entry field offset.
> 
> oidmap does not make use of this flexibilty, hardcoding the offset to
> zero instead. Let's fix this by passing struct type and member to
> hashmap_free_entries.
I'm not sure how much this improves anything.

We're now telling the hashmap code how to get to our "struct oidmap_entry" pointer by using the correct offset there. But we know that offset will always be 0, because we put our internal hashmap entry at the start of oidmap_entry.

What you can't do is:
  struct foo {
    int first_member;
    struct oidmap_entry not_the_first_member;
  };

and work directly with "struct foo" pointers. You have to convert oidmap_entry pointers into foo pointers with container_of() or similar. And that is true both before and after your patch.

That said, I don't mind doing this as a cleanup; there's a subtle dependency on the location of internal_entry within object_entry, and this would move towards getting rid of it.

-Peff
Previous: Jeff KingNext: Abhishek Kumar
Message 7 of 10 in “oidmap: make oidmap_free independent of struct layout”
  1. 1/2 oidmap: make oidmap_free independent of struct layoutAbhishek Kumar, Apr 8, 2020
  2. 2/2 oidmap: rework iterators to return typed pointerAbhishek Kumar, Apr 8, 2020
  3. Junio C HamanoApr 8, 2020
  4. 1/2 oidmap: make oidmap_free independent of struct layoutAbhishek Kumar, Apr 8, 2020
  5. 2/2 oidmap: rework iterators to return typed pointerAbhishek Kumar, Apr 8, 2020
  6. Jeff KingApr 8, 2020
  7. Jeff KingApr 8, 2020
  8. 1/3 oidmap: make oidmap_free independent of struct layoutAbhishek Kumar, Apr 25, 2020
  9. 2/3 oidmap: rework iterators to return typed pointerAbhishek Kumar, Apr 25, 2020
  10. 3/3 oidmap: return oidmap_entry pointersAbhishek Kumar, Apr 25, 2020

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.