Fix SHOW_MEMORY for gcc and glibc on linux
All checks were successful
Tests / Clang total: 932, passed: 932
Clang |Total|New|Outstanding|Fixed|Trend
|:-:|:-:|:-:|:-:|:-:
|0|0|0|0|:clap:
Tests / Release [gcc] total: 932, passed: 932
Tests / Release [gcc,aarch64] total: 931, passed: 931
Tests / Coverage total: 930, passed: 930
weaselab/conflict-set/pipeline/head This commit looks good
All checks were successful
Tests / Clang total: 932, passed: 932
Clang |Total|New|Outstanding|Fixed|Trend
|:-:|:-:|:-:|:-:|:-:
|0|0|0|0|:clap:
Tests / Release [gcc] total: 932, passed: 932
Tests / Release [gcc,aarch64] total: 931, passed: 931
Tests / Coverage total: 930, passed: 930
weaselab/conflict-set/pipeline/head This commit looks good
This commit is contained in:
@@ -47,7 +47,9 @@ limitations under the License.
|
|||||||
#if __has_builtin(__builtin_assume)
|
#if __has_builtin(__builtin_assume)
|
||||||
#define assume(e) __builtin_assume(e)
|
#define assume(e) __builtin_assume(e)
|
||||||
#else
|
#else
|
||||||
#define assume(e) __attribute__((assume(e)))
|
#define assume(e) \
|
||||||
|
if (!(e)) \
|
||||||
|
__builtin_unreachable()
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#define assume assert
|
#define assume assert
|
||||||
|
17
Internal.h
17
Internal.h
@@ -43,6 +43,8 @@ operator<=>(const std::span<const uint8_t> &lhs,
|
|||||||
#if SHOW_MEMORY
|
#if SHOW_MEMORY
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
#include <malloc/malloc.h>
|
#include <malloc/malloc.h>
|
||||||
|
#else
|
||||||
|
#include <malloc.h>
|
||||||
#endif
|
#endif
|
||||||
inline int64_t mallocBytes = 0;
|
inline int64_t mallocBytes = 0;
|
||||||
inline int64_t peakMallocBytes = 0;
|
inline int64_t peakMallocBytes = 0;
|
||||||
@@ -50,16 +52,21 @@ inline int64_t peakMallocBytes = 0;
|
|||||||
|
|
||||||
// malloc that aborts on OOM and thus always returns a non-null pointer
|
// malloc that aborts on OOM and thus always returns a non-null pointer
|
||||||
__attribute__((always_inline)) inline void *safe_malloc(size_t s) {
|
__attribute__((always_inline)) inline void *safe_malloc(size_t s) {
|
||||||
|
void *p = malloc(s);
|
||||||
|
if (p == nullptr) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
#if SHOW_MEMORY
|
#if SHOW_MEMORY
|
||||||
|
#ifdef __APPLE__
|
||||||
mallocBytes += s;
|
mallocBytes += s;
|
||||||
|
#else
|
||||||
|
mallocBytes += malloc_usable_size(p);
|
||||||
|
#endif
|
||||||
if (mallocBytes > peakMallocBytes) {
|
if (mallocBytes > peakMallocBytes) {
|
||||||
peakMallocBytes = mallocBytes;
|
peakMallocBytes = mallocBytes;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (void *p = malloc(s)) {
|
return p;
|
||||||
return p;
|
|
||||||
}
|
|
||||||
abort();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// There's nothing safer about this than free. Only called safe_free for
|
// There's nothing safer about this than free. Only called safe_free for
|
||||||
@@ -68,6 +75,8 @@ __attribute__((always_inline)) inline void safe_free(void *p) {
|
|||||||
#if SHOW_MEMORY
|
#if SHOW_MEMORY
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
mallocBytes -= malloc_size(p);
|
mallocBytes -= malloc_size(p);
|
||||||
|
#else
|
||||||
|
mallocBytes -= malloc_usable_size(p);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
free(p);
|
free(p);
|
||||||
|
Reference in New Issue
Block a user