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

[PATCH 7/8] wrapper: expose try_to_free_pack_memory()

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Nov 6, 2010, 11:48 UTC
Message-ID
<20101106114817.GG27641@burratino>
In-Reply-To
<20101106113905.GA27405@burratino>

As v1.7.0-rc0~43 (slim down "git show-index", 2010-01-21) explains, xmalloc() is dependent on zlib, the sha1 lib, and the rest of git's object file access machinery via try_to_free_pack_memory. That is overkill when xmalloc() is only being used to print a message and exit on memory exhaustion.

So let each caller decide whether the "discard pack windows" logic is needed. Programs using the sha1_file library should request that xmalloc discard stale windows when an allocation fails, by calling

	set_try_to_free_handler(try_to_free_pack_memory);

A later patch will stop setting up that handler except in response to such explicit requests, allowing wrapper.o to be used without adding a sha1_file.o dependency by programs that do not access the object db.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 git-compat-util.h |    1 +
 sha1_file.c       |    5 +++++
 wrapper.c         |    7 +------
 3 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/git-compat-util.h b/git-compat-util.h
index 029162e..07ee75e 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -387,6 +387,7 @@ static inline void *gitmempcpy(void *dest, const void *src, size_t n)
 #endif
 
 extern void release_pack_memory(size_t, int);
+extern void try_to_free_pack_memory(size_t size);
 
 typedef void (*try_to_free_t)(size_t);
 extern try_to_free_t set_try_to_free_routine(try_to_free_t);
diff --git a/sha1_file.c b/sha1_file.c
index 8e299ae..c48baaa 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -576,6 +576,11 @@ void release_pack_memory(size_t need, int fd)
 		; /* nothing */
 }
 
+void try_to_free_pack_memory(size_t size)
+{
+	release_pack_memory(size, -1);
+}
+
 void *xmmap(void *start, size_t length,
 	int prot, int flags, int fd, off_t offset)
 {
diff --git a/wrapper.c b/wrapper.c
index 185dfbc..6c6579b 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -3,12 +3,7 @@
  */
 #include "cache.h"
 
-static void try_to_free_builtin(size_t size)
-{
-	release_pack_memory(size, -1);
-}
-
-static void (*try_to_free_routine)(size_t size) = try_to_free_builtin;
+static void (*try_to_free_routine)(size_t size) = try_to_free_pack_memory;
 
 try_to_free_t set_try_to_free_routine(try_to_free_t routine)
 {
-- 
1.7.2.3.557.gab647.dirty
Previous: Jonathan NiederNext: Jonathan Nieder
Message 8 of 14 in “Remove various dependencies from wrapper.o”
  1. 0/8 Remove various dependencies from wrapper.oJonathan Nieder, Nov 6, 2010
  2. 1/8 wrapper: move xmmap() to sha1_file.cJonathan Nieder, Nov 6, 2010
  3. 2/8 wrapper: move odb_* to environment.cJonathan Nieder, Nov 6, 2010
  4. 3/8 path helpers: move git_mkstemp* to wrapper.cJonathan Nieder, Nov 6, 2010
  5. 4/8 strbuf: move strbuf_branchname to sha1_name.cJonathan Nieder, Nov 6, 2010
  6. 5/8 wrapper: give zlib wrappers their own translation unitJonathan Nieder, Nov 6, 2010
  7. 6/8 pack-objects: mark file-local variable staticJonathan Nieder, Nov 6, 2010
  8. 7/8 wrapper: expose try_to_free_pack_memory()Jonathan Nieder, Nov 6, 2010
  9. 8/8 Remove pack file handling dependency from wrapper.oJonathan Nieder, Nov 6, 2010
  10. René ScharfeNov 6, 2010
  11. Jonathan NiederNov 6, 2010
  12. René ScharfeNov 7, 2010
  13. Jonathan NiederNov 7, 2010
  14. Jonathan NiederNov 6, 2010

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.