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

Re: [PATCH 1/2] Added use of xmalloc() on diff-delta.c

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Apr 4, 2007, 22:31 UTC
Message-ID
<Pine.LNX.4.64.0704041525220.6730@woody.linux-foundation.org>
In-Reply-To
<7vejn02bcv.fsf@assigned-by-dhcp.cox.net>
On Wed, 4 Apr 2007, Junio C Hamano wrote:
> 
> These patches take that nice property away, making libification
> more difficult, which is the downside.  Is there an upside?
Well, we could just make the libification rule very simple:
 - the library does *not* include "xmalloc()", and you have to handle 
   out-of-memory situations yourself inside the xmalloc() that *you* as a 
   libification user provide!.

Then, we just make our xmalloc() be non-inlined (which we should do *anyway* - it's long since grown so big that it shouldn't be inlined in the first place), and we make it part of a non-library git object file.

Other libgit uses might end up doing something like
		..
		if (sigsetjump(buffer, 1)) {
			show_oom_message();
		..
	void *xmalloc(size_t size)
	{
		void *ret = malloc(size ? size : 1);
		if (!ret)
			siglongjmp(buffer);
		return ret;
	}

or, if they use C++ exception handling, they'd just make their own xmalloc() raise an exception, and have the callers catch it.

The point being that this is what you'd need to do *anyway*, and trying to make all the library routines return NULL or some other error case is just worse programming practice than just having a xmalloc() that dies by default but that can be overridden.

		Linus
Previous: Junio C HamanoNext: Junio C Hamano
Message 4 of 5 in “Added use of xmalloc() on diff-delta.c”
  1. 1/2 Added use of xmalloc() on diff-delta.cBruno Ribas, Apr 4, 2007
  2. 2/2 Removed NULL check on builtin-pack-objects.c from create_delta_index() as it just checks for Out of MemoryBruno Ribas, Apr 4, 2007
  3. Junio C HamanoApr 4, 2007
  4. Linus TorvaldsApr 4, 2007
  5. Junio C HamanoApr 5, 2007

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.