merge-ort: add pool_alloc, pool_calloc, and pool_strndup wrappers

Make the code more flexible so that it can handle both being run with or without a memory pool by adding utility functions which will either call xmalloc, xcalloc, xstrndup or mem_pool_alloc, mem_pool_calloc, mem_pool_strndup depending on whether we have a non-NULL memory pool. A subsequent commit will make use of these. (We will actually be dropping these functions soon and just assuming we always have a memory pool, but the flexibility was very useful during development of merge-ort so I want to be able to restore it if needed.) Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Jul 30, 2021 at 11:47 UTC cdf2241c717b05845ff9e25b87be6ca7559e82eb
1 file changed +24
merge-ort.c
+24
@@ -664,6 +664,30 @@ static void path_msg(struct merge_options *opt,
664 strbuf_addch(sb, '\n');
665 }
666
667 +MAYBE_UNUSED
668 +static void *pool_calloc(struct mem_pool *pool, size_t count, size_t size)
669 +{
670 + if (!pool)
671 + return xcalloc(count, size);
672 + return mem_pool_calloc(pool, count, size);
673 +}
674 +
675 +MAYBE_UNUSED
676 +static void *pool_alloc(struct mem_pool *pool, size_t size)
677 +{
678 + if (!pool)
679 + return xmalloc(size);
680 + return mem_pool_alloc(pool, size);
681 +}
682 +
683 +MAYBE_UNUSED
684 +static void *pool_strndup(struct mem_pool *pool, const char *str, size_t len)
685 +{
686 + if (!pool)
687 + return xstrndup(str, len);
688 + return mem_pool_strndup(pool, str, len);
689 +}
690 +
691 /* add a string to a strbuf, but converting "/" to "_" */
692 static void add_flattened_path(struct strbuf *out, const char *s)
693 {