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

Re: [RFD] Libification proposal: separate internal and external interfaces

From
Pphillip.wood123@gmail.com <phillip.wood123@gmail.com>
Date
Apr 23, 2024, 09:57 UTC
Message-ID
<cb2ffdb1-5e6c-4dd3-89d4-f0b31f2f17ec@gmail.com>
In-Reply-To
<20240422162617.308366-1-calvinwan@google.com>
Hi Calvin
On 22/04/2024 17:26, Calvin Wan wrote:
Show 26 quoted lines
> The first idea involves turning `strbuf_grow()` into a wrapper function
> that invokes its equivalent library function, eg.
> `libgit_strbuf_grow()`:
> 
> int libgit_strbuf_grow(struct strbuf *sb, size_t extra)
> {
> 	int new_buf = !sb->alloc;
> 	if (unsigned_add_overflows(extra, 1) ||
> 	    unsigned_add_overflows(sb->len, extra + 1))
> 		return -1;
> 	if (new_buf)
> 		sb->buf = NULL;
> 	ALLOC_GROW(sb->buf, sb->len + extra + 1, sb->alloc);
> 	if (new_buf)
> 		sb->buf[0] = '\0';
>          return 0;
> }
> 
> void strbuf_grow(struct strbuf *sb, size_t extra)
> {
>          if (libgit_strbuf_grow(sb, extra))
>                  die("you want to use way too much memory");
> }
> 
> (Note a context object could also be added as a parameter to
> `libgit_strbuf_grow()` for error messages and possibly global variables.)

I agree with Junio that this is a good route forward and that we should not consider removing the wrappers to be part of the libification project. ALLOC_GROW() can die so I think we'd need a way to propagate an error message up to the wrapper even for relatively simple functions like this. For the allocation functions we'd either need to use a static string for the message which is not a good fit for other functions that want to dynamically format their messages (for example to include a path name into the error message), or pre-allocate the error messages.

> The shortfall of this approach is that we'd be carrying two different
> functions for every library function until we are able to remove all of
> them. It would also create additional toil for Git contributors to
> figure out which version of the function should be used.

Hopefully it should be clear if a function is part of the library or not so I don't think this should be a big problem.

Best Wishes
Phillip
Previous: Junio C HamanoNext: Kyle Lippincott
Message 13 of 18 in “[RFD] Libification proposal: separate internal and external interfaces”
  1. Calvin WanApr 2, 2024
  2. brian m. carlsonApr 7, 2024
  3. rsbecker@nexbridge.comApr 7, 2024
  4. brian m. carlsonApr 8, 2024
  5. rsbecker@nexbridge.comApr 8, 2024
  6. Junio C HamanoApr 8, 2024
  7. brian m. carlsonApr 9, 2024
  8. Calvin WanApr 9, 2024
  9. Phillip WoodApr 9, 2024
  10. Calvin WanApr 9, 2024
  11. Calvin WanApr 22, 2024
  12. Junio C HamanoApr 22, 2024
  13. phillip.wood123@gmail.comApr 23, 2024
  14. Kyle LippincottMay 9, 2024
  15. Phillip WoodMay 10, 2024
  16. Kyle LippincottMay 10, 2024
  17. Kyle LippincottMay 9, 2024
  18. Junio C HamanoMay 9, 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.