summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElijah Newren <newren@gmail.com>2021-07-30 11:47:38 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-07-30 16:01:18 (GMT)
commitcdf2241c717b05845ff9e25b87be6ca7559e82eb (patch)
tree21ecd672592db9cd230f74926370201e0c637efb
parentfa0e936fbb683dbce70b797ae8a5be6b88f48d88 (diff)
downloadgit-cdf2241c717b05845ff9e25b87be6ca7559e82eb.zip
git-cdf2241c717b05845ff9e25b87be6ca7559e82eb.tar.gz
git-cdf2241c717b05845ff9e25b87be6ca7559e82eb.tar.bz2
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>
-rw-r--r--merge-ort.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/merge-ort.c b/merge-ort.c
index 401a402..63f6724 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -664,6 +664,30 @@ static void path_msg(struct merge_options *opt,
strbuf_addch(sb, '\n');
}
+MAYBE_UNUSED
+static void *pool_calloc(struct mem_pool *pool, size_t count, size_t size)
+{
+ if (!pool)
+ return xcalloc(count, size);
+ return mem_pool_calloc(pool, count, size);
+}
+
+MAYBE_UNUSED
+static void *pool_alloc(struct mem_pool *pool, size_t size)
+{
+ if (!pool)
+ return xmalloc(size);
+ return mem_pool_alloc(pool, size);
+}
+
+MAYBE_UNUSED
+static void *pool_strndup(struct mem_pool *pool, const char *str, size_t len)
+{
+ if (!pool)
+ return xstrndup(str, len);
+ return mem_pool_strndup(pool, str, len);
+}
+
/* add a string to a strbuf, but converting "/" to "_" */
static void add_flattened_path(struct strbuf *out, const char *s)
{