Use malloc_usable_size() on any OS based on GNU libc
malloc_usable_size() is a GNU extension in GNU libc; hence, use it every time GNU libc is used, rather than only on Linux.
This commit is contained in:
parent
5417ab0159
commit
34894936d8
2 changed files with 4 additions and 4 deletions
4
qjs.c
4
qjs.c
|
@ -34,7 +34,7 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
#include <malloc/malloc.h>
|
#include <malloc/malloc.h>
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__) || defined(__GLIBC__)
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#elif defined(__FreeBSD__)
|
#elif defined(__FreeBSD__)
|
||||||
#include <malloc_np.h>
|
#include <malloc_np.h>
|
||||||
|
@ -151,7 +151,7 @@ static size_t js_trace_malloc_usable_size(const void *ptr)
|
||||||
return _msize((void *)ptr);
|
return _msize((void *)ptr);
|
||||||
#elif defined(EMSCRIPTEN)
|
#elif defined(EMSCRIPTEN)
|
||||||
return 0;
|
return 0;
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__) || defined(__GLIBC__)
|
||||||
return malloc_usable_size((void *)ptr);
|
return malloc_usable_size((void *)ptr);
|
||||||
#else
|
#else
|
||||||
/* change this to `return 0;` if compilation fails */
|
/* change this to `return 0;` if compilation fails */
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
#include <malloc/malloc.h>
|
#include <malloc/malloc.h>
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__) || defined(__GLIBC__)
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#elif defined(__FreeBSD__)
|
#elif defined(__FreeBSD__)
|
||||||
#include <malloc_np.h>
|
#include <malloc_np.h>
|
||||||
|
@ -1708,7 +1708,7 @@ static size_t js_def_malloc_usable_size(const void *ptr)
|
||||||
return _msize((void *)ptr);
|
return _msize((void *)ptr);
|
||||||
#elif defined(EMSCRIPTEN)
|
#elif defined(EMSCRIPTEN)
|
||||||
return 0;
|
return 0;
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__) || defined(__GLIBC__)
|
||||||
return malloc_usable_size((void *)ptr);
|
return malloc_usable_size((void *)ptr);
|
||||||
#else
|
#else
|
||||||
/* change this to `return 0;` if compilation fails */
|
/* change this to `return 0;` if compilation fails */
|
||||||
|
|
Loading…
Reference in a new issue