From: Phillip Wood <phillip.wood123@gmail.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
"Edward Thomson" <ethomson@edwardthomson.com>
Cc: git@vger.kernel.org, johannes.schindelin@gmx.de
Subject: Re: [PATCH 1/1] xdiff: provide indirection to git functions
Date: Wed, 16 Feb 2022 11:02:33 +0000 [thread overview]
Message-ID: <7e6385f8-f25d-69f5-edae-6f5d6f785046@gmail.com> (raw)
In-Reply-To: <220216.86wnhvvgeh.gmgdl@evledraar.gmail.com>
On 15/02/2022 23:40, Ævar Arnfjörð Bjarmason wrote:
>
> On Wed, Feb 09 2022, Edward Thomson wrote:
>
>> Provide an indirection layer into the git-specific functionality and
>> utilities in `git-xdiff.h`, prefixing those types and functions with
>> `xdl_` (and `XDL_` for macros). This allows other projects that use
>> git's xdiff implementation to keep up-to-date; they can now take all the
>> files _except_ `git-xdiff.h`, which they have customized for their own
>> environment.
>
> It seems sensible to share code here, but...
>
>> +#ifndef GIT_XDIFF_H
>> +#define GIT_XDIFF_H
>> +
>> +#define xdl_malloc(x) xmalloc(x)
>> +#define xdl_free(ptr) free(ptr)
>> +#define xdl_realloc(ptr,x) xrealloc(ptr,x)
>
> ...I don't understand the need for prefixing every function that may be
> used from git.git with xdl_*. In particular for these memory managing
> functions shouldn't this Just Work per 8d128513429 (grep/pcre2: actually
> make pcre2 use custom allocator, 2021-02-18) and cbe81e653fa
> (grep/pcre2: move back to thread-only PCREv2 structures, 2021-02-18)?
> I.e. link-time use of free().
I read that paragraph a couple of times and I'm still not sure I
understand what you're saying. It is not unusual for libraries to define
their own allocation functions and the code base is already using
xdl_malloc etc so these defines seem quite reasonable. As you point out
below we'd need wrappers for xmalloc() etc anyway so I'm not sure what
the problem is.
> Of course trivial wrappers would be needed for x*() variants...
>
>> +#define xdl_regex_t regex_t
>
> This is a type that's in POSIX. Why do we need an xdl_* prefix for it?
>
>> +#define xdl_regmatch_t regmatch_t
>
> ditto.
>
>> +#define xdl_regexec_buf(p, b, s, n, m, f) regexec_buf(p, b, s, n, m, f)
>
> But this is our own custom function, which brings me to...
>
>> +#define XDL_BUG(msg) BUG(msg)
>
> ...unless libgit2 has a regexec_buf() or BUG() why do we need this
> indirection? Let's just have xdiff() use a bug, and then either libgit2
> will have a BUG() macro/function, or it'll fail at compile-time.
>
> This seems to at least partly have been inspired by git.git's
> 546096a5cbb (xdiff: use BUG(...), not xdl_bug(...), 2021-06-07), i.e. we
> used to have an xdl_bug(), but now we just use BUG().
>
> I then see on your libgit2 side 1458fb56e (xdiff: include new xdiff from
> git, 2022-01-29).
>
> But why not simply?:
>
> #define BUG(msg) GIT_ASSERT(msg)
>
> It would make things easier on the git.git side (etags and all).
If we want xdiff to be usable for other projects I think we're going to
have to accept that it is sensible to namespace its functions.
Best Wishes
Phillip
next prev parent reply other threads:[~2022-02-16 11:02 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-09 1:29 [PATCH 0/1] xdiff: share xdiff between git and libgit2 Edward Thomson
2022-02-09 1:33 ` [PATCH 1/1] xdiff: provide indirection to git functions Edward Thomson
2022-02-09 11:07 ` Phillip Wood
2022-02-15 23:40 ` Ævar Arnfjörð Bjarmason
2022-02-16 11:02 ` Phillip Wood [this message]
2022-02-16 13:27 ` Ævar Arnfjörð Bjarmason
[not found] ` <20220217012847.GA8@e5e602f6ad40>
2022-02-17 9:29 ` Ævar Arnfjörð Bjarmason
2022-02-17 17:32 ` Junio C Hamano
2022-02-17 22:58 ` Edward Thomson
2022-04-15 15:55 ` Ævar Arnfjörð Bjarmason
2022-02-17 15:44 ` [PATCH 0/1] xdiff: share xdiff between git and libgit2 Johannes Schindelin
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=7e6385f8-f25d-69f5-edae-6f5d6f785046@gmail.com \
--to=phillip.wood123@gmail.com \
--cc=avarab@gmail.com \
--cc=ethomson@edwardthomson.com \
--cc=git@vger.kernel.org \
--cc=johannes.schindelin@gmx.de \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).