merge from dev

This commit is contained in:
daan 2019-07-22 10:16:59 -07:00
commit 80e09ef44e
14 changed files with 46 additions and 32 deletions

View file

@ -117,6 +117,9 @@ bool _mi_page_is_valid(mi_page_t* page);
#define mi_likely(x) (x)
#endif
#ifndef __has_builtin
#define __has_builtin(x) 0
#endif
#if defined(_MSC_VER)
#define mi_decl_noinline __declspec(noinline)
@ -149,9 +152,17 @@ bool _mi_page_is_valid(mi_page_t* page);
// Overflow detecting multiply
#define MI_MUL_NO_OVERFLOW ((size_t)1 << (4*sizeof(size_t))) // sqrt(SIZE_MAX)
static inline bool mi_mul_overflow(size_t size, size_t count, size_t* total) {
#if __has_builtin(__builtin_umul_overflow) || __GNUC__ >= 5
#if (MI_INTPTR_SIZE == 4)
return __builtin_umul_overflow(size, count, total);
#else
return __builtin_umull_overflow(size, count, total);
#endif
#else /* __builtin_umul_overflow is unavailable */
*total = size * count;
return ((size >= MI_MUL_NO_OVERFLOW || count >= MI_MUL_NO_OVERFLOW)
&& size > 0 && (SIZE_MAX / size) < count);
#endif
}
// Align a byte size to a size in _machine words_,

View file

@ -8,7 +8,6 @@ terms of the MIT license. A copy of the license can be found in the file
#ifndef MIMALLOC_TYPES_H
#define MIMALLOC_TYPES_H
#include <stdlib.h> // size_t etc.
#include <stddef.h> // ptrdiff_t
#include <stdint.h> // uintptr_t, uint16_t, etc

View file

@ -69,7 +69,6 @@ terms of the MIT license. A copy of the license can be found in the file
// Includes
// ------------------------------------------------------
#include <stdlib.h> // size_t, malloc etc.
#include <stdbool.h> // bool
#include <stdio.h> // FILE