unity_memory.h 1.9 KB
Newer Older
1
/* ==========================================
J
jsalling 已提交
2 3 4 5
 *  Unity Project - A Test Framework for C
 *  Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
 *  [Released under MIT License. Please refer to license.txt for details]
 * ========================================== */
6

7 8 9 10 11 12 13
#ifndef UNITY_MEMORY_OVERRIDES_H_
#define UNITY_MEMORY_OVERRIDES_H_

#ifdef __cplusplus
extern "C"
{
#endif
14

15 16
#include <stddef.h>

17
#ifdef UNITY_EXCLUDE_STDLIB_MALLOC
J
jsalling 已提交
18 19 20 21 22
/* Define this macro to remove the use of stdlib.h, malloc, and free.
 * Many embedded systems do not have a heap or malloc/free by default.
 * This internal unity_malloc() provides allocated memory deterministically from
 * the end of an array only, unity_free() only releases from end-of-array,
 * blocks are not coalesced, and memory not freed in LIFO order is stranded. */
23 24 25 26 27
    #ifndef UNITY_INTERNAL_HEAP_SIZE_BYTES
    #define UNITY_INTERNAL_HEAP_SIZE_BYTES 256
    #endif
#endif

28
/* These functions are used by Unity to allocate and release memory
J
jsalling 已提交
29
 * on the heap and can be overridden with platform-specific implementations.
30 31 32
 * For example, when using FreeRTOS UNITY_MALLOC becomes pvPortMalloc()
 * and UNITY_FREE becomes vPortFree(). */
#if !defined(UNITY_MALLOC) || !defined(UNITY_FREE)
33
    #include <stdlib.h>
34 35
    #define UNITY_MALLOC(size) malloc(size)
    #define UNITY_FREE(ptr)    free(ptr)
36
#else
37 38
    extern void* UNITY_MALLOC(size_t size);
    extern void UNITY_FREE(void* ptr);
39 40
#endif

41 42 43 44 45
#define malloc  unity_malloc
#define calloc  unity_calloc
#define realloc unity_realloc
#define free    unity_free

46 47 48 49 50
void* unity_malloc(size_t size);
void* unity_calloc(size_t num, size_t size);
void* unity_realloc(void * oldMem, size_t size);
void unity_free(void * mem);

51 52 53 54 55 56 57 58 59 60
/* You must compile with malloc replacement, as defined in unity_fixture_malloc_overrides.h */
void UnityMalloc_StartTest(void);
void UnityMalloc_EndTest(void);
void UnityMalloc_MakeMallocFailAfterCount(int countdown);

#ifdef __cplusplus
}
#endif

#endif