Skip to content

Commit 473bd1d

Browse files
committedMar 12, 2024
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: #304
1 parent e859eae commit 473bd1d

File tree

2 files changed

+3
-17
lines changed

2 files changed

+3
-17
lines changed
 

‎cutils.h

+2-6
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@
3838
#endif
3939
#if defined(__APPLE__)
4040
#include <malloc/malloc.h>
41-
#elif defined(__ANDROID__)
42-
#include <dlmalloc.h>
43-
#elif defined(__linux__) || defined(__CYGWIN__)
41+
#elif defined(__linux__) || defined(__ANDROID__) || defined(__CYGWIN__)
4442
#include <malloc.h>
4543
#elif defined(__FreeBSD__)
4644
#include <malloc_np.h>
@@ -421,9 +419,7 @@ static inline size_t js__malloc_usable_size(const void *ptr)
421419
return malloc_size(ptr);
422420
#elif defined(_WIN32)
423421
return _msize((void *)ptr);
424-
#elif defined(__ANDROID__)
425-
return dlmalloc_usable_size((void *)ptr);
426-
#elif defined(__linux__) || defined(__FreeBSD__)
422+
#elif defined(__linux__) || defined(__ANDROID__) || defined(__CYGWIN__) || defined(__FreeBSD__)
427423
return malloc_usable_size((void *)ptr);
428424
#else
429425
return 0;

‎quickjs.c

+1-11
Original file line numberDiff line numberDiff line change
@@ -1734,17 +1734,7 @@ static const JSMallocFunctions def_malloc_funcs = {
17341734
js_def_malloc,
17351735
js_def_free,
17361736
js_def_realloc,
1737-
#if defined(__APPLE__)
1738-
malloc_size,
1739-
#elif defined(_WIN32)
1740-
(size_t (*)(const void *))_msize,
1741-
#elif defined(__ANDROID__)
1742-
(size_t (*)(const void *))dlmalloc_usable_size,
1743-
#elif defined(__linux__) || defined (__CYGWIN__)
1744-
(size_t (*)(const void *))malloc_usable_size,
1745-
#else
1746-
NULL,
1747-
#endif
1737+
js__malloc_usable_size
17481738
};
17491739

17501740
JSRuntime *JS_NewRuntime(void)

0 commit comments

Comments
 (0)