In my new merge algorithm, I made use of the mem_pool API in a few places...but I also needed to add a few more functions and also needed to make the API a bit more general. Changes since v1: * Made the error message tweaks suggested by Eric * Although mem_pool_init() intialized all members manually, add a memset() to 0 for future-proofing, as suggested by Junio. * Use 'pool' instead of 'mem_pool' in patch 2 so that patch 3 doesn't have to change as much (as suggested by Junio). Also, Matheus said he'd rebase his parallel-checkout RFC series (next yet in next or seen) on top of mine to avoid the semantic conflict. Elijah Newren (3): mem-pool: add convenience functions for xstrdup and xstrndup mem-pool: use more standard initialization and finalization mem-pool: use consistent pool variable name fast-import.c | 12 ++------- mem-pool.c | 74 ++++++++++++++++++++++++++++++++------------------- mem-pool.h | 14 +++++++--- read-cache.c | 21 +++++++++------ split-index.c | 6 +++-- 5 files changed, 75 insertions(+), 52 deletions(-) base-commit: 7814e8a05a59c0cf5fb186661d1551c75d1299b5 Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-830%2Fnewren%2Fmem_pool_api-v2 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-830/newren/mem_pool_api-v2 Pull-Request: https://github.com/git/git/pull/830 Range-diff vs v1: 1: eae8b2923f ! 1: 6d679c5b46 mem-pool: add convenience functions for xstrdup and xstrndup @@ mem-pool.c: void *mem_pool_calloc(struct mem_pool *mem_pool, size_t count, size_ + char *ret = mem_pool_alloc(pool, len); + + if (!ret) -+ die("Out of memory, mem_pool_xstrdup failed"); ++ die(_("mem_pool_xstrdup: out of memory")); + + return memcpy(ret, str, len); +} @@ mem-pool.c: void *mem_pool_calloc(struct mem_pool *mem_pool, size_t count, size_ + char *ret = mem_pool_alloc(pool, minlen+1); + + if (!ret) -+ die("Out of memory, mem_pool_xstrndup failed"); ++ die(_("mem_pool_xstrndup: out of memory")); + + ret[minlen] = '\0'; + return memcpy(ret, str, minlen); 2: f13a52055c ! 2: e04ba96b22 mem-pool: use more standard initialization and finalization @@ mem-pool.c: static struct mp_block *mem_pool_alloc_block(struct mem_pool *mem_po } -void mem_pool_init(struct mem_pool **mem_pool, size_t initial_size) -+void mem_pool_init(struct mem_pool *mem_pool, size_t initial_size) ++void mem_pool_init(struct mem_pool *pool, size_t initial_size) { - struct mem_pool *pool; - @@ mem-pool.c: static struct mp_block *mem_pool_alloc_block(struct mem_pool *mem_po - - pool = xcalloc(1, sizeof(*pool)); - -- pool->block_alloc = BLOCK_GROWTH_SIZE; -+ mem_pool->mp_block = NULL; -+ mem_pool->pool_alloc = 0; -+ mem_pool->block_alloc = BLOCK_GROWTH_SIZE; ++ memset(pool, 0, sizeof(*pool)); + pool->block_alloc = BLOCK_GROWTH_SIZE; if (initial_size > 0) -- mem_pool_alloc_block(pool, initial_size, NULL); + mem_pool_alloc_block(pool, initial_size, NULL); - - *mem_pool = pool; -+ mem_pool_alloc_block(mem_pool, initial_size, NULL); } void mem_pool_discard(struct mem_pool *mem_pool, int invalidate_memory) @@ mem-pool.h: struct mem_pool { * Initialize mem_pool with specified initial size. */ -void mem_pool_init(struct mem_pool **mem_pool, size_t initial_size); -+void mem_pool_init(struct mem_pool *mem_pool, size_t initial_size); ++void mem_pool_init(struct mem_pool *pool, size_t initial_size); /* - * Discard a memory pool and free all the memory it is responsible for. 3: 62c2479fe6 ! 3: 616402c64e mem-pool: use consistent pool variable name @@ mem-pool.c: static struct mp_block *mem_pool_alloc_block(struct mem_pool *mem_po } return p; - } - --void mem_pool_init(struct mem_pool *mem_pool, size_t initial_size) -+void mem_pool_init(struct mem_pool *pool, size_t initial_size) - { -- mem_pool->mp_block = NULL; -- mem_pool->pool_alloc = 0; -- mem_pool->block_alloc = BLOCK_GROWTH_SIZE; -+ pool->mp_block = NULL; -+ pool->pool_alloc = 0; -+ pool->block_alloc = BLOCK_GROWTH_SIZE; - - if (initial_size > 0) -- mem_pool_alloc_block(mem_pool, initial_size, NULL); -+ mem_pool_alloc_block(pool, initial_size, NULL); +@@ mem-pool.c: void mem_pool_init(struct mem_pool *pool, size_t initial_size) + mem_pool_alloc_block(pool, initial_size, NULL); } -void mem_pool_discard(struct mem_pool *mem_pool, int invalidate_memory) @@ mem-pool.c: char *mem_pool_xstrndup(struct mem_pool *pool, const char *str, size return 1; ## mem-pool.h ## -@@ mem-pool.h: struct mem_pool { - /* - * Initialize mem_pool with specified initial size. - */ --void mem_pool_init(struct mem_pool *mem_pool, size_t initial_size); -+void mem_pool_init(struct mem_pool *pool, size_t initial_size); - +@@ mem-pool.h: void mem_pool_init(struct mem_pool *pool, size_t initial_size); /* * Discard all the memory the memory pool is responsible for. */ -- gitgitgadget