10const char *CMockStringOutOfMemory =
11 "CMock has run out of memory. Please allocate more.";
12const char *CMockStringCalledMore =
"Called more times than expected.";
13const char *CMockStringCalledLess =
"Called fewer times than expected.";
14const char *CMockStringCalledEarly =
"Called earlier than expected.";
15const char *CMockStringCalledLate =
"Called later than expected.";
16const char *CMockStringCallOrder =
"Called out of order.";
17const char *CMockStringIgnPreExp =
"IgnoreArg called before Expect.";
18const char *CMockStringPtrPreExp =
"ReturnThruPtr called before Expect.";
19const char *CMockStringPtrIsNULL =
"Pointer is NULL.";
20const char *CMockStringExpNULL =
"Expected NULL.";
21const char *CMockStringMismatch =
22 "Function called with unexpected argument value.";
25#ifdef CMOCK_MEM_DYNAMIC
26static unsigned char *CMock_Guts_Buffer = NULL;
27static CMOCK_MEM_INDEX_TYPE CMock_Guts_BufferSize = CMOCK_MEM_ALIGN_SIZE;
28static CMOCK_MEM_INDEX_TYPE CMock_Guts_FreePtr = CMOCK_MEM_ALIGN_SIZE;
30static unsigned char CMock_Guts_Buffer[CMOCK_MEM_SIZE + CMOCK_MEM_ALIGN_SIZE];
31static CMOCK_MEM_INDEX_TYPE CMock_Guts_BufferSize =
32 CMOCK_MEM_SIZE + CMOCK_MEM_ALIGN_SIZE;
33static CMOCK_MEM_INDEX_TYPE CMock_Guts_FreePtr = CMOCK_MEM_ALIGN_SIZE;
39CMOCK_MEM_INDEX_TYPE CMock_Guts_MemNew(CMOCK_MEM_INDEX_TYPE size) {
40 CMOCK_MEM_INDEX_TYPE index;
45 return CMOCK_GUTS_NONE;
48 size = size + CMOCK_MEM_INDEX_SIZE;
49 if (size & CMOCK_MEM_ALIGN_MASK)
50 size = (size + CMOCK_MEM_ALIGN_MASK) & ~CMOCK_MEM_ALIGN_MASK;
51 if ((CMock_Guts_BufferSize - CMock_Guts_FreePtr) < size) {
52#ifndef CMOCK_MEM_DYNAMIC
53 return CMOCK_GUTS_NONE;
58 CMOCK_MEM_INDEX_TYPE new_buffersize =
59 CMock_Guts_BufferSize + CMOCK_MEM_SIZE + size;
60 unsigned char *new_buffer =
61 realloc(CMock_Guts_Buffer, (
size_t)new_buffersize);
62 if (new_buffer == NULL)
63 return CMOCK_GUTS_NONE;
64 CMock_Guts_Buffer = new_buffer;
65 CMock_Guts_BufferSize = new_buffersize;
71 index = CMock_Guts_FreePtr + CMOCK_MEM_INDEX_SIZE;
72 *(CMOCK_MEM_INDEX_TYPE *)(&CMock_Guts_Buffer[CMock_Guts_FreePtr]) =
74 CMock_Guts_FreePtr += size;
82CMOCK_MEM_INDEX_TYPE CMock_Guts_MemChain(CMOCK_MEM_INDEX_TYPE root_index,
83 CMOCK_MEM_INDEX_TYPE obj_index) {
84 CMOCK_MEM_INDEX_TYPE index;
89 if (root_index == CMOCK_GUTS_NONE) {
95 if ((root_index < CMOCK_MEM_ALIGN_SIZE) ||
96 (root_index >= CMock_Guts_FreePtr)) {
97 return CMOCK_GUTS_NONE;
99 if ((obj_index < CMOCK_MEM_ALIGN_SIZE) ||
100 (obj_index >= CMock_Guts_FreePtr)) {
101 return CMOCK_GUTS_NONE;
104 root = (
void *)(&CMock_Guts_Buffer[root_index]);
105 obj = (
void *)(&CMock_Guts_Buffer[obj_index]);
110 index = *(CMOCK_MEM_INDEX_TYPE *)((CMOCK_MEM_PTR_AS_INT)next -
111 CMOCK_MEM_INDEX_SIZE);
112 if (index >= CMock_Guts_FreePtr)
113 return CMOCK_GUTS_NONE;
115 next = (
void *)(&CMock_Guts_Buffer[index]);
117 *(CMOCK_MEM_INDEX_TYPE *)((CMOCK_MEM_PTR_AS_INT)next -
118 CMOCK_MEM_INDEX_SIZE) =
119 (CMOCK_MEM_INDEX_TYPE)((CMOCK_MEM_PTR_AS_INT)obj -
120 (CMOCK_MEM_PTR_AS_INT)CMock_Guts_Buffer);
129CMock_Guts_MemNext(CMOCK_MEM_INDEX_TYPE previous_item_index) {
130 CMOCK_MEM_INDEX_TYPE index;
134 if ((previous_item_index < CMOCK_MEM_ALIGN_SIZE) ||
135 (previous_item_index >= CMock_Guts_FreePtr))
136 return CMOCK_GUTS_NONE;
137 previous_item = (
void *)(&CMock_Guts_Buffer[previous_item_index]);
142 index = *(CMOCK_MEM_INDEX_TYPE *)((CMOCK_MEM_PTR_AS_INT)previous_item -
143 CMOCK_MEM_INDEX_SIZE);
144 if ((index > 1) && (index < CMock_Guts_FreePtr))
147 return CMOCK_GUTS_NONE;
153CMOCK_MEM_INDEX_TYPE CMock_Guts_MemEndOfChain(CMOCK_MEM_INDEX_TYPE root_index) {
154 CMOCK_MEM_INDEX_TYPE index = root_index;
155 CMOCK_MEM_INDEX_TYPE next_index;
157 for (next_index = root_index; next_index != CMOCK_GUTS_NONE;
158 next_index = CMock_Guts_MemNext(index)) {
168void *CMock_Guts_GetAddressFor(CMOCK_MEM_INDEX_TYPE index) {
169 if ((index >= CMOCK_MEM_ALIGN_SIZE) && (index < CMock_Guts_FreePtr)) {
170 return (
void *)(&CMock_Guts_Buffer[index]);
179CMOCK_MEM_INDEX_TYPE CMock_Guts_MemBytesCapacity(
void) {
180 return (
sizeof(CMock_Guts_Buffer) - CMOCK_MEM_ALIGN_SIZE);
186CMOCK_MEM_INDEX_TYPE CMock_Guts_MemBytesFree(
void) {
187 return CMock_Guts_BufferSize - CMock_Guts_FreePtr;
193CMOCK_MEM_INDEX_TYPE CMock_Guts_MemBytesUsed(
void) {
194 return CMock_Guts_FreePtr - CMOCK_MEM_ALIGN_SIZE;
200void CMock_Guts_MemFreeAll(
void) {
201 CMock_Guts_FreePtr = CMOCK_MEM_ALIGN_SIZE;
207void CMock_Guts_MemFreeFinal(
void) {
208 CMock_Guts_FreePtr = CMOCK_MEM_ALIGN_SIZE;
209#ifdef CMOCK_MEM_DYNAMIC
210 if (CMock_Guts_Buffer) {
211 free(CMock_Guts_Buffer);
212 CMock_Guts_Buffer = NULL;