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

Re: [PATCH v3 0/4] fetch/receive: use batched reference updates

From
Jeff King <peff@peff.net>
Date
May 22, 2025, 15:31 UTC
Message-ID
<20250522153136.GA1150962@coredump.intra.peff.net>
In-Reply-To
<CAOLa=ZQhaPXS1y5zkRv2CQ_S5=8+XRg_A1snXHVYXz3uvVgZSg@mail.gmail.com>
On Thu, May 22, 2025 at 01:50:18AM -0700, Karthik Nayak wrote:
Show 13 quoted lines
> > If we store and return a "void *" pointer as we do now, but accept a
> > const pointer via strmap_put(), then we're casting away potentially
> > important const-ness without the caller even seeing it. I think it's
> > safer for the client to do the cast explicitly (since they are the ones
> > who know how they plan to use it).
> >
> 
> But isn't that the case now anyways? We always lose the const-ness since
> we only accept a 'void *'. But by only changing 'strmap_put()' to accept
> a 'const void *', but storing and returning a 'void *'. We simply modify
> the current construct to also say that any data received is not
> modified. But I do see your point, we'll have to cast there anyways and
> might as well do it on the client side.

Right, there is no winning here in the type system. But by pushing the cast onto the calling side, it is more visible and closer to the code that knows how the result will be used.

Show 7 quoted lines
> > I don't think we can really represent what we want in C's type system.
> > But if we wanted a safe(r) interface that didn't involve type-casting,
> > we might be able to do something like:
> [...]
> Agreed, and then there is additional load to ensure users will use
> 'strmap_put()' and 'strmap_put_const()' as required and simply not cast
> away.

That part I'm not too worried about, since casts are easy-ish to catch and flag in reviews. But I'm not sure if it's materially making the world a better place to have the extra complexity.

-Peff
Previous: Karthik Nayak
Message 11 of 11 in “fetch/receive: use batched reference updates”
  1. 0/4 fetch/receive: use batched reference updatesKarthik Nayak, May 19, 2025
  2. 1/4 refs: add function to translate errors to stringsKarthik Nayak, May 19, 2025
  3. 2/4 fetch: use batched reference updatesKarthik Nayak, May 19, 2025
  4. 3/4 send-pack: fix memory leak around duplicate refsKarthik Nayak, May 19, 2025
  5. 4/4 receive-pack: use batched reference updatesKarthik Nayak, May 19, 2025
  6. Junio C HamanoMay 19, 2025
  7. Karthik NayakMay 20, 2025
  8. Junio C HamanoMay 21, 2025
  9. Jeff KingMay 22, 2025
  10. Karthik NayakMay 22, 2025
  11. Jeff KingMay 22, 2025

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.