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

Re: [PATCH] reftable: use xmalloc() and xrealloc()

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 8, 2024, 20:36 UTC
Message-ID
<xmqqzfu3a8x3.fsf@gitster.g>
In-Reply-To
<CAOw_e7Z9dGeVU399D6o37L3am0abnYUrZnNQEFKhyUv=A2=j8g@mail.gmail.com>
Han-Wen Nienhuys <hanwenn@gmail.com> writes:
> However, it is probably pointless as long as strbuf_* functions do not
> signal OOM gracefully. There was some talk of libifying strbuf. Did
> that work include returning OOM error codes in case malloc returns
> null? A quick look at strbuf.h suggests not.
I would expect not.

The "libified" strbuf (aka "strbuf API in the Git std lib") will have to be different from what we internally use from <strbuf.h>. <gitstdlib/strbuf.h> will export gitstdlib_strbuf_addstr(), which is "properly" libified and signals an allocation failure to its caller.

When that happens, I would expect that strbuf_addstr() would be a thin wrapper around gitstdlib_strbuf_addstr(), and still just dies with "we ran out of memory", i.e.

	/* strbuf.h */
	#include <strbuf.h>
	#include <gitstdlib/strbuf.h>
	void strbuf_addstr(struct strbuf *sb, const char *s)
	{
		int err = gitstdlib_strbuf_addstr(sb, s);
                if (!err)
			return; /* happy */
		switch (err) {
		case GITLIB_OOM: /* there may be others */
			die("Out of memory");
			...
		}
	}

which would keep the damage to Git codebase to the minimum when we become the first client of the "Git std lib".

Previous: Han-Wen NienhuysNext: Patrick Steinhardt
Message 6 of 7 in “reftable: use xmalloc() and xrealloc()”
  1. reftable: use xmalloc() and xrealloc()René Scharfe, Apr 6, 2024
  2. Patrick SteinhardtApr 8, 2024
  3. Junio C HamanoApr 8, 2024
  4. Patrick SteinhardtApr 8, 2024
  5. Han-Wen NienhuysApr 8, 2024
  6. Junio C HamanoApr 8, 2024
  7. Patrick SteinhardtApr 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.