|
21 | 21 | #include "mimalloc.h" // mi_malloc/mi_calloc/mi_realloc/mi_free/mi_usable_size — bind 3rd-party allocators (#424) |
22 | 22 | #if defined(CBM_BIND_TS_ALLOCATOR) && CBM_BIND_TS_ALLOCATOR |
23 | 23 | #include "sqlite3.h" // sqlite3_mem_methods, sqlite3_config, SQLITE_CONFIG_MALLOC — bind sqlite to mimalloc |
24 | | -#if defined(HAVE_LIBGIT2) |
25 | | -#include <git2/version.h> |
26 | | -#if defined(LIBGIT2_VERSION_CHECK) |
27 | | -#if !LIBGIT2_VERSION_CHECK(1, 7, 0) |
28 | | -#error "HAVE_LIBGIT2 requires libgit2 >= 1.7.0 for git_allocator" |
29 | | -#endif |
30 | | -#elif defined(LIBGIT2_VER_MAJOR) && defined(LIBGIT2_VER_MINOR) && defined(LIBGIT2_VER_REVISION) |
31 | | -#if ((LIBGIT2_VER_MAJOR * 1000000) + (LIBGIT2_VER_MINOR * 10000) + (LIBGIT2_VER_REVISION * 100)) < \ |
32 | | - 1070000 |
33 | | -#error "HAVE_LIBGIT2 requires libgit2 >= 1.7.0 for git_allocator" |
34 | | -#endif |
35 | | -#else |
36 | | -#error "HAVE_LIBGIT2 requires known libgit2 version macros for the >= 1.7.0 git_allocator guard" |
37 | | -#endif |
38 | | -#include <git2.h> // git_libgit2_opts, GIT_OPT_SET_ALLOCATOR — bind libgit2 to mimalloc |
39 | | -#include <git2/sys/alloc.h> // git_allocator — not pulled in by <git2.h> (it's a sys/ header) |
40 | | -#endif |
41 | 24 | #endif |
42 | 25 | #include <stdint.h> // uint32_t, uint64_t, int64_t |
43 | 26 | #include <stdlib.h> |
@@ -256,7 +239,7 @@ static TSParser *get_thread_parser(const TSLanguage *ts_lang, CBMLanguage lang) |
256 | 239 |
|
257 | 240 | // --- Allocator binding (defense-in-depth, #424) --- |
258 | 241 |
|
259 | | -/* Bind tree-sitter, sqlite3, and libgit2 to mimalloc explicitly so a correct |
| 242 | +/* Bind tree-sitter and sqlite3 to mimalloc explicitly so a correct |
260 | 243 | * binary does NOT depend on the fragile MI_OVERRIDE symbol override. Under |
261 | 244 | * MI_OVERRIDE=1 — particularly the Windows static-MinGW link with |
262 | 245 | * --allow-multiple-definition — `malloc`/`free` can resolve to DIFFERENT |
@@ -300,25 +283,6 @@ static int cbm_sqlite_meminit(void *appdata) { |
300 | 283 | static void cbm_sqlite_memshutdown(void *appdata) { |
301 | 284 | (void)appdata; |
302 | 285 | } |
303 | | - |
304 | | -#if defined(HAVE_LIBGIT2) |
305 | | -/* libgit2 >= 1.7 git_allocator backed by mimalloc. The struct has exactly |
306 | | - * three members: gmalloc(size_t,file,line), grealloc(ptr,size,file,line), |
307 | | - * gfree(ptr). The file/line args are ignored. */ |
308 | | -static void *cbm_git_malloc(size_t n, const char *file, int line) { |
309 | | - (void)file; |
310 | | - (void)line; |
311 | | - return mi_malloc(n); |
312 | | -} |
313 | | -static void *cbm_git_realloc(void *ptr, size_t size, const char *file, int line) { |
314 | | - (void)file; |
315 | | - (void)line; |
316 | | - return mi_realloc(ptr, size); |
317 | | -} |
318 | | -static void cbm_git_free(void *ptr) { |
319 | | - mi_free(ptr); |
320 | | -} |
321 | | -#endif /* HAVE_LIBGIT2 */ |
322 | 286 | #endif /* CBM_BIND_TS_ALLOCATOR */ |
323 | 287 |
|
324 | 288 | void cbm_alloc_init(void) { |
@@ -349,24 +313,6 @@ void cbm_alloc_init(void) { |
349 | 313 | int sqlite_rc = sqlite3_config(SQLITE_CONFIG_MALLOC, &cbm_sqlite_mem); |
350 | 314 | assert(sqlite_rc == SQLITE_OK && "SQLITE_CONFIG_MALLOC must run before sqlite3_initialize"); |
351 | 315 | (void)sqlite_rc; |
352 | | - |
353 | | -#if defined(HAVE_LIBGIT2) |
354 | | - /* libgit2. GIT_OPT_SET_ALLOCATOR MUST be set BEFORE git_libgit2_init(): |
355 | | - * libgit2's git_allocator_global_init (run during init) installs the default |
356 | | - * stdalloc only if no custom allocator is set yet |
357 | | - * (`if (git__allocator.gmalloc != git_failalloc_malloc) return 0;`), and the |
358 | | - * pre-init global is the fail-allocator. There is no allocator-reset on |
359 | | - * git_libgit2_shutdown, so binding once here — before pass_githistory's |
360 | | - * per-call git_libgit2_init/shutdown pairs ever run — persists for the whole |
361 | | - * process. git_libgit2_opts(GIT_OPT_SET_ALLOCATOR,...) itself does not |
362 | | - * allocate, so calling it before init is safe. */ |
363 | | - static git_allocator cbm_git_alloc = { |
364 | | - cbm_git_malloc, /* gmalloc */ |
365 | | - cbm_git_realloc, /* grealloc */ |
366 | | - cbm_git_free, /* gfree */ |
367 | | - }; |
368 | | - git_libgit2_opts(GIT_OPT_SET_ALLOCATOR, &cbm_git_alloc); |
369 | | -#endif /* HAVE_LIBGIT2 */ |
370 | 316 | #endif /* CBM_BIND_TS_ALLOCATOR */ |
371 | 317 | } |
372 | 318 |
|
|
0 commit comments