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 {
183
183
GIT_OPT_GET_WINDOWS_SHAREMODE ,
184
184
GIT_OPT_SET_WINDOWS_SHAREMODE ,
185
185
GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION ,
186
+ GIT_OPT_SET_ALLOCATOR
186
187
} git_libgit2_opt_t ;
187
188
188
189
/**
@@ -345,6 +346,12 @@ typedef enum {
345
346
* > additional checksum calculation on each object. This defaults
346
347
* > to enabled.
347
348
*
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
+ *
348
355
* @param option Option key
349
356
* @param ... value to set the option
350
357
* @return 0 on success, <0 on failure
Original file line number Diff line number Diff line change @@ -72,6 +72,30 @@ typedef struct {
72
72
void (* gfree )(void * ptr );
73
73
} git_allocator ;
74
74
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
+
75
99
GIT_END_DECL
76
100
77
101
#endif
Original file line number Diff line number Diff line change @@ -29,3 +29,12 @@ int git_allocator_setup(git_allocator *allocator)
29
29
memcpy (& git__allocator , allocator , sizeof (* allocator ));
30
30
return 0 ;
31
31
}
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 16
16
#endif
17
17
18
18
#include <git2.h>
19
+ #include "alloc.h"
19
20
#include "sysdir.h"
20
21
#include "cache.h"
21
22
#include "global.h"
@@ -260,6 +261,10 @@ int git_libgit2_opts(int key, ...)
260
261
git_odb__strict_hash_verification = (va_arg (ap , int ) != 0 );
261
262
break ;
262
263
264
+ case GIT_OPT_SET_ALLOCATOR :
265
+ error = git_allocator_setup (va_arg (ap , git_allocator * ));
266
+ break ;
267
+
263
268
default :
264
269
giterr_set (GITERR_INVALID , "invalid option key" );
265
270
error = -1 ;
You can’t perform that action at this time.
0 commit comments