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
This commit is contained in:
Saúl Ibarra Corretgé 2024-03-12 09:06:07 +01:00
parent e859eae483
commit 473bd1d531
2 changed files with 3 additions and 17 deletions

View file

@ -38,9 +38,7 @@
#endif
#if defined(__APPLE__)
#include <malloc/malloc.h>
#elif defined(__ANDROID__)
#include <dlmalloc.h>
#elif defined(__linux__) || defined(__CYGWIN__)
#elif defined(__linux__) || defined(__ANDROID__) || defined(__CYGWIN__)
#include <malloc.h>
#elif defined(__FreeBSD__)
#include <malloc_np.h>
@ -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;

View file

@ -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)