I have a makefile that builds, runs unit tests, memory leaks etc. But is there a way I can stop malloc(), free(), calloc() and the like from being used in the source code?
I have replacement memory functions that handle things like mocking. Is there a way I can enforce EagleMemory_Free() to be used instead of free(), for example.
My replacement functions have a different signature so I can’t simply create a macro that points the internal one to my own:
void* EagleMemory_Allocate(char *id, size_t size);
void EagleMemory_Free(void *ptr);
void** EagleMemory_MultiAllocate(char *id, size_t size, int quantity);
void EagleMemory_MultiFree(void **ptr, int quantity);
void EagleMemory_MockInit(void);
void EagleMemory_Mock(char *id);
void EagleMemory_MockFinish(void);
int EagleMemory_GetMockInvocations(void);
Oh, I should also point out I don’t want to replace the function at runtime and cause my software to crash – that’s just stupid. I want to catch the use of the std function at build time or through some other script before the software runs.
Thanks to Alexey Frunze. The
nmcommand was exactly what I needed. I added this to my makefile:Works great!