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 #ifndef INCLUDE_alloc_h__ 9 #define INCLUDE_alloc_h__ 10 11 #include "git2/sys/alloc.h" 12 13 extern git_allocator git__allocator; 14 15 #define git__malloc(len) git__allocator.gmalloc(len, __FILE__, __LINE__) 16 #define git__calloc(nelem, elsize) git__allocator.gcalloc(nelem, elsize, __FILE__, __LINE__) 17 #define git__strdup(str) git__allocator.gstrdup(str, __FILE__, __LINE__) 18 #define git__strndup(str, n) git__allocator.gstrndup(str, n, __FILE__, __LINE__) 19 #define git__substrdup(str, n) git__allocator.gsubstrdup(str, n, __FILE__, __LINE__) 20 #define git__realloc(ptr, size) git__allocator.grealloc(ptr, size, __FILE__, __LINE__) 21 #define git__reallocarray(ptr, nelem, elsize) git__allocator.greallocarray(ptr, nelem, elsize, __FILE__, __LINE__) 22 #define git__mallocarray(nelem, elsize) git__allocator.gmallocarray(nelem, elsize, __FILE__, __LINE__) 23 #define git__free git__allocator.gfree 24 25 /** 26 * This function is being called by our global setup routines to 27 * initialize the standard allocator. 28 */ 29 int git_allocator_global_init(void); 30 31 /** 32 * Switch out libgit2's global memory allocator 33 * 34 * @param allocator The new allocator that should be used. All function pointers 35 * of it need to be set correctly. 36 * @return An error code or 0. 37 */ 38 int git_allocator_setup(git_allocator *allocator); 39 40 #endif 41