Line Flow Count Block(s) Source
1 - /*
2 - * Copyright (C) the libgit2 contributors. All rights reserved.
3 - *
4 - * This file is part of libgit2, distributed under the GNU GPL v2 with
5 - * a Linking Exception. For full terms see the included COPYING file.
6 - */
7 -
8 - #include "alloc.h"
9 -
10 - #include "allocators/stdalloc.h"
11 - #include "allocators/win32_crtdbg.h"
12 -
13 - git_allocator git__allocator;
14 -
15 10 2 static int setup_default_allocator(void)
16 - {
17 - #if defined(GIT_MSVC_CRTDBG)
18 - return git_win32_crtdbg_init_allocator(&git__allocator);
19 - #else
20 10 2 return git_stdalloc_init_allocator(&git__allocator);
21 - #endif
22 - }
23 -
24 9 2 int git_allocator_global_init(void)
25 - {
26 - /*
27 - * We don't want to overwrite any allocator which has been set before
28 - * the init function is called.
29 - */
30 9 2 if (git__allocator.gmalloc != NULL)
31 1 3 return 0;
32 -
33 8 4 return setup_default_allocator();
34 - }
35 -
36 4 2 int git_allocator_setup(git_allocator *allocator)
37 - {
38 4 2 if (!allocator)
39 2 3 return setup_default_allocator();
40 -
41 2 4 memcpy(&git__allocator, allocator, sizeof(*allocator));
42 2 4 return 0;
43 - }