Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose a malloc function to 3rd party ODB backends #900

Merged
merged 1 commit into from Sep 6, 2012
Merged

Expose a malloc function to 3rd party ODB backends #900

merged 1 commit into from Sep 6, 2012

Conversation

pwkelley
Copy link

The ODB backend interface has functions in it for doing reads. These functions allocate buffers and return them (and ownership of them) to the caller. It is expected right now that the ODB backend allocates these buffers using git__malloc. Since this function is not exported, it's not possible to write a third-party ODB backend for libgit2. All backends must be in the git2 library so that they can call git__malloc.

This change asks that backends use a new exported function called git_odb_backend_malloc to allocate buffers that will change ownership from the backend to libgit2. The fact that this entry point just redirects to git__malloc right now is an implementation detail.

This implementation detail means that the existing backends don't have to be switched over to using git_odb_backend_malloc (although they could be). It also means that the caller (who takes ownership of the buffer) can still assume that git__free is the function to be used to free any buffer that comes back from an ODB backend.

The implementation could be changed to have a separate heap for git_odb_backend_malloc allocations. Doing so would mean that libgit2 would need to keep track of the free function for each buffer so that it can call the right function at free time.

This implementation detail does expose git__malloc to any outside caller. But anyone using it for a purpose other than allocating a buffer to return from read/read_prefix in libgit2 is in violation of the contract and subject to being broken by the implementation details described above changing.

There are certainly other ways to do this. If this isn't what the team feels like is the best approach then I would be happy to revisit it.

Thanks,
Philip
Microsoft Corporation

@travisbot
Copy link

This pull request passes (merged c49d328 into 2b175ca).

@ben
Copy link
Member

ben commented Aug 27, 2012

I like it. 👍 Thanks, @phkelley!

@vmg
Copy link
Member

vmg commented Sep 6, 2012

Drumroll... Is this Microsoft's first PR being merged into libgit2? Omigash.

Sooo looking forward to more.

vmg pushed a commit that referenced this pull request Sep 6, 2012
Expose a malloc function to 3rd party ODB backends
@vmg vmg merged commit 7a3fc9f into libgit2:development Sep 6, 2012
phatblat pushed a commit to phatblat/libgit2 that referenced this pull request Sep 13, 2014
Expose a malloc function to 3rd party ODB backends
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants