Another attempt to fix something that was previously fixed by
73255670 but got reversed due to breaking something else.
The issue is that CMock_Guts_Buffer was unsigned char thus it
may have been unaligned (byte aligned). Portions from this buffer
where casted to a structure. On certain architectures alignment
must be maintained when accessing 32bit or 64 bit data and that
was not maintained with byte aligned array.
Instead of using attribute that may be complier specific, changing
type of array to long long.
GCC (& Clang) have the notion of pure and const functions [1],
where those attributes are intended to help the optimiser.
Annotate a few APIs here with the appropriate key words, which
also fixes Wsuggest-attribute=pure and Wsuggest-attribute=const
warnings, which a source base might have enabled:
.../src/cmock.c: In function ‘CMock_Guts_MemNext’:
.../src/cmock.c:118:22: warning: function might be candidate for attribute ‘pure’ [-Wsuggest-attribute=pure]
118 | CMOCK_MEM_INDEX_TYPE CMock_Guts_MemNext(CMOCK_MEM_INDEX_TYPE previous_item_index)
| ^~~~~~~~~~~~~~~~~~
.../src/cmock.c: In function ‘CMock_Guts_MemEndOfChain’:
.../src/cmock.c:140:22: warning: function might be candidate for attribute ‘pure’ if it is known to return normally [-Wsuggest-attribute=pure]
140 | CMOCK_MEM_INDEX_TYPE CMock_Guts_MemEndOfChain(CMOCK_MEM_INDEX_TYPE root_index)
| ^~~~~~~~~~~~~~~~~~~~~~~~
.../src/cmock.c: In function ‘CMock_Guts_GetAddressFor’:
.../src/cmock.c:158:7: warning: function might be candidate for attribute ‘pure’ [-Wsuggest-attribute=pure]
158 | void* CMock_Guts_GetAddressFor(CMOCK_MEM_INDEX_TYPE index)
| ^~~~~~~~~~~~~~~~~~~~~~~~
.../src/cmock.c: In function ‘CMock_Guts_MemBytesCapacity’:
.../src/cmock.c:173:22: warning: function might be candidate for attribute ‘const’ [-Wsuggest-attribute=const]
173 | CMOCK_MEM_INDEX_TYPE CMock_Guts_MemBytesCapacity(void)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
.../src/cmock.c: In function ‘CMock_Guts_MemBytesFree’:
.../src/cmock.c:181:22: warning: function might be candidate for attribute ‘pure’ [-Wsuggest-attribute=pure]
181 | CMOCK_MEM_INDEX_TYPE CMock_Guts_MemBytesFree(void)
| ^~~~~~~~~~~~~~~~~~~~~~~
.../src/cmock.c: In function ‘CMock_Guts_MemBytesUsed’:
.../src/cmock.c:189:22: warning: function might be candidate for attribute ‘pure’ [-Wsuggest-attribute=pure]
189 | CMOCK_MEM_INDEX_TYPE CMock_Guts_MemBytesUsed(void)
| ^~~~~~~~~~~~~~~~~~~~~~~
[1] https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html
Signed-off-by: André Draszik <git@andred.net>
We should be able to allocate up to CMock_Guts_MemBytesFree() minus
CMOCK_MEM_INDEX_SIZE. An incorrect less-than-or-equal prevented
allocating the very last byte.
Set CMock_Guts_FreePtr to CMOCK_MEM_ALIGN_SIZE initially (the same
value it is reset to by CMock_Guts_MemFreeAll(). This makes sure
that the value returned by CMock_Guts_MemBytesUsed() is 0 initially
and not a negative value.
The value of CMOCK_MEM_ALIGN changed depending on whether unity.h
or cmock.h was included first. Since cmock_internals.h uses
features from unity.h, it should include unity.h.
IgnoreMode was used only for the ExpectAnyArgs plugin, and the
semantics of it were backwards:
- IgnoreMode = CMOCK_ARG_NONE means to ignore all arguments
- IgnoreMode = CMOCK_ARG_ALL means to verify all arguments
ExpectAnyArgsBool should make the purpose and semantics of this
field clearer.
Additionally, ExpectAnyArgs doesn't use FinalReturn for anything.
Changed allocation to use CMOCK_MEM_INDEX_TYPE instead of unsigned char. This may allocate extra memory if CMOCK_MEM_SIZE is not a multiple of CMOCK_MEM_INDEX_SIZE. Had to substitute CMock_Guts_Buffer with a define in this case because pointers are not constants.
realloc() was successful. Prior to this change, if realloc() failed, the
current test would fail for out-of-memory, but subsequent tests would
continue trying to run with CMock_Guts_Buffer at address 0x00000000 and
thinking that the buffer size was sufficient. Therefore depending on the
system and how it handles (or doesn't handle) null pointer
dereferencing, subsequent tests might pass, fail in strange ways, or
crash the test app.
- Made use of the new UNITY_SET_DETAILS feature to background set up function & argument details for messages
- CMock now takes up a lot less memory! woo!
This is useful when testing embedded code, and trying to gain
confidence that CMock works correctly, is configured correctly,
etc.
This involved creating cmock_internal.h which holds #defines
used by cmock.c. These are then also used in TestCMockc.c
instead of hard-coded data sizes.