unity_fixture_malloc_overrides.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* Copyright (c) 2010 James Grenning and Contributed to Unity Project
  2. * ==========================================
  3. * Unity Project - A Test Framework for C
  4. * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
  5. * [Released under MIT License. Please refer to license.txt for details]
  6. * ========================================== */
  7. #ifndef UNITY_FIXTURE_MALLOC_OVERRIDES_H_
  8. #define UNITY_FIXTURE_MALLOC_OVERRIDES_H_
  9. #include <stddef.h>
  10. #ifdef UNITY_EXCLUDE_STDLIB_MALLOC
  11. /* Define this macro to remove the use of stdlib.h, malloc, and free.
  12. * Many embedded systems do not have a heap or malloc/free by default.
  13. * This internal unity_malloc() provides allocated memory deterministically from
  14. * the end of an array only, unity_free() only releases from end-of-array,
  15. * blocks are not coalesced, and memory not freed in LIFO order is stranded. */
  16. #ifndef UNITY_INTERNAL_HEAP_SIZE_BYTES
  17. #define UNITY_INTERNAL_HEAP_SIZE_BYTES 256
  18. #endif
  19. #endif
  20. /* These functions are used by the Unity Fixture to allocate and release memory
  21. * on the heap and can be overridden with platform-specific implementations.
  22. * For example, when using FreeRTOS UNITY_FIXTURE_MALLOC becomes pvPortMalloc()
  23. * and UNITY_FIXTURE_FREE becomes vPortFree(). */
  24. #if !defined(UNITY_FIXTURE_MALLOC) || !defined(UNITY_FIXTURE_FREE)
  25. #include <stdlib.h>
  26. #define UNITY_FIXTURE_MALLOC(size) malloc(size)
  27. #define UNITY_FIXTURE_FREE(ptr) free(ptr)
  28. #else
  29. extern void* UNITY_FIXTURE_MALLOC(size_t size);
  30. extern void UNITY_FIXTURE_FREE(void* ptr);
  31. #endif
  32. #define malloc unity_malloc
  33. #define calloc unity_calloc
  34. #define realloc unity_realloc
  35. #define free unity_free
  36. void* unity_malloc(size_t size);
  37. void* unity_calloc(size_t num, size_t size);
  38. void* unity_realloc(void * oldMem, size_t size);
  39. void unity_free(void * mem);
  40. #endif /* UNITY_FIXTURE_MALLOC_OVERRIDES_H_ */