summaryrefslogtreecommitdiff
path: root/src/global.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2018-03-20 14:23:49 +0000
committerPatrick Steinhardt <ps@pks.im>2018-06-07 12:57:39 +0200
commit9865cd1696ac4a3f47991a9a1d79b17cef5edc89 (patch)
treee1ee4f20bceb1a8c5f98aceb41d98dcec3a3f3d1 /src/global.c
parent08b318c0645b27393a70c2289a65b949ea4b45ed (diff)
downloadlibgit2-9865cd1696ac4a3f47991a9a1d79b17cef5edc89.tar.gz
alloc: make memory allocators use function pointers
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.
Diffstat (limited to 'src/global.c')
-rw-r--r--src/global.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/global.c b/src/global.c
index 53e660904..d33772e91 100644
--- a/src/global.c
+++ b/src/global.c
@@ -7,6 +7,7 @@
#include "global.h"
+#include "alloc.h"
#include "hash.h"
#include "sysdir.h"
#include "filter.h"
@@ -60,7 +61,8 @@ static int init_common(void)
#endif
/* Initialize any other subsystems that have global state */
- if ((ret = git_hash_global_init()) == 0 &&
+ if ((ret = git_allocator_global_init()) == 0 &&
+ (ret = git_hash_global_init()) == 0 &&
(ret = git_sysdir_global_init()) == 0 &&
(ret = git_filter_global_init()) == 0 &&
(ret = git_merge_driver_global_init()) == 0 &&