Skip to content

Commit

Permalink
Fix MallocCount for MinGW
Browse files Browse the repository at this point in the history
MinGW defines aliases in stdlib.h for `realloc` and `free` which require wrapping.
  • Loading branch information
mikee47 committed Sep 16, 2024
1 parent 1e39a56 commit 435741c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Sming/Components/malloc_count/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
7 changes: 6 additions & 1 deletion Sming/Components/malloc_count/malloc_count.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -419,7 +424,7 @@ void operator delete[](void* ptr, size_t)

#endif

#endif // ESP8266
#endif

extern "C" char* WRAP(strdup)(const char* s)
{
Expand Down

0 comments on commit 435741c

Please sign in to comment.