File tree Expand file tree Collapse file tree 4 files changed +45
-0
lines changed
Expand file tree Collapse file tree 4 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -183,6 +183,7 @@ typedef enum {
183183 GIT_OPT_GET_WINDOWS_SHAREMODE ,
184184 GIT_OPT_SET_WINDOWS_SHAREMODE ,
185185 GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION ,
186+ GIT_OPT_SET_ALLOCATOR
186187} git_libgit2_opt_t ;
187188
188189/**
@@ -345,6 +346,12 @@ typedef enum {
345346 * > additional checksum calculation on each object. This defaults
346347 * > to enabled.
347348 *
349+ * opts(GIT_OPT_SET_ALLOCATOR, git_allocator *allocator)
350+ *
351+ * > Set the memory allocator to a different memory allocator. This
352+ * > allocator will then be used to make all memory allocations for
353+ * > libgit2 operations.
354+ *
348355 * @param option Option key
349356 * @param ... value to set the option
350357 * @return 0 on success, <0 on failure
Original file line number Diff line number Diff line change @@ -72,6 +72,30 @@ typedef struct {
7272 void (* gfree )(void * ptr );
7373} git_allocator ;
7474
75+ /**
76+ * Initialize the allocator structure to use the `stdalloc` pointer.
77+ *
78+ * Set up the structure so that all of its members are using the standard
79+ * "stdalloc" allocator functions. The structure can then be used with
80+ * `git_allocator_setup`.
81+ *
82+ * @param allocator The allocator that is to be initialized.
83+ * @return An error code or 0.
84+ */
85+ int git_stdalloc_init_allocator (git_allocator * allocator );
86+
87+ /**
88+ * Initialize the allocator structure to use the `crtdbg` pointer.
89+ *
90+ * Set up the structure so that all of its members are using the "crtdbg"
91+ * allocator functions. Note that this allocator is only available on Windows
92+ * platforms and only if libgit2 is being compiled with "-DMSVC_CRTDBG".
93+ *
94+ * @param allocator The allocator that is to be initialized.
95+ * @return An error code or 0.
96+ */
97+ int git_win32_crtdbg_init_allocator (git_allocator * allocator );
98+
7599GIT_END_DECL
76100
77101#endif
Original file line number Diff line number Diff line change @@ -29,3 +29,12 @@ int git_allocator_setup(git_allocator *allocator)
2929 memcpy (& git__allocator , allocator , sizeof (* allocator ));
3030 return 0 ;
3131}
32+
33+ #if !defined(GIT_MSVC_CRTDBG )
34+ int git_win32_crtdbg_init_allocator (git_allocator * allocator )
35+ {
36+ GIT_UNUSED (allocator );
37+ giterr_set (GIT_EINVALID , "crtdbg memory allocator not available" );
38+ return -1 ;
39+ }
40+ #endif
Original file line number Diff line number Diff line change 1616#endif
1717
1818#include <git2.h>
19+ #include "alloc.h"
1920#include "sysdir.h"
2021#include "cache.h"
2122#include "global.h"
@@ -260,6 +261,10 @@ int git_libgit2_opts(int key, ...)
260261 git_odb__strict_hash_verification = (va_arg (ap , int ) != 0 );
261262 break ;
262263
264+ case GIT_OPT_SET_ALLOCATOR :
265+ error = git_allocator_setup (va_arg (ap , git_allocator * ));
266+ break ;
267+
263268 default :
264269 giterr_set (GITERR_INVALID , "invalid option key" );
265270 error = -1 ;
You can’t perform that action at this time.
0 commit comments