Re: [PATCH 3/7] merge-ort: add pool_alloc, pool_calloc, and pool_strndup wrappers
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Jul 23, 2021, 22:07 UTC
- Message-ID
- <CAPig+cQD28hPV30B2Oih=LUDmJGWKTFXmZGE65YYhqAeH0FVvQ@mail.gmail.com>
- In-Reply-To
- <e30b8c8fea110b2475d00a4b37eb62a4883999c4.1627044897.git.gitgitgadget@gmail.com>
On Fri, Jul 23, 2021 at 8:55 AM Elijah Newren via GitGitGadget <gitgitgadget@gmail.com> wrote:
Show 8 quoted lines
> We need 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. Add these > functions; the next commit will make use of these. > > Signed-off-by: Elijah Newren <newren@gmail.com>
Patch [2/7] feels somewhat incomplete without the utility functions introduced by this patch (and, indeed, when reading [2/7], I was wondering how you were going to deal with the potential NULL pointer). From a review standpoint, I could easily see [2/7] and [3/7] presented as a single patch, but it's not worth a re-roll.
Show 26 quoted lines
> diff --git a/merge-ort.c b/merge-ort.c
> @@ -683,6 +683,30 @@ static void path_msg(struct merge_options *opt,
> +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);
> +}
> +