From 435741c917f188e0e4c21f7d586ce9397b0c1ae3 Mon Sep 17 00:00:00 2001 From: mikee47 Date: Mon, 16 Sep 2024 08:05:09 +0100 Subject: [PATCH] Fix MallocCount for MinGW MinGW defines aliases in stdlib.h for `realloc` and `free` which require wrapping. --- Sming/Components/malloc_count/component.mk | 5 +++++ Sming/Components/malloc_count/malloc_count.cpp | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Sming/Components/malloc_count/component.mk b/Sming/Components/malloc_count/component.mk index 7089c0962f..5579848cd1 100644 --- a/Sming/Components/malloc_count/component.mk +++ b/Sming/Components/malloc_count/component.mk @@ -29,6 +29,11 @@ MC_WRAP_FUNCS += \ pvPortZallocIram \ vPortFree endif +ifeq ($(SMING_ARCH)$(UNAME),HostWindows) +MC_WRAP_FUNCS += \ + __mingw_realloc \ + __mingw_free +endif EXTRA_LDFLAGS := $(call UndefWrap,$(MC_WRAP_FUNCS)) diff --git a/Sming/Components/malloc_count/malloc_count.cpp b/Sming/Components/malloc_count/malloc_count.cpp index 6766a8e46b..64e59cad86 100644 --- a/Sming/Components/malloc_count/malloc_count.cpp +++ b/Sming/Components/malloc_count/malloc_count.cpp @@ -373,6 +373,11 @@ extern "C" void* WRAP(pvPortZalloc)(size_t) __attribute__((alias("mc_zalloc"))); extern "C" void* WRAP(pvPortZallocIram)(size_t) __attribute__((alias("mc_zalloc"))); extern "C" void WRAP(vPortFree)(void*) __attribute__((alias("mc_free"))); +#elif defined(__WIN32) + +extern "C" void* WRAP(__mingw_realloc)(void*, size_t) __attribute__((alias("mc_realloc"))); +extern "C" void WRAP(__mingw_free)(void*) __attribute__((alias("mc_free"))); + #else void* operator new(size_t size) @@ -419,7 +424,7 @@ void operator delete[](void* ptr, size_t) #endif -#endif // ESP8266 +#endif extern "C" char* WRAP(strdup)(const char* s) {