Add internal M_UNLIKELY_NOMEM to help coverage computation

This commit is contained in:
Patrick Pelissier committed 2023-04-03 00:05:29 +02:00
1 parent 6976d4e23d
commit 7534aa0d61
18 files changed
+72 -64

No files matched your search

+14 -14
View File
@@ -246,7 +246,7 @@
if (s->size > d->alloc) { \
const size_t alloc = s->size; \
type *ptr = M_CALL_REALLOC(oplist, type, d->ptr, alloc); \
if (M_UNLIKELY (ptr == NULL)) { \
if (M_UNLIKELY_NOMEM (ptr == NULL)) { \
M_MEMORY_FULL(sizeof (type) * alloc); \
return ; \
} \
@@ -323,13 +323,13 @@
if (M_UNLIKELY (v->size >= v->alloc)) { \
M_ASSERT(v->size == v->alloc); \
size_t alloc = M_CALL_INC_ALLOC(oplist, v->alloc); \
if (M_UNLIKELY (alloc <= v->alloc)) { \
if (M_UNLIKELY_NOMEM (alloc <= v->alloc)) { \
M_MEMORY_FULL(sizeof (type) * alloc); \
return NULL; \
} \
M_ASSERT (alloc > v->size); \
type *ptr = M_CALL_REALLOC(oplist, type, v->ptr, alloc); \
if (M_UNLIKELY (ptr == NULL) ) { \
if (M_UNLIKELY_NOMEM (ptr == NULL) ) { \
M_MEMORY_FULL(sizeof (type) * alloc); \
return NULL; \
} \
@@ -388,13 +388,13 @@
if (M_UNLIKELY (v->size >= v->alloc) ) { \
M_ASSERT(v->size == v->alloc); \
size_t alloc = M_CALL_INC_ALLOC(oplist, v->alloc); \
if (M_UNLIKELY (alloc <= v->alloc)) { \
if (M_UNLIKELY_NOMEM (alloc <= v->alloc)) { \
M_MEMORY_FULL(sizeof (type) * alloc); \
return ; \
} \
M_ASSERT (alloc > v->size); \
type *ptr = M_CALL_REALLOC(oplist, type, v->ptr, alloc); \
if (M_UNLIKELY (ptr == NULL) ) { \
if (M_UNLIKELY_NOMEM (ptr == NULL) ) { \
M_MEMORY_FULL(sizeof (type) * alloc); \
return; \
} \
@@ -424,7 +424,7 @@
if (size > v->alloc) { \
size_t alloc = size ; \
type *ptr = M_CALL_REALLOC(oplist, type, v->ptr, alloc); \
if (M_UNLIKELY (ptr == NULL) ) { \
if (M_UNLIKELY_NOMEM (ptr == NULL) ) { \
M_MEMORY_FULL(sizeof (type) * alloc); \
return; \
} \
@@ -453,7 +453,7 @@
v->ptr = NULL; \
} else { \
type *ptr = M_CALL_REALLOC(oplist, type, v->ptr, alloc); \
if (M_UNLIKELY (ptr == NULL) ) { \
if (M_UNLIKELY_NOMEM (ptr == NULL) ) { \
M_MEMORY_FULL(sizeof (type) * alloc); \
return; \
} \
@@ -475,12 +475,12 @@
if (M_UNLIKELY (size > v->alloc) ) { \
size_t alloc = M_CALL_INC_ALLOC(oplist, size) ; \
/* In case of overflow of size_t */ \
if (M_UNLIKELY (alloc <= v->alloc)) { \
if (M_UNLIKELY_NOMEM (alloc <= v->alloc)) { \
M_MEMORY_FULL(sizeof (type) * alloc); \
return NULL; \
} \
type *ptr = M_CALL_REALLOC(oplist, type, v->ptr, alloc); \
if (M_UNLIKELY (ptr == NULL) ) { \
if (M_UNLIKELY_NOMEM (ptr == NULL) ) { \
M_MEMORY_FULL(sizeof (type) * alloc); \
return NULL; \
} \
@@ -594,7 +594,7 @@
M_ASSERT_INDEX(i, v->size+1); \
size_t size = v->size + num; \
/* Test for overflow of variable size */ \
if (M_UNLIKELY (size <= v->size)) { \
if (M_UNLIKELY_NOMEM (size <= v->size)) { \
/* Unlikely case of nothing to do */ \
if (num == 0) return; \
M_MEMORY_FULL(sizeof (type) * v->size); \
@@ -603,12 +603,12 @@
/* Test if alloc array is sufficient */ \
if (size > v->alloc) { \
size_t alloc = M_CALL_INC_ALLOC(oplist, size) ; \
if (M_UNLIKELY (alloc <= v->alloc)) { \
if (M_UNLIKELY_NOMEM (alloc <= v->alloc)) { \
M_MEMORY_FULL(sizeof (type) * alloc); \
return ; \
} \
type *ptr = M_CALL_REALLOC(oplist, type, v->ptr, alloc); \
if (M_UNLIKELY (ptr == NULL) ) { \
if (M_UNLIKELY_NOMEM (ptr == NULL) ) { \
M_MEMORY_FULL(sizeof (type) * alloc); \
return; \
} \
@@ -895,7 +895,7 @@
return; \
/* NOTE: if size is <= 4, no need to perform an allocation */ \
type *temp = M_CALL_REALLOC(oplist, type, NULL, l->size); \
if (temp == NULL) { \
if (M_UNLIKELY_NOMEM (temp == NULL)) { \
M_MEMORY_FULL(sizeof (type) * l->size); \
return ; \
} \
@@ -952,7 +952,7 @@
M_ASSERT(newSize > a1->size); \
if (newSize > a1->alloc) { \
type *ptr = M_CALL_REALLOC(oplist, type, a1->ptr, newSize); \
if (M_UNLIKELY (ptr == NULL) ) { \
if (M_UNLIKELY_NOMEM (ptr == NULL) ) { \
M_MEMORY_FULL(sizeof (type) * newSize); \
} \
a1->ptr = ptr; \
+6 -6
View File
@@ -125,7 +125,7 @@ m_bitset_set(m_bitset_t d, const m_bitset_t s)
// Test if enough space in target
if (s->size > M_B1TSET_FROM_ALLOC (d->alloc)) {
m_b1tset_limb_ct *ptr = M_MEMORY_REALLOC (m_b1tset_limb_ct, d->ptr, needAlloc);
if (M_UNLIKELY (ptr == NULL)) {
if (M_UNLIKELY_NOMEM (ptr == NULL)) {
M_MEMORY_FULL(needAlloc);
return ;
}
@@ -208,14 +208,14 @@ m_bitset_push_back (m_bitset_t v, bool x)
// Compute the needed allocation.
const size_t needAlloc = M_B1TSET_INC_ALLOC_SIZE(v->alloc);
// Check for integer overflow
if (M_UNLIKELY (needAlloc <= v->alloc)) {
if (M_UNLIKELY_NOMEM (needAlloc <= v->alloc)) {
M_MEMORY_FULL(needAlloc * sizeof(m_b1tset_limb_ct));
return;
}
// Alloc memory
m_b1tset_limb_ct *ptr = M_MEMORY_REALLOC (m_b1tset_limb_ct, v->ptr, needAlloc);
// Check if success
if (M_UNLIKELY (ptr == NULL) ) {
if (M_UNLIKELY_NOMEM (ptr == NULL) ) {
M_MEMORY_FULL(needAlloc * sizeof(m_b1tset_limb_ct));
return;
}
@@ -244,7 +244,7 @@ m_bitset_resize (m_bitset_t v, size_t size)
{
M_B1TSET_CONTRACT (v);
// Check for overflow
if (M_UNLIKELY (size >= ((size_t)-1) - M_B1TSET_LIMB_BIT)) {
if (M_UNLIKELY_NOMEM (size >= ((size_t)-1) - M_B1TSET_LIMB_BIT)) {
M_MEMORY_FULL((size_t) -1);
return;
}
@@ -253,7 +253,7 @@ m_bitset_resize (m_bitset_t v, size_t size)
if (newAlloc > v->alloc) {
// Allocate more limbs to store the bitset.
m_b1tset_limb_ct *ptr = M_MEMORY_REALLOC (m_b1tset_limb_ct, v->ptr, newAlloc);
if (M_UNLIKELY (ptr == NULL) ) {
if (M_UNLIKELY_NOMEM (ptr == NULL) ) {
M_MEMORY_FULL(newAlloc * sizeof(m_b1tset_limb_ct));
return;
}
@@ -305,7 +305,7 @@ m_bitset_reserve (m_bitset_t v, size_t alloc)
} else {
// Allocate more memory or reduce memory usage
m_b1tset_limb_ct *ptr = M_MEMORY_REALLOC (m_b1tset_limb_ct, v->ptr, newAlloc);
if (M_UNLIKELY (ptr == NULL) ) {
if (M_UNLIKELY_NOMEM (ptr == NULL) ) {
M_MEMORY_FULL(newAlloc * sizeof(m_b1tset_limb_ct));
return;
}
+1 -1
View File
@@ -417,7 +417,7 @@
M_STATIC_ASSERT(N >= 2, M_LIB_ILLEGAL_PARAM, \
"Number of items per node shall be >= 2."); \
node_t n = M_CALL_NEW(key_oplist, struct M_C(name, _node_s)); \
if (M_UNLIKELY (n == NULL)) { \
if (M_UNLIKELY_NOMEM (n == NULL)) { \
M_MEMORY_FULL(sizeof (node_t)); \
M_ASSERT (0); \
} \
+3 -3
View File
@@ -320,7 +320,7 @@ M_C(name, _init)(buffer_t v, size_t size) \
\
M_BUFF3R_IF_CTE_SIZE(m_size)( /* Statically allocated */ , \
v->data = M_CALL_REALLOC(oplist, M_C(name, _el_ct), NULL, M_BUFF3R_SIZE(m_size)); \
if (v->data == NULL) { \
if (M_UNLIKELY_NOMEM (v->data == NULL)) { \
M_MEMORY_FULL (M_BUFF3R_SIZE(m_size)*sizeof(M_C(name, _el_ct))); \
return; \
} \
@@ -907,7 +907,7 @@ M_C(name, _init)(buffer_t v, size_t size) \
atomic_init(&buffer->ConsoIdx, (unsigned int) size); \
buffer->size = (unsigned int) size; \
buffer->Tab = M_CALL_REALLOC(oplist, M_C(name, _el_ct), NULL, size); \
if (buffer->Tab == NULL) { \
if (M_UNLIKELY_NOMEM (buffer->Tab == NULL)) { \
M_MEMORY_FULL (size*sizeof(M_C(name, _el_ct) )); \
return; \
} \
@@ -1249,7 +1249,7 @@ M_C(name, _init)(buffer_t v, size_t size) \
atomic_init(&buffer->consoIdx, (unsigned int) size); \
buffer->size = (unsigned int) size; \
buffer->Tab = M_CALL_REALLOC(oplist, M_C(name, _el_ct), NULL, size); \
if (buffer->Tab == NULL) { \
if (M_UNLIKELY_NOMEM (buffer->Tab == NULL)) { \
M_MEMORY_FULL (size*sizeof(M_C(name, _el_ct) )); \
return; \
} \
+5 -5
View File
@@ -311,7 +311,7 @@ M_BEGIN_PROTECTED_CODE
{ \
M_C(name, _lf_node_t) * node; \
node = M_MEMORY_ALLOC(M_C(name, _lf_node_t)); \
if (M_UNLIKELY(node == NULL)) { \
if (M_UNLIKELY_NOMEM (node == NULL)) { \
M_MEMORY_FULL(sizeof(M_C(name, _lf_node_t))); \
return NULL; \
} \
@@ -321,7 +321,7 @@ M_BEGIN_PROTECTED_CODE
for(unsigned i = 0; i < initial; i++) { \
M_C(name, _slist_node_ct) *n; \
n = M_MEMORY_ALLOC(M_C(name, _slist_node_ct)); \
if (M_UNLIKELY(n == NULL)) { \
if (M_UNLIKELY_NOMEM (n == NULL)) { \
M_MEMORY_FULL(sizeof(M_C(name, _lf_node_t))); \
return NULL; \
} \
@@ -465,7 +465,7 @@ M_BEGIN_PROTECTED_CODE
const size_t max_thread = gc_mem->max_thread; \
/* Initialize the thread data of the mempool */ \
mem->thread_data = M_MEMORY_REALLOC(M_C(name, _lfmp_thread_ct), NULL, max_thread); \
if (mem->thread_data == NULL) { \
if (M_UNLIKELY_NOMEM (mem->thread_data == NULL)) { \
M_MEMORY_FULL(max_thread * sizeof(M_C(name, _lfmp_thread_ct))); \
return; \
} \
@@ -588,7 +588,7 @@ m_gc_init(m_gc_t gc_mem, size_t max_thread)
atomic_init(&gc_mem->ticket, 0UL);
m_genint_init(gc_mem->thread_alloc, (unsigned int) max_thread);
gc_mem->thread_data = M_MEMORY_REALLOC(m_gc_lfmp_thread_ct, NULL, max_thread);
if (gc_mem->thread_data == NULL) {
if (M_UNLIKELY_NOMEM (gc_mem->thread_data == NULL)) {
M_MEMORY_FULL(max_thread * sizeof(m_gc_lfmp_thread_ct));
return;
}
@@ -758,7 +758,7 @@ m_vlapool_init(m_vlapool_t mem, m_gc_t gc_mem)
/* Initialize the thread data of the vlapool */
mem->thread_data = M_MEMORY_REALLOC(m_vlapool_lfmp_thread_ct, NULL, max_thread);
if (mem->thread_data == NULL) {
if (M_UNLIKELY_NOMEM (mem->thread_data == NULL)) {
M_MEMORY_FULL(max_thread * sizeof(m_vlapool_lfmp_thread_ct));
return;
}
+5
View File
@@ -425,6 +425,11 @@ M_BEGIN_PROTECTED_CODE
#endif
/* M_UNLIKELY used to test conditions that will trigger memory errors.
It is needed so that it can be disabled in coverage mode. */
#define M_UNLIKELY_NOMEM(cond) M_UNLIKELY(cond)
/***************************************************************/
/****************** Preprocessing Times Macro ******************/
/***************************************************************/
+2 -2
View File
@@ -175,7 +175,7 @@
{ \
size_t def = d->default_size; \
/* Test for overflow of the size computation */ \
if (M_UNLIKELY (def > SIZE_MAX / sizeof (type) - sizeof(node_t))) { \
if (M_UNLIKELY_NOMEM (def > SIZE_MAX / sizeof (type) - sizeof(node_t))) { \
M_MEMORY_FULL(sizeof(node_t)+def * sizeof(type)); \
return NULL; \
} \
@@ -183,7 +183,7 @@
node_t*n = (node_t*) (void*) \
M_CALL_REALLOC(oplist, char, NULL, \
sizeof(node_t) + def * sizeof(type) ); \
if (n==NULL) { \
if (M_UNLIKELY_NOMEM (n==NULL)) { \
M_MEMORY_FULL(sizeof(node_t)+def * sizeof(type)); \
return NULL; \
} \
+7 -7
View File
@@ -454,7 +454,7 @@
/* NOTE: Contract may not be fulfilled here */ \
size_t old_size = M_C(name, _array_list_pair_size)(map->table); \
size_t new_size = old_size * 2; \
if (M_UNLIKELY (new_size <= old_size)) { \
if (M_UNLIKELY_NOMEM (new_size <= old_size)) { \
M_MEMORY_FULL((size_t)-1); \
} \
M_ASSERT (old_size > 1 && new_size > 1); \
@@ -1312,7 +1312,7 @@ enum m_d1ct_oa_element_e {
dict->count_delete = 0; \
M_C3(m_d1ct_,name,_update_limit)(dict, M_D1CT_INITIAL_SIZE); \
dict->data = M_CALL_REALLOC(key_oplist, M_C(name, _pair_ct), NULL, M_D1CT_INITIAL_SIZE); \
if (dict->data == NULL) { \
if (M_UNLIKELY_NOMEM (dict->data == NULL)) { \
M_MEMORY_FULL(sizeof (M_C(name, _pair_ct)) * M_D1CT_INITIAL_SIZE); \
return ; \
} \
@@ -1407,7 +1407,7 @@ enum m_d1ct_oa_element_e {
/* resize can be called just to delete the items */ \
if (newSize > oldSize) { \
data = M_CALL_REALLOC(key_oplist, M_C(name, _pair_ct), data, newSize); \
if (M_UNLIKELY (data == NULL) ) { \
if (M_UNLIKELY_NOMEM (data == NULL) ) { \
M_MEMORY_FULL(sizeof (M_C(name, _pair_ct)) * newSize); \
return ; \
} \
@@ -1526,7 +1526,7 @@ enum m_d1ct_oa_element_e {
size_t newSize = dict->mask+1; \
if (dict->count > (dict->mask / 2)) { \
newSize += newSize; \
if (M_UNLIKELY (newSize <= dict->mask+1)) { \
if (M_UNLIKELY_NOMEM (newSize <= dict->mask+1)) { \
M_MEMORY_FULL((size_t)-1); \
} \
} \
@@ -1580,7 +1580,7 @@ enum m_d1ct_oa_element_e {
size_t newSize = dict->mask+1; \
if (dict->count > (dict->mask / 2)) { \
newSize += newSize; \
if (M_UNLIKELY (newSize <= dict->mask+1)) { \
if (M_UNLIKELY_NOMEM (newSize <= dict->mask+1)) { \
M_MEMORY_FULL((size_t)-1); \
} \
} \
@@ -1722,7 +1722,7 @@ enum m_d1ct_oa_element_e {
map->upper_limit = org->upper_limit; \
map->lower_limit = org->lower_limit; \
map->data = M_CALL_REALLOC(key_oplist, M_C(name, _pair_ct), NULL, map->mask+1); \
if (map->data == NULL) { \
if (M_UNLIKELY_NOMEM (map->data == NULL)) { \
M_MEMORY_FULL(sizeof (M_C(name, _pair_ct)) * (map->mask+1)); \
return ; \
} \
@@ -1958,7 +1958,7 @@ enum m_d1ct_oa_element_e {
that no reallocation of the hash map occurs up to capacity */ \
size = (size_t) m_core_roundpow2 ((uint64_t) ((double) capacity * (1.0 / coeff_up))); \
/* Test for overflow of the computation */ \
if (M_UNLIKELY (size < capacity)) { \
if (M_UNLIKELY_NOMEM (size < capacity)) { \
M_MEMORY_FULL((size_t)-1); \
} \
M_ASSERT (M_POWEROF2_P(size)); \
+1 -1
View File
@@ -110,7 +110,7 @@ m_genint_init(m_genint_t s, unsigned int n)
const size_t alloc = (n + M_GEN1NT_LIMBSIZE - 1) / M_GEN1NT_LIMBSIZE;
const unsigned int index = n % M_GEN1NT_LIMBSIZE;
atomic_ullong *ptr = M_MEMORY_REALLOC (atomic_ullong, NULL, alloc);
if (M_UNLIKELY (ptr == NULL)) {
if (M_UNLIKELY_NOMEM (ptr == NULL)) {
M_MEMORY_FULL(alloc);
return;
}
+1 -1
View File
@@ -531,7 +531,7 @@ typedef struct m_il1st_head_s {
M_IL1ST_CONTRACT(name, list); \
M_IL1ST_NODE_CONTRACT(it->current); \
type *p = M_CALL_NEW(oplist, type); \
if (M_UNLIKELY (p == NULL)) { \
if (M_UNLIKELY_NOMEM (p == NULL)) { \
M_MEMORY_FULL (sizeof (type)); \
return ; \
} \
+1 -1
View File
@@ -194,7 +194,7 @@ M_BEGIN_PROTECTED_CODE
M_C(name, _init_new)(void) \
{ \
type *ptr = M_CALL_NEW(oplist, type); \
if (ptr == NULL) { \
if (M_UNLIKELY_NOMEM (ptr == NULL)) { \
M_MEMORY_FULL(sizeof(type)); \
return NULL; \
} \
+7 -7
View File
@@ -276,7 +276,7 @@
M_L1ST_CONTRACT(v); \
struct M_C(name, _s) *next; \
next = M_C3(m_l1st_,name,_new)(); \
if (M_UNLIKELY (next == NULL)) { \
if (M_UNLIKELY_NOMEM (next == NULL)) { \
M_MEMORY_FULL(sizeof (struct M_C(name, _s))); \
return NULL; \
} \
@@ -491,7 +491,7 @@
M_ASSERT (insertion_point != NULL); \
M_ASSERT(M_C(name, _sublist_p)(list, insertion_point)); \
struct M_C(name, _s) *next = M_C3(m_l1st_,name,_new)(); \
if (M_UNLIKELY (next == NULL)) { \
if (M_UNLIKELY_NOMEM (next == NULL)) { \
M_MEMORY_FULL(sizeof (struct M_C(name, _s))); \
return; \
} \
@@ -539,7 +539,7 @@
while (it_org != NULL) { \
next = M_C3(m_l1st_,name,_new)(); \
*update_list = next; \
if (M_UNLIKELY (next == NULL)) { \
if (M_UNLIKELY_NOMEM (next == NULL)) { \
M_MEMORY_FULL(sizeof (struct M_C(name, _s))); \
/* FIXME: Partialy initialized list. What to do? */ \
return; \
@@ -1028,7 +1028,7 @@
{ \
M_L1ST_DUAL_PUSH_CONTRACT(v); \
struct M_C(name, _s) *next = M_C3(m_l1st_,name,_new)(); \
if (M_UNLIKELY (next == NULL)) { \
if (M_UNLIKELY_NOMEM (next == NULL)) { \
M_MEMORY_FULL(sizeof (struct M_C(name, _s))); \
return NULL; \
} \
@@ -1140,7 +1140,7 @@
{ \
M_L1ST_DUAL_PUSH_CONTRACT(v); \
struct M_C(name, _s) *next = M_C3(m_l1st_,name,_new)(); \
if (M_UNLIKELY (next == NULL)) { \
if (M_UNLIKELY_NOMEM (next == NULL)) { \
M_MEMORY_FULL(sizeof (struct M_C(name, _s))); \
return NULL; \
} \
@@ -1294,7 +1294,7 @@
M_L1ST_DUAL_PUSH_CONTRACT(list); \
M_ASSERT (insertion_point != NULL); \
struct M_C(name, _s) *next = M_C3(m_l1st_,name,_new)(); \
if (M_UNLIKELY (next == NULL)) { \
if (M_UNLIKELY_NOMEM (next == NULL)) { \
M_MEMORY_FULL(sizeof (struct M_C(name, _s))); \
return; \
} \
@@ -1354,7 +1354,7 @@
while (it_org != NULL) { \
next = M_C3(m_l1st_,name,_new)(); \
*update_list = next; \
if (M_UNLIKELY (next == NULL)) { \
if (M_UNLIKELY_NOMEM (next == NULL)) { \
M_MEMORY_FULL(sizeof (struct M_C(name, _s))); \
return; \
} \
+3 -3
View File
@@ -209,7 +209,7 @@ static inline int m_shar3d_integer_cref(int *p) { return *p; }
return; \
} \
ptr = M_CALL_NEW(oplist, struct M_C(name, _s)); \
if (M_UNLIKELY (ptr == NULL)) { \
if (M_UNLIKELY_NOMEM (ptr == NULL)) { \
M_MEMORY_FULL(sizeof(struct M_C(name, _s))); \
return; \
} \
@@ -227,7 +227,7 @@ static inline int m_shar3d_integer_cref(int *p) { return *p; }
/* NOTE: Alloc 1 struct with both structures. */ \
struct M_C(name, combine_s) *p = \
M_CALL_NEW(oplist, struct M_C(name, combine_s)); \
if (M_UNLIKELY (p == NULL)) { \
if (M_UNLIKELY_NOMEM (p == NULL)) { \
M_MEMORY_FULL(sizeof(struct M_C(name, combine_s))); \
return; \
} \
@@ -419,7 +419,7 @@ static inline int m_shar3d_integer_cref(int *p) { return *p; }
M_ASSERT(s != NULL); \
M_ASSERT (n > 0 && n < UINT_MAX); \
s->buffer = M_CALL_REALLOC(oplist, M_C(name, _atype_ct), NULL, n); \
if (M_UNLIKELY (s->buffer == NULL)) { \
if (M_UNLIKELY_NOMEM (s->buffer == NULL)) { \
M_MEMORY_FULL(sizeof(M_C(name, _atype_ct)) * n); \
return; \
} \
+2 -2
View File
@@ -392,7 +392,7 @@ m_snapsh0t_mrsw_init(m_snapsh0t_mrsw_ct s, size_t n)
// Initialize the counters to zero (no reader use it)
atomic_uint *ptr = M_MEMORY_REALLOC (atomic_uint, NULL, n);
if (M_UNLIKELY (ptr == NULL)) {
if (M_UNLIKELY_NOMEM (ptr == NULL)) {
M_MEMORY_FULL(sizeof (atomic_uint) * n);
return;
}
@@ -646,7 +646,7 @@ m_snapsh0t_mrsw_read_end(m_snapsh0t_mrsw_ct s, unsigned int idx)
M_ASSERT (nReader > 0 && nReader <= M_SNAPSH0T_SPMC_MAX_READER); \
snap->data = M_CALL_REALLOC(oplist, M_C(name, _aligned_type_ct), \
NULL, nReader+M_SNAPSH0T_SPMC_EXTRA_BUFFER); \
if (M_UNLIKELY (snap->data == NULL)) { \
if (M_UNLIKELY_NOMEM (snap->data == NULL)) { \
M_MEMORY_FULL(sizeof(M_C(name, _aligned_type_ct)) * \
(nReader+M_SNAPSH0T_SPMC_EXTRA_BUFFER)); \
return; \
+4 -4
View File
@@ -257,7 +257,7 @@ m_string_clear_get_cstr(m_string_t v)
// Need to allocate a heap string to return the copy.
size_t alloc = m_string_size(v)+1;
char *ptr = M_MEMORY_REALLOC (char, NULL, alloc);
if (M_UNLIKELY (ptr == NULL)) {
if (M_UNLIKELY_NOMEM (ptr == NULL)) {
M_MEMORY_FULL(sizeof (char) * alloc);
return NULL;
}
@@ -326,7 +326,7 @@ m_str1ng_fit2size (m_string_t v, size_t size_alloc)
// Insufficient current allocation to store the new string
// Perform an allocation on the heap.
size_t alloc = size_alloc + size_alloc / 2;
if (M_UNLIKELY (alloc <= old_alloc)) {
if (M_UNLIKELY_NOMEM (alloc <= old_alloc)) {
/* Overflow in alloc computation */
M_MEMORY_FULL(sizeof (char) * alloc);
// NOTE: Return is currently broken.
@@ -334,7 +334,7 @@ m_str1ng_fit2size (m_string_t v, size_t size_alloc)
return NULL;
}
char *ptr = M_MEMORY_REALLOC (char, v->ptr, alloc);
if (M_UNLIKELY (ptr == NULL)) {
if (M_UNLIKELY_NOMEM (ptr == NULL)) {
M_MEMORY_FULL(sizeof (char) * alloc);
// NOTE: Return is currently broken.
abort();
@@ -390,7 +390,7 @@ m_string_reserve(m_string_t v, size_t alloc)
// If the string is stack allocated, v->ptr is NULL
// and it will therefore perform the initial allocation
char *ptr = M_MEMORY_REALLOC (char, v->ptr, alloc);
if (M_UNLIKELY (ptr == NULL) ) {
if (M_UNLIKELY_NOMEM (ptr == NULL) ) {
M_MEMORY_FULL(sizeof (char) * alloc);
return;
}
+5 -5
View File
@@ -259,7 +259,7 @@ typedef int32_t m_tr33_index_t;
return; \
} \
/* Realloc the array */ \
if (M_UNLIKELY (alloc >= INT32_MAX)) { \
if (M_UNLIKELY_NOMEM (alloc >= INT32_MAX)) { \
M_MEMORY_FULL(sizeof (struct M_C(name, _node_s)) * alloc); \
return; \
} \
@@ -269,7 +269,7 @@ typedef int32_t m_tr33_index_t;
M_TR33_NO_NODE in some cases, performing branchless code. */ \
struct M_C(name,_node_s)*ptr = tree->tab == NULL ? NULL : tree->tab-1;\
ptr = M_CALL_REALLOC(oplist, struct M_C(name, _node_s), ptr, alloc+1);\
if (M_UNLIKELY (ptr == NULL) ) { \
if (M_UNLIKELY_NOMEM (ptr == NULL) ) { \
M_MEMORY_FULL(sizeof (struct M_C(name, _node_s)) * alloc); \
return; \
} \
@@ -313,7 +313,7 @@ typedef int32_t m_tr33_index_t;
size_t alloc = M_CALL_INC_ALLOC(oplist, (size_t) tree->capacity); \
/* Take into account if realloc is allowed */ \
alloc += tree->allow_realloc; \
if (M_UNLIKELY (alloc >= INT32_MAX)) { \
if (M_UNLIKELY_NOMEM (alloc >= INT32_MAX)) { \
M_MEMORY_FULL(sizeof (struct M_C(name, _node_s)) * alloc); \
return M_TR33_NO_NODE; \
} \
@@ -323,7 +323,7 @@ typedef int32_t m_tr33_index_t;
M_TR33_NO_NODE in some cases, performing branchless code. */ \
struct M_C(name,_node_s)*ptr = tree->tab == NULL ? NULL : tree->tab-1; \
ptr = M_CALL_REALLOC(oplist, struct M_C(name, _node_s), ptr, alloc+1); \
if (M_UNLIKELY (ptr == NULL) ) { \
if (M_UNLIKELY_NOMEM (ptr == NULL) ) { \
M_MEMORY_FULL(sizeof (struct M_C(name, _node_s)) * alloc); \
return M_TR33_NO_NODE; \
} \
@@ -1122,7 +1122,7 @@ typedef int32_t m_tr33_index_t;
} else { \
struct M_C(name, _node_s) *ptr = \
M_CALL_REALLOC(oplist, struct M_C(name, _node_s), NULL, alloc+1); \
if (M_UNLIKELY (ptr == NULL) ) { \
if (M_UNLIKELY_NOMEM (ptr == NULL) ) { \
M_MEMORY_FULL(sizeof(struct M_C(name, _node_s)) * alloc); \
return; \
} \
+2 -2
View File
@@ -265,7 +265,7 @@ typedef struct m_worker_sync_s {
{ \
if (!m_work3r_queue_full_p(block->worker->queue_g)) { \
struct M_C3(m_worker_, name, _s) *p = M_MEMORY_ALLOC ( struct M_C3(m_worker_, name, _s)); \
if (M_UNLIKELY(p == NULL)) { \
if (M_UNLIKELY_NOMEM(p == NULL)) { \
M_MEMORY_FULL(sizeof (struct M_C3(m_worker_, name, _s))); \
} \
p->callback = callback; \
@@ -410,7 +410,7 @@ m_worker_init(m_worker_t g, int numWorker, unsigned int extraQueue, void (*reset
M_ASSERT(numWorker >= 0);
size_t numWorker_st = (size_t) numWorker;
g->worker = M_MEMORY_REALLOC(m_work3r_thread_ct, NULL, numWorker_st);
if (g->worker == NULL) {
if (M_UNLIKELY_NOMEM (g->worker == NULL)) {
M_MEMORY_FULL(sizeof (m_work3r_thread_ct) * numWorker_st);
return;
}
+3
View File
@@ -124,6 +124,9 @@
#define M_TR33_CONTRACT(...) (void)0
#undef M_TR33_IT_CONTRACT
#define M_TR33_IT_CONTRACT(...) (void)0
/* Overwrite M_UNLIKELY_NOMEM so that it can never fails, to avoid spurious coverage */
#undef M_UNLIKELY_NOMEM
#define M_UNLIKELY_NOMEM(...) 0
/* For coverage build, do not expand other likes NULL, etc. */
#undef M_STATIC_FAILURE
#undef NULL