|
10 | 10 |
|
11 | 11 | #include "git2/sys/alloc.h" |
12 | 12 |
|
| 13 | +#include "git2_util.h" |
| 14 | + |
13 | 15 | extern git_allocator git__allocator; |
14 | 16 |
|
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 |
| 17 | +GIT_INLINE(void *) git__malloc(size_t len) |
| 18 | +{ |
| 19 | + void *p = git__allocator.gmalloc(len, __FILE__, __LINE__); |
| 20 | + |
| 21 | + if (!p) |
| 22 | + git_error_set_oom(); |
| 23 | + |
| 24 | + return p; |
| 25 | +} |
| 26 | + |
| 27 | +GIT_INLINE(void *) git__realloc(void *ptr, size_t size) |
| 28 | +{ |
| 29 | + void *p = git__allocator.grealloc(ptr, size, __FILE__, __LINE__); |
| 30 | + |
| 31 | + if (!p) |
| 32 | + git_error_set_oom(); |
| 33 | + |
| 34 | + return p; |
| 35 | +} |
| 36 | + |
| 37 | +GIT_INLINE(void) git__free(void *ptr) |
| 38 | +{ |
| 39 | + git__allocator.gfree(ptr); |
| 40 | +} |
| 41 | + |
| 42 | +extern void *git__calloc(size_t nelem, size_t elsize); |
| 43 | +extern void *git__mallocarray(size_t nelem, size_t elsize); |
| 44 | +extern void *git__reallocarray(void *ptr, size_t nelem, size_t elsize); |
| 45 | + |
| 46 | +extern char *git__strdup(const char *str); |
| 47 | +extern char *git__strndup(const char *str, size_t n); |
| 48 | +extern char *git__substrdup(const char *str, size_t n); |
24 | 49 |
|
25 | 50 | /** |
26 | 51 | * This function is being called by our global setup routines to |
|
0 commit comments