From 473bd1d531ff4fc07817b9fcdd6df2857e0edb60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Tue, 12 Mar 2024 09:06:07 +0100 Subject: [PATCH] Fix Android build dlmalloc has been removed and the NDK now exposes a malloc.h header with malloc_usable_size exposed, so use that. Also remove the duplication in js__malloc_usable_size. Fixes: https://github.com/quickjs-ng/quickjs/issues/304 --- cutils.h | 8 ++------ quickjs.c | 12 +----------- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/cutils.h b/cutils.h index a926319..447a72a 100644 --- a/cutils.h +++ b/cutils.h @@ -38,9 +38,7 @@ #endif #if defined(__APPLE__) #include -#elif defined(__ANDROID__) -#include -#elif defined(__linux__) || defined(__CYGWIN__) +#elif defined(__linux__) || defined(__ANDROID__) || defined(__CYGWIN__) #include #elif defined(__FreeBSD__) #include @@ -421,9 +419,7 @@ static inline size_t js__malloc_usable_size(const void *ptr) return malloc_size(ptr); #elif defined(_WIN32) return _msize((void *)ptr); -#elif defined(__ANDROID__) - return dlmalloc_usable_size((void *)ptr); -#elif defined(__linux__) || defined(__FreeBSD__) +#elif defined(__linux__) || defined(__ANDROID__) || defined(__CYGWIN__) || defined(__FreeBSD__) return malloc_usable_size((void *)ptr); #else return 0; diff --git a/quickjs.c b/quickjs.c index 3cc8175..527f75a 100644 --- a/quickjs.c +++ b/quickjs.c @@ -1734,17 +1734,7 @@ static const JSMallocFunctions def_malloc_funcs = { js_def_malloc, js_def_free, js_def_realloc, -#if defined(__APPLE__) - malloc_size, -#elif defined(_WIN32) - (size_t (*)(const void *))_msize, -#elif defined(__ANDROID__) - (size_t (*)(const void *))dlmalloc_usable_size, -#elif defined(__linux__) || defined (__CYGWIN__) - (size_t (*)(const void *))malloc_usable_size, -#else - NULL, -#endif + js__malloc_usable_size }; JSRuntime *JS_NewRuntime(void)