All of lore.kernel.org
 help / color / mirror / Atom feed
From: Phillip Wood <phillip.wood123@gmail.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>, git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>, Jeff King <peff@peff.net>
Subject: Re: [PATCH 7/7] xdiff: remove xdl_free(), use free() instead
Date: Fri, 8 Jul 2022 18:51:43 +0100	[thread overview]
Message-ID: <6b8fc0e8-c446-1275-12f3-e6520de9584d@gmail.com> (raw)
In-Reply-To: <patch-7.7-a1bf9a94f0a-20220708T140354Z-avarab@gmail.com>

Hi Ævar

On 08/07/2022 15:20, Ævar Arnfjörð Bjarmason wrote:
> Remove the xdl_free() wrapper macro in favor of using free()
> directly. The wrapper macro was brought in with the initial import of
> xdiff/ in 3443546f6ef (Use a *real* built-in diff generator,
> 2006-03-24).
> 
> As subsequent discussions on the topic[1] have made clear there's no
> reason to use this wrapper.

That link is to a message where you assert that there is no reason for 
the wrapper, you seem to be the only person in that thread making that 
argument. The libgit2 maintainer and others are arguing that it is worth 
keeping to make it easy to swap the allocator.

> Both git itself as well as any external
> users such as libgit2 compile the xdiff/* code as part of their own
> compilation, and can thus find the right malloc() and free() at
> link-time.

I'm struggling to see how that is simpler than the current situation 
with xdl_malloc(). Perhaps you could show how you think libgit2 could 
easily make xdiff use git__malloc() instead of malloc() without changing 
the malloc() calls (the message you linked to essentially suggests they 
do a search and replace). If people cannot swap in another allocator 
without changing the code then you are imposing a barrier to them 
contributing patches back to git's xdiff.

Best Wishes

Phillip

> When compiling git we already find a custom malloc() and free()
> e.g. if compiled with USE_NED_ALLOCATOR=YesPlease.
> 
> 1. https://lore.kernel.org/git/220415.867d7qbaad.gmgdl@evledraar.gmail.com/
> 
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>   xdiff/xdiff.h      |  3 ---
>   xdiff/xdiffi.c     |  4 ++--
>   xdiff/xhistogram.c |  6 +++---
>   xdiff/xpatience.c  |  8 ++++----
>   xdiff/xprepare.c   | 28 ++++++++++++++--------------
>   xdiff/xutils.c     |  2 +-
>   6 files changed, 24 insertions(+), 27 deletions(-)
> 
> diff --git a/xdiff/xdiff.h b/xdiff/xdiff.h
> index df048e0099b..a37d89fcdaf 100644
> --- a/xdiff/xdiff.h
> +++ b/xdiff/xdiff.h
> @@ -118,9 +118,6 @@ typedef struct s_bdiffparam {
>   	long bsize;
>   } bdiffparam_t;
>   
> -
> -#define xdl_free(ptr) free(ptr)
> -
>   void *xdl_mmfile_first(mmfile_t *mmf, long *size);
>   long xdl_mmfile_size(mmfile_t *mmf);
>   
> diff --git a/xdiff/xdiffi.c b/xdiff/xdiffi.c
> index 6590811634f..375bb81a8aa 100644
> --- a/xdiff/xdiffi.c
> +++ b/xdiff/xdiffi.c
> @@ -359,7 +359,7 @@ int xdl_do_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
>   	res = xdl_recs_cmp(&dd1, 0, dd1.nrec, &dd2, 0, dd2.nrec,
>   			   kvdf, kvdb, (xpp->flags & XDF_NEED_MINIMAL) != 0,
>   			   &xenv);
> -	xdl_free(kvd);
> +	free(kvd);
>   
>   	return res;
>   }
> @@ -960,7 +960,7 @@ void xdl_free_script(xdchange_t *xscr) {
>   
>   	while ((xch = xscr) != NULL) {
>   		xscr = xscr->next;
> -		xdl_free(xch);
> +		free(xch);
>   	}
>   }
>   
> diff --git a/xdiff/xhistogram.c b/xdiff/xhistogram.c
> index f20592bfbdd..be35d9c9697 100644
> --- a/xdiff/xhistogram.c
> +++ b/xdiff/xhistogram.c
> @@ -240,9 +240,9 @@ static int fall_back_to_classic_diff(xpparam_t const *xpp, xdfenv_t *env,
>   
>   static inline void free_index(struct histindex *index)
>   {
> -	xdl_free(index->records);
> -	xdl_free(index->line_map);
> -	xdl_free(index->next_ptrs);
> +	free(index->records);
> +	free(index->line_map);
> +	free(index->next_ptrs);
>   	xdl_cha_free(&index->rcha);
>   }
>   
> diff --git a/xdiff/xpatience.c b/xdiff/xpatience.c
> index bb328d9f852..8fffd2b8297 100644
> --- a/xdiff/xpatience.c
> +++ b/xdiff/xpatience.c
> @@ -233,7 +233,7 @@ static int find_longest_common_sequence(struct hashmap *map, struct entry **res)
>   	/* No common unique lines were found */
>   	if (!longest) {
>   		*res = NULL;
> -		xdl_free(sequence);
> +		free(sequence);
>   		return 0;
>   	}
>   
> @@ -245,7 +245,7 @@ static int find_longest_common_sequence(struct hashmap *map, struct entry **res)
>   		entry = entry->previous;
>   	}
>   	*res = entry;
> -	xdl_free(sequence);
> +	free(sequence);
>   	return 0;
>   }
>   
> @@ -358,7 +358,7 @@ static int patience_diff(mmfile_t *file1, mmfile_t *file2,
>   			env->xdf1.rchg[line1++ - 1] = 1;
>   		while(count2--)
>   			env->xdf2.rchg[line2++ - 1] = 1;
> -		xdl_free(map.entries);
> +		free(map.entries);
>   		return 0;
>   	}
>   
> @@ -372,7 +372,7 @@ static int patience_diff(mmfile_t *file1, mmfile_t *file2,
>   		result = fall_back_to_classic_diff(&map,
>   			line1, count1, line2, count2);
>    out:
> -	xdl_free(map.entries);
> +	free(map.entries);
>   	return result;
>   }
>   
> diff --git a/xdiff/xprepare.c b/xdiff/xprepare.c
> index 4182d9e1c0a..169629761c0 100644
> --- a/xdiff/xprepare.c
> +++ b/xdiff/xprepare.c
> @@ -89,7 +89,7 @@ static int xdl_init_classifier(xdlclassifier_t *cf, long size, long flags) {
>   
>   	GALLOC_ARRAY(cf->rcrecs, cf->alloc);
>   	if (!cf->rcrecs) {
> -		xdl_free(cf->rchash);
> +		free(cf->rchash);
>   		xdl_cha_free(&cf->ncha);
>   		return -1;
>   	}
> @@ -102,8 +102,8 @@ static int xdl_init_classifier(xdlclassifier_t *cf, long size, long flags) {
>   
>   static void xdl_free_classifier(xdlclassifier_t *cf) {
>   
> -	xdl_free(cf->rcrecs);
> -	xdl_free(cf->rchash);
> +	free(cf->rcrecs);
> +	free(cf->rchash);
>   	xdl_cha_free(&cf->ncha);
>   }
>   
> @@ -230,11 +230,11 @@ static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_
>   	return 0;
>   
>   abort:
> -	xdl_free(ha);
> -	xdl_free(rindex);
> -	xdl_free(rchg);
> -	xdl_free(rhash);
> -	xdl_free(recs);
> +	free(ha);
> +	free(rindex);
> +	free(rchg);
> +	free(rhash);
> +	free(recs);
>   	xdl_cha_free(&xdf->rcha);
>   	return -1;
>   }
> @@ -242,11 +242,11 @@ static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_
>   
>   static void xdl_free_ctx(xdfile_t *xdf) {
>   
> -	xdl_free(xdf->rhash);
> -	xdl_free(xdf->rindex);
> -	xdl_free(xdf->rchg - 1);
> -	xdl_free(xdf->ha);
> -	xdl_free(xdf->recs);
> +	free(xdf->rhash);
> +	free(xdf->rindex);
> +	free(xdf->rchg - 1);
> +	free(xdf->ha);
> +	free(xdf->recs);
>   	xdl_cha_free(&xdf->rcha);
>   }
>   
> @@ -424,7 +424,7 @@ static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xd
>   	}
>   	xdf2->nreff = nreff;
>   
> -	xdl_free(dis);
> +	free(dis);
>   
>   	return 0;
>   }
> diff --git a/xdiff/xutils.c b/xdiff/xutils.c
> index 865e08f0e93..00eeba452a5 100644
> --- a/xdiff/xutils.c
> +++ b/xdiff/xutils.c
> @@ -88,7 +88,7 @@ void xdl_cha_free(chastore_t *cha) {
>   
>   	for (cur = cha->head; (tmp = cur) != NULL;) {
>   		cur = cur->next;
> -		xdl_free(tmp);
> +		free(tmp);
>   	}
>   }
>   


  reply	other threads:[~2022-07-08 17:51 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-29 15:25 [PATCH 0/3] xdiff: introduce memory allocation macros Phillip Wood via GitGitGadget
2022-06-29 15:25 ` [PATCH 1/3] xdiff: introduce XDL_ALLOC_ARRAY() Phillip Wood via GitGitGadget
2022-06-29 15:25 ` [PATCH 2/3] xdiff: introduce XDL_CALLOC_ARRAY() Phillip Wood via GitGitGadget
2022-06-30 18:17   ` Junio C Hamano
2022-07-06 13:17     ` Phillip Wood
2022-06-29 15:25 ` [PATCH 3/3] xdiff: introduce XDL_ALLOC_GROW() Phillip Wood via GitGitGadget
2022-06-30 10:54   ` Ævar Arnfjörð Bjarmason
2022-06-30 12:03     ` Phillip Wood
2022-06-30 12:38       ` Phillip Wood
2022-06-30 13:25         ` Ævar Arnfjörð Bjarmason
2022-07-06 13:23           ` Phillip Wood
2022-07-07 11:17             ` Ævar Arnfjörð Bjarmason
2022-07-08  9:35               ` Phillip Wood
2022-07-08 14:20                 ` [PATCH 0/7] xdiff: use standard alloc macros, share them via git-shared-util.h Ævar Arnfjörð Bjarmason
2022-07-08 14:20                   ` [PATCH 1/7] xdiff: simplify freeing patterns around xdl_free_env() Ævar Arnfjörð Bjarmason
2022-07-08 14:20                   ` [PATCH 2/7] git-shared-util.h: move "shared" allocation utilities here Ævar Arnfjörð Bjarmason
2022-07-08 14:20                   ` [PATCH 3/7] git-shared-util.h: add G*() versions of *ALLOC_*() Ævar Arnfjörð Bjarmason
2022-07-11 10:06                     ` Phillip Wood
2022-07-08 14:20                   ` [PATCH 4/7] xdiff: use G[C]ALLOC_ARRAY(), not XDL_CALLOC_ARRAY() Ævar Arnfjörð Bjarmason
2022-07-11 10:10                     ` Phillip Wood
2022-07-08 14:20                   ` [PATCH 5/7] xdiff: use GALLOC_GROW(), not XDL_ALLOC_GROW() Ævar Arnfjörð Bjarmason
2022-07-11 10:13                     ` Phillip Wood
2022-07-11 10:48                       ` Ævar Arnfjörð Bjarmason
2022-07-13  9:09                         ` Phillip Wood
2022-07-13 10:48                           ` Ævar Arnfjörð Bjarmason
2022-07-13 13:21                             ` Phillip Wood
2022-07-08 14:20                   ` [PATCH 6/7] xdiff: remove xdl_malloc() wrapper, use malloc(), not xmalloc() Ævar Arnfjörð Bjarmason
2022-07-08 17:42                     ` Phillip Wood
2022-07-08 21:44                       ` Ævar Arnfjörð Bjarmason
2022-07-08 19:35                     ` Jeff King
2022-07-08 21:47                       ` Ævar Arnfjörð Bjarmason
2022-07-11  9:33                         ` Jeff King
2022-07-08 14:20                   ` [PATCH 7/7] xdiff: remove xdl_free(), use free() instead Ævar Arnfjörð Bjarmason
2022-07-08 17:51                     ` Phillip Wood [this message]
2022-07-08 21:26                       ` Ævar Arnfjörð Bjarmason
2022-07-11  9:26                         ` Phillip Wood
2022-07-11  9:54                           ` Phillip Wood
2022-07-11 10:02                           ` Ævar Arnfjörð Bjarmason
2022-07-13 13:00                             ` Phillip Wood
2022-07-13 13:18                               ` Ævar Arnfjörð Bjarmason
2022-06-30 18:32   ` [PATCH 3/3] xdiff: introduce XDL_ALLOC_GROW() Junio C Hamano
2022-07-06 13:14     ` Phillip Wood
2022-06-30 10:46 ` [PATCH 0/3] xdiff: introduce memory allocation macros Ævar Arnfjörð Bjarmason
2022-07-08 16:25 ` [PATCH v2 0/4] " Phillip Wood via GitGitGadget
2022-07-08 16:25   ` [PATCH v2 1/4] xdiff: introduce XDL_ALLOC_ARRAY() Phillip Wood via GitGitGadget
2022-07-08 16:25   ` [PATCH v2 2/4] xdiff: introduce xdl_calloc Phillip Wood via GitGitGadget
2022-07-08 16:25   ` [PATCH v2 3/4] xdiff: introduce XDL_CALLOC_ARRAY() Phillip Wood via GitGitGadget
2022-07-08 16:25   ` [PATCH v2 4/4] xdiff: introduce XDL_ALLOC_GROW() Phillip Wood via GitGitGadget
2022-07-08 22:17     ` Ævar Arnfjörð Bjarmason
2022-07-11 10:00       ` Phillip Wood
2022-07-12  7:19         ` Jeff King
2022-07-13  9:38           ` Phillip Wood

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6b8fc0e8-c446-1275-12f3-e6520de9584d@gmail.com \
    --to=phillip.wood123@gmail.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    --cc=phillip.wood@dunelm.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.