Thread (214 messages) 214 messages, 14 authors, 2021-05-18

Re: [PATCH v2 05/13] reftable: utility functions

From: Johannes Schindelin <hidden>
Date: 2020-10-13 14:19:55

Hi Patrick,

On Mon, 12 Oct 2020, Patrick Steinhardt wrote:
On Mon, Oct 12, 2020 at 08:25:05AM -0700, Jonathan Nieder wrote:
quoted
(+cc: Patrick Steinhardt from libgit2)
Hi,

Han-Wen Nienhuys wrote[1]:
quoted
On Fri, Oct 2, 2020 at 6:12 AM Jonathan Nieder [off-list ref] wrote:
quoted
Han-Wen Nienhuys wrote:
quoted
quoted
quoted
+     reftable_free(a);
+}
Are there other callers that need custom free?
The libgit2 folks requested the ability to set memory allocation
routines, hence reftable_free().
Thanks.  Patrick or Han-Wen, can you say a little more about this use
case?  That would help with making sure we are making an API that
meets its needs.

For example, is a custom allocator something that would be set
globally or something attached to a handle?  If the former, would code
that uses xmalloc and free and gets #define-d away when used in
libgit2 work?  If the latter, what does the handle look like?
We have global pluggable allocators in libgit2 which can be set up
before calling `git_libgit2_init()`. The user of libgit2 can fill a
`git_allocator` structure with a set of funtcion pointers, most
importantly with implementations of `free` and `malloc`. Those then get
used across all of libgit2 for all subsequent allocations.
I did not find out how those are used in the `deps/` part of libgit2's
source code. For example, I see a couple of instances where `malloc()` is
used in `ntlmclient` and in `pcre`.

The thing I was looking for would have been something like

	#define malloc(size) git__malloc(size)
	...

This would also have been what I imagined to be the best strategy to
integrate the reftable code once it is properly embedded in libgit.a (and
of course using libgit.a's API as much as it can).

Somewhat related: I was wondering whether it would make sense for git.git
to rename `strbuf` to `git_buf`? Would that make it easier to exchange
code between the two projects? Or would it just be unnecessary churn?

Ciao,
Dscho
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help