All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Han-Wen Nienhuys <hanwenn@gmail.com>
Cc: "Patrick Steinhardt" <ps@pks.im>, "René Scharfe" <l.s.r@web.de>,
	"Git List" <git@vger.kernel.org>,
	nasamuffin@google.com
Subject: Re: [PATCH] reftable: use xmalloc() and xrealloc()
Date: Mon, 08 Apr 2024 13:36:40 -0700	[thread overview]
Message-ID: <xmqqzfu3a8x3.fsf@gitster.g> (raw)
In-Reply-To: <CAOw_e7Z9dGeVU399D6o37L3am0abnYUrZnNQEFKhyUv=A2=j8g@mail.gmail.com> (Han-Wen Nienhuys's message of "Mon, 8 Apr 2024 19:50:47 +0200")

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".

  reply	other threads:[~2024-04-08 20:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-06 20:37 [PATCH] reftable: use xmalloc() and xrealloc() René Scharfe
2024-04-08  5:44 ` Patrick Steinhardt
2024-04-08 15:42   ` Junio C Hamano
2024-04-08 16:33     ` Patrick Steinhardt
2024-04-08 17:50   ` Han-Wen Nienhuys
2024-04-08 20:36     ` Junio C Hamano [this message]
2024-04-09  3:24     ` Patrick Steinhardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqzfu3a8x3.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=hanwenn@gmail.com \
    --cc=l.s.r@web.de \
    --cc=nasamuffin@google.com \
    --cc=ps@pks.im \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.