Hash :
c47f7155
Author :
Date :
2018-03-14T10:34:59
util: extract `stdalloc` allocator into its own module Right now, the standard allocator is being declared as part of the "util.h" header as a set of inline functions. As with the crtdbg allocator functions, these inline functions make it hard to convert to function pointers for our allocators. Create a new "stdalloc" module containing our standard allocations functions to split these out. Convert the existing allocators to macros which make use of the stdalloc functions.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_stdalloc_h__
#define INCLUDE_stdalloc_h__
#include "common.h"
/*
* Custom memory allocation wrappers
* that set error code and error message
* on allocation failure
*/
void *git__stdalloc__malloc(size_t len);
void *git__stdalloc__calloc(size_t nelem, size_t elsize);
char *git__stdalloc__strdup(const char *str);
char *git__stdalloc__strndup(const char *str, size_t n);
/* NOTE: This doesn't do null or '\0' checking. Watch those boundaries! */
char *git__stdalloc__substrdup(const char *start, size_t n);
void *git__stdalloc__realloc(void *ptr, size_t size);
/**
* Similar to `git__stdalloc__realloc`, except that it is suitable for reallocing an
* array to a new number of elements of `nelem`, each of size `elsize`.
* The total size calculation is checked for overflow.
*/
void *git__stdalloc__reallocarray(void *ptr, size_t nelem, size_t elsize);
/**
* Similar to `git__stdalloc__calloc`, except that it does not zero memory.
*/
void *git__stdalloc__mallocarray(size_t nelem, size_t elsize);
void git__stdalloc__free(void *ptr);
#endif