提交 63a0b98f 编写于 作者: J jsalling

Remove atoi() dependency, only need stdlib.h in Fixture for malloc

 For redefinition of UNITY_FIXTURE_MALLOC/...FREE use both or replace both.
 Clean up whitespace, remaining void*, and comment.
上级 34a30f8e
...@@ -149,21 +149,12 @@ void UnityMalloc_MakeMallocFailAfterCount(int countdown) ...@@ -149,21 +149,12 @@ void UnityMalloc_MakeMallocFailAfterCount(int countdown)
malloc_fail_countdown = countdown; malloc_fail_countdown = countdown;
} }
#ifdef malloc // These definitions are always included from unity_fixture_malloc_overrides.h
// We undef to use them or avoid conflict with <stdlib.h> per the C standard
#undef malloc #undef malloc
#endif
#ifdef free
#undef free #undef free
#endif
#ifdef calloc
#undef calloc #undef calloc
#endif
#ifdef realloc
#undef realloc #undef realloc
#endif
#include <stdlib.h> #include <stdlib.h>
...@@ -290,7 +281,7 @@ void UnityPointer_Init(void) ...@@ -290,7 +281,7 @@ void UnityPointer_Init(void)
pointer_index = 0; pointer_index = 0;
} }
void UnityPointer_Set(void ** pointer, void * newValue) void UnityPointer_Set(void** pointer, void* newValue)
{ {
if (pointer_index >= MAX_POINTERS) if (pointer_index >= MAX_POINTERS)
{ {
...@@ -311,8 +302,7 @@ void UnityPointer_UndoAllSets(void) ...@@ -311,8 +302,7 @@ void UnityPointer_UndoAllSets(void)
{ {
pointer_index--; pointer_index--;
*(pointer_store[pointer_index].pointer) = *(pointer_store[pointer_index].pointer) =
pointer_store[pointer_index].old_value; pointer_store[pointer_index].old_value;
} }
} }
...@@ -373,7 +363,13 @@ int UnityGetCommandLineOptions(int argc, const char* argv[]) ...@@ -373,7 +363,13 @@ int UnityGetCommandLineOptions(int argc, const char* argv[])
{ {
if (*(argv[i]) >= '0' && *(argv[i]) <= '9') if (*(argv[i]) >= '0' && *(argv[i]) <= '9')
{ {
UnityFixture.RepeatCount = atoi(argv[i]); unsigned int digit = 0;
UnityFixture.RepeatCount = 0;
while (argv[i][digit] >= '0' && argv[i][digit] <= '9')
{
UnityFixture.RepeatCount *= 10;
UnityFixture.RepeatCount += (unsigned int)argv[i][digit++] - '0';
}
i++; i++;
} }
} }
......
...@@ -10,26 +10,17 @@ ...@@ -10,26 +10,17 @@
#include <stddef.h> #include <stddef.h>
// This function is used by the Unity Fixture to allocate memory on // These functions are used by the Unity Fixture to allocate and release memory
// the heap and can be overridden with platform-specific heap // on the heap and can be overridden with platform-specific implementations.
// implementations. For example, when using FreeRTOS // For example, when using FreeRTOS UNITY_FIXTURE_MALLOC becomes pvPortMalloc()
// UNITY_FIXTURE_MALLOC becomes pvPortMalloc(). // and UNITY_FIXTURE_FREE becomes vPortFree().
#ifndef UNITY_FIXTURE_MALLOC #if !defined(UNITY_FIXTURE_MALLOC) || !defined(UNITY_FIXTURE_FREE)
#define UNITY_FIXTURE_MALLOC( SIZE ) malloc( ( SIZE ) ) #define UNITY_FIXTURE_MALLOC(size) malloc(size)
#else #define UNITY_FIXTURE_FREE(ptr) free(ptr)
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 #else
extern void UNITY_FIXTURE_FREE(void *ptr); extern void* UNITY_FIXTURE_MALLOC(size_t size);
extern void UNITY_FIXTURE_FREE(void* ptr);
#endif #endif
#define malloc unity_malloc #define malloc unity_malloc
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册