summaryrefslogtreecommitdiff
path: root/src/alloc.c
Commit message (Collapse)AuthorAgeFilesLines
* alloc: set up an allocator that fails before library initEdward Thomson2020-12-091-4/+16
| | | | | | | | | | | | | | | | | | | We require the library to be initialized with git_libgit2_init before it is functional. However, if a user tries to uses the library without doing so - as they might when getting started with the library for the first time - we will likely crash. This commit introduces some guard rails - now instead of having _no_ allocator by default, we'll have an allocator that always fails, and never tries to set an error message (since the thread-local state is set up by git_libgit2_init). We've modified the error retrieval function to (try to) ensure that the library has been initialized before getting the thread-local error message. (Unfortunately, we cannot determine if the thread local storage has actually been configured, this does require initialization by git_libgit2_init. But a naive attempt should be good enough for most cases.)
* cmake: rename MSVC_CRTDBG to WIN32_LEAKCHECKEdward Thomson2020-11-211-1/+1
|
* alloc: rename the win32 leakcheck allocatorEdward Thomson2020-11-211-2/+2
| | | | | The win32 leakchecking system is now named win32_leakcheck. Update the allocator to match.
* win32: consolidate leak checking initializationEdward Thomson2020-11-211-20/+0
| | | | | Move leak check initialization into git_win32_leakcheck_global_init, and call it on library initialization.
* win32: "crtdbg" is now "leakcheck"Edward Thomson2020-11-211-6/+5
| | | | | msvc crtdbg is a mouthfull that is not particularly indicative of what it does. Let's rename it to "win32 leakcheck".
* runtime: move init/shutdown into the "runtime"Edward Thomson2020-10-111-1/+3
| | | | | Provide a mechanism for system components to register for initialization and shutdown of the libgit2 runtime.
* win32: teach the allocator to deal with crtdbgEdward Thomson2020-10-111-0/+20
| | | | | Move the MSVC C runtime debugging bits into the allocator's global init function.
* allocators: extract crtdbg allocator into its own filePatrick Steinhardt2019-02-211-14/+2
| | | | | | | | | | | | | | | The Windows-specific crtdbg allocator is currently mixed into the crtdbg stacktracing compilation unit, making it harder to find than necessary. Extract it and move it into the new "allocators/" subdirectory to improve discoverability. This change means that the crtdbg compilation unit is now compiled unconditionally, whereas it has previously only been compiled on Windows platforms. Thus we now have additional guards around the code so that it will only be compiled if GIT_MSVC_CRTDBG is defined. This also allows us to move over the fallback-implementation of `git_win32_crtdbg_init_allocator` into the same compilation unit.
* allocators: move standard allocator into subdirectoryPatrick Steinhardt2019-02-211-1/+1
| | | | | | | Right now, our two allocator implementations are scattered around the tree in "stdalloc.h" and "win32/w32_crtdbg_stacktrace.h". Start grouping them together in a single directory "allocators/", similar to how e.g. our streams are organized.
* git_error: use new names in internal APIs and usageEdward Thomson2019-01-221-1/+1
| | | | | Move to the `git_error` name in the internal API for error-related functions.
* util: allow callers to reset custom allocatorsEdward Thomson2018-10-211-5/+13
| | | | | Provide a utility to reset custom allocators back to their default. This is particularly useful for testing.
* alloc: don't overwrite allocator during init if setcmn/allocator-init-orderCarlos Martín Nieto2018-07-151-0/+7
| | | | | If the allocator has been set before we the library is initialised, we would replace that setting with the standard allocator contrary to the user's wishes.
* settings: allow swapping out memory allocatorPatrick Steinhardt2018-06-071-0/+9
| | | | | | | Tie in the newly created infrastructure for swapping out memory allocators into our settings code. A user can now simply use the new option "GIT_OPT_SET_ALLOCATOR" with `git_libgit2_opts`, passing in an already initialized allocator structure as vararg.
* alloc: make memory allocators use function pointersPatrick Steinhardt2018-06-071-0/+31
Currently, our memory allocators are being redirected to the correct implementation at compile time by simply using macros. In order to make them swappable at runtime, this commit reshuffles that by instead making use of a global "git_allocator" structure, whose pointers are set up to reference the allocator functions. Like this, it becomes easy to swap out allocators by simply setting these function pointers. In order to initialize a "git_allocator", our provided allocators "stdalloc" and "crtdbg" both provide an init function. This is being called to initialize a passed in allocator struct and set up its members correctly. No support is yet included to enable users of libgit2 to switch out the memory allocator at a global level.