提交 7737fee4 编写于 作者: A Andrew Burks

Fixes #116: Allow overrides of the Unity Fixture's memory functions. This...

Fixes #116: Allow overrides of the Unity Fixture's memory functions. This enables custom heap implementations to be used with the Unity Fixture.
上级 31b12556
......@@ -196,7 +196,7 @@ void * unity_malloc(size_t size)
malloc_count++;
guard = (Guard*)malloc(size + sizeof(Guard) + 4);
guard = (Guard*)UNITY_FIXTURE_MALLOC(size + sizeof(Guard) + 4);
guard->size = size;
mem = (char*)&(guard[1]);
memcpy(&mem[size], end, strlen(end) + 1);
......@@ -219,7 +219,7 @@ static void release_memory(void * mem)
guard--;
malloc_count--;
free(guard);
UNITY_FIXTURE_FREE(guard);
}
void unity_free(void * mem)
......
......@@ -10,6 +10,28 @@
#include <stddef.h>
// This function is used by the Unity Fixture to allocate memory on
// the heap and can be overridden with platform-specific heap
// implementations. For example, when using FreeRTOS
// UNITY_FIXTURE_MALLOC becomes pvPortMalloc().
#ifndef UNITY_FIXTURE_MALLOC
#define UNITY_FIXTURE_MALLOC( SIZE ) malloc( ( SIZE ) )
#else
extern void * UNITY_FIXTURE_MALLOC(size_t size);
#endif
// This function is used by the Unity Fixture to release memory in the
// heap and can be overridden with platform-specific heap
// implementations. For example, when using FreeRTOS
// UNITY_FIXTURE_FREE becomes vPortFree().
#ifndef UNITY_FIXTURE_FREE
#define UNITY_FIXTURE_FREE( PTR ) free( ( PTR ) )
#else
extern void UNITY_FIXTURE_FREE(void *ptr);
#endif
#define malloc unity_malloc
#define calloc unity_calloc
#define realloc unity_realloc
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册