From 1e196fe22a7be866310bf6c33cfae848bf38c3be Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sat, 21 Dec 2024 13:02:17 +0100 Subject: [PATCH] Port to new spec M_MEMORY_FULL --- m-array.h | 28 ++++++++++++++-------------- m-bitset.h | 12 ++++++------ m-bptree.h | 2 +- m-bstring.h | 4 ++-- m-buffer.h | 6 +++--- m-c-mempool.h | 10 +++++----- m-core.h | 9 +++++---- m-deque.h | 4 ++-- m-dict.h | 26 +++++++++++++------------- m-genint.h | 2 +- m-i-shared.h | 2 +- m-list.h | 14 +++++++------- m-mempool.h | 4 ++-- m-rbtree.h | 6 +++--- m-shared-ptr.h | 8 ++++---- m-shared.h | 8 ++++---- m-snapshot.h | 4 ++-- m-string.h | 10 +++++----- m-tree.h | 10 +++++----- m-try.h | 2 +- m-worker.h | 4 ++-- 21 files changed, 88 insertions(+), 87 deletions(-) diff --git a/m-array.h b/m-array.h index dcb7309b..d6d2a5e3 100644 --- a/m-array.h +++ b/m-array.h @@ -244,7 +244,7 @@ const size_t alloc = s->size; \ type *ptr = M_CALL_REALLOC(oplist, type, d->ptr, d->alloc, alloc); \ if (M_UNLIKELY_NOMEM (ptr == NULL)) { \ - M_MEMORY_FULL(sizeof (type) * alloc); \ + M_MEMORY_FULL(type, alloc); \ return ; \ } \ d->ptr = ptr; \ @@ -325,13 +325,13 @@ M_ASSERT(v->size == v->alloc); \ size_t alloc = M_CALL_INC_ALLOC(oplist, v->alloc); \ if (M_UNLIKELY_NOMEM (alloc <= v->alloc)) { \ - M_MEMORY_FULL(sizeof (type) * alloc); \ + M_MEMORY_FULL(type, alloc); \ return NULL; \ } \ M_ASSERT (alloc > v->size); \ type *ptr = M_CALL_REALLOC(oplist, type, v->ptr, v->alloc, alloc); \ if (M_UNLIKELY_NOMEM (ptr == NULL) ) { \ - M_MEMORY_FULL(sizeof (type) * alloc); \ + M_MEMORY_FULL(type, alloc); \ return NULL; \ } \ v->ptr = ptr; \ @@ -394,13 +394,13 @@ M_ASSERT(v->size == v->alloc); \ size_t alloc = M_CALL_INC_ALLOC(oplist, v->alloc); \ if (M_UNLIKELY_NOMEM (alloc <= v->alloc)) { \ - M_MEMORY_FULL(sizeof (type) * alloc); \ + M_MEMORY_FULL(type, alloc); \ return ; \ } \ M_ASSERT (alloc > v->size); \ type *ptr = M_CALL_REALLOC(oplist, type, v->ptr, v->alloc, alloc); \ if (M_UNLIKELY_NOMEM (ptr == NULL) ) { \ - M_MEMORY_FULL(sizeof (type) * alloc); \ + M_MEMORY_FULL(type, alloc); \ return; \ } \ v->ptr = ptr; \ @@ -432,7 +432,7 @@ size_t alloc = size ; \ type *ptr = M_CALL_REALLOC(oplist, type, v->ptr, v->alloc, alloc); \ if (M_UNLIKELY_NOMEM (ptr == NULL) ) { \ - M_MEMORY_FULL(sizeof (type) * alloc); \ + M_MEMORY_FULL(type, alloc); \ return; \ } \ v->ptr = ptr; \ @@ -463,7 +463,7 @@ } else { \ type *ptr = M_CALL_REALLOC(oplist, type, v->ptr, v->alloc, alloc); \ if (M_UNLIKELY_NOMEM (ptr == NULL) ) { \ - M_MEMORY_FULL(sizeof (type) * alloc); \ + M_MEMORY_FULL(type, alloc); \ return; \ } \ v->ptr = ptr; \ @@ -485,12 +485,12 @@ size_t alloc = M_CALL_INC_ALLOC(oplist, size) ; \ /* In case of overflow of size_t */ \ if (M_UNLIKELY_NOMEM (alloc <= v->alloc)) { \ - M_MEMORY_FULL(sizeof (type) * alloc); \ + M_MEMORY_FULL(type, alloc); \ return NULL; \ } \ type *ptr = M_CALL_REALLOC(oplist, type, v->ptr, v->alloc, alloc); \ if (M_UNLIKELY_NOMEM (ptr == NULL) ) { \ - M_MEMORY_FULL(sizeof (type) * alloc); \ + M_MEMORY_FULL(type, alloc); \ return NULL; \ } \ v->ptr = ptr; \ @@ -608,19 +608,19 @@ if (M_UNLIKELY_NOMEM (size <= v->size)) { \ /* Unlikely case of nothing to do */ \ if (num == 0) return; \ - M_MEMORY_FULL(sizeof (type) * v->size); \ + M_MEMORY_FULL(type, v->size); \ return ; \ } \ /* Test if alloc array is sufficient */ \ if (size > v->alloc) { \ size_t alloc = M_CALL_INC_ALLOC(oplist, size) ; \ if (M_UNLIKELY_NOMEM (alloc <= v->alloc)) { \ - M_MEMORY_FULL(sizeof (type) * alloc); \ + M_MEMORY_FULL(type, alloc); \ return ; \ } \ type *ptr = M_CALL_REALLOC(oplist, type, v->ptr, v->alloc, alloc); \ if (M_UNLIKELY_NOMEM (ptr == NULL) ) { \ - M_MEMORY_FULL(sizeof (type) * alloc); \ + M_MEMORY_FULL(type, alloc); \ return; \ } \ v->ptr = ptr; \ @@ -910,7 +910,7 @@ /* NOTE: if size is <= 4, no need to perform an allocation */ \ type *temp = M_CALL_REALLOC(oplist, type, NULL, 0, l->size); \ if (M_UNLIKELY_NOMEM (temp == NULL)) { \ - M_MEMORY_FULL(sizeof (type) * l->size); \ + M_MEMORY_FULL(type, l->size); \ return ; \ } \ M_C3(m_arra4_,name,_stable_sort_noalloc)(l->ptr, l->size, temp); \ @@ -968,7 +968,7 @@ if (newSize > a1->alloc) { \ type *ptr = M_CALL_REALLOC(oplist, type, a1->ptr, a1->alloc, newSize); \ if (M_UNLIKELY_NOMEM (ptr == NULL) ) { \ - M_MEMORY_FULL(sizeof (type) * newSize); \ + M_MEMORY_FULL(type, newSize); \ } \ a1->ptr = ptr; \ a1->alloc = newSize; \ diff --git a/m-bitset.h b/m-bitset.h index 1e32710e..0ff8a975 100644 --- a/m-bitset.h +++ b/m-bitset.h @@ -126,7 +126,7 @@ m_bitset_set(m_bitset_t d, const m_bitset_t s) if (s->size > M_B1TSET_FROM_ALLOC (d->alloc)) { m_b1tset_limb_ct *ptr = M_MEMORY_REALLOC (m_b1tset_limb_ct, d->ptr, d->alloc, needAlloc); if (M_UNLIKELY_NOMEM (ptr == NULL)) { - M_MEMORY_FULL(needAlloc); + M_MEMORY_FULL(m_b1tset_limb_ct, needAlloc); return ; } d->ptr = ptr; @@ -212,14 +212,14 @@ m_bitset_push_back (m_bitset_t v, bool x) const size_t needAlloc = M_B1TSET_INC_ALLOC_SIZE(v->alloc); // Check for integer overflow if (M_UNLIKELY_NOMEM (needAlloc <= v->alloc)) { - M_MEMORY_FULL(needAlloc * sizeof(m_b1tset_limb_ct)); + M_MEMORY_FULL(m_b1tset_limb_ct, needAlloc); return; } // Alloc memory m_b1tset_limb_ct *ptr = M_MEMORY_REALLOC (m_b1tset_limb_ct, v->ptr, v->alloc, needAlloc); // Check if success if (M_UNLIKELY_NOMEM (ptr == NULL) ) { - M_MEMORY_FULL(needAlloc * sizeof(m_b1tset_limb_ct)); + M_MEMORY_FULL(m_b1tset_limb_ct, needAlloc); return; } v->ptr = ptr; @@ -248,7 +248,7 @@ m_bitset_resize (m_bitset_t v, size_t size) M_B1TSET_CONTRACT (v); // Check for overflow if (M_UNLIKELY_NOMEM (size >= ((size_t)-1) - M_B1TSET_LIMB_BIT)) { - M_MEMORY_FULL((size_t) -1); + M_MEMORY_FULL(char, (size_t) -1); return; } // Compute the needed allocation. @@ -257,7 +257,7 @@ m_bitset_resize (m_bitset_t v, size_t size) // Allocate more limbs to store the bitset. m_b1tset_limb_ct *ptr = M_MEMORY_REALLOC (m_b1tset_limb_ct, v->ptr, v->alloc, newAlloc); if (M_UNLIKELY_NOMEM (ptr == NULL) ) { - M_MEMORY_FULL(newAlloc * sizeof(m_b1tset_limb_ct)); + M_MEMORY_FULL(m_b1tset_limb_ct, newAlloc); return; } v->ptr = ptr; @@ -309,7 +309,7 @@ m_bitset_reserve (m_bitset_t v, size_t alloc) // Allocate more memory or reduce memory usage m_b1tset_limb_ct *ptr = M_MEMORY_REALLOC (m_b1tset_limb_ct, v->ptr, v->alloc, newAlloc); if (M_UNLIKELY_NOMEM (ptr == NULL) ) { - M_MEMORY_FULL(newAlloc * sizeof(m_b1tset_limb_ct)); + M_MEMORY_FULL(m_b1tset_limb_ct, newAlloc); return; } v->ptr = ptr; diff --git a/m-bptree.h b/m-bptree.h index 83bbd50c..a99e03c9 100644 --- a/m-bptree.h +++ b/m-bptree.h @@ -412,7 +412,7 @@ "Number of items per node shall be >= 2."); \ node_t n = M_CALL_NEW(key_oplist, struct M_F(name, _node_s)); \ if (M_UNLIKELY_NOMEM (n == NULL)) { \ - M_MEMORY_FULL(sizeof (node_t)); \ + M_MEMORY_FULL(node_t, 1); \ M_ASSERT (0); \ } \ n->next = NULL; \ diff --git a/m-bstring.h b/m-bstring.h index 85d16b83..9fce5b5d 100644 --- a/m-bstring.h +++ b/m-bstring.h @@ -180,7 +180,7 @@ m_bstr1ng_fit2size (m_bstring_t v, size_t size_alloc, bool exact_alloc) } return &v->ptr[v->offset]; allocation_error: - M_MEMORY_FULL(size_alloc); + M_MEMORY_FULL(uint8_t, size_alloc); // NOTE: Return is currently broken. abort(); return NULL; @@ -409,7 +409,7 @@ m_bstring_reserve (m_bstring_t v, size_t n) } else { uint8_t *ptr = M_MEMORY_REALLOC (uint8_t, v->ptr, v->alloc, n); if (M_UNLIKELY_NOMEM (ptr == NULL)) { - M_MEMORY_FULL(n); + M_MEMORY_FULL(uint8_t, n); } // The string cannot be fully embedded anymore. v->ptr = ptr; diff --git a/m-buffer.h b/m-buffer.h index 20a3b01a..16936596 100644 --- a/m-buffer.h +++ b/m-buffer.h @@ -321,7 +321,7 @@ M_F(name, _init)(buffer_t v, size_t size) \ M_BUFF3R_IF_CTE_SIZE(m_size)( /* Statically allocated */ , \ v->data = M_CALL_REALLOC(oplist, M_F(name, _el_ct), NULL, 0, M_BUFF3R_SIZE(m_size)); \ if (M_UNLIKELY_NOMEM (v->data == NULL)) { \ - M_MEMORY_FULL (M_BUFF3R_SIZE(m_size)*sizeof(M_F(name, _el_ct))); \ + M_MEMORY_FULL (M_F(name, _el_ct), M_BUFF3R_SIZE(m_size)); \ return; \ } \ ) \ @@ -908,7 +908,7 @@ M_F(name, _init)(buffer_t v, size_t size) \ buffer->size = (unsigned int) size; \ buffer->Tab = M_CALL_REALLOC(oplist, M_F(name, _el_ct), NULL, 0, size); \ if (M_UNLIKELY_NOMEM (buffer->Tab == NULL)) { \ - M_MEMORY_FULL (size*sizeof(M_F(name, _el_ct) )); \ + M_MEMORY_FULL (M_F(name, _el_ct), size); \ return; \ } \ for(unsigned int j = 0; j < (unsigned int) size; j++) { \ @@ -1250,7 +1250,7 @@ M_F(name, _init)(buffer_t v, size_t size) \ buffer->size = (unsigned int) size; \ buffer->Tab = M_CALL_REALLOC(oplist, M_F(name, _el_ct), NULL, 0, size); \ if (M_UNLIKELY_NOMEM (buffer->Tab == NULL)) { \ - M_MEMORY_FULL (size*sizeof(M_F(name, _el_ct) )); \ + M_MEMORY_FULL (M_F(name, _el_ct), size); \ return; \ } \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_PUSH_INIT_POP_MOVE)) { \ diff --git a/m-c-mempool.h b/m-c-mempool.h index be1f3501..d065115c 100644 --- a/m-c-mempool.h +++ b/m-c-mempool.h @@ -312,7 +312,7 @@ M_BEGIN_PROTECTED_CODE M_F(name, _lf_node_t) * node; \ node = M_MEMORY_ALLOC(M_F(name, _lf_node_t)); \ if (M_UNLIKELY_NOMEM (node == NULL)) { \ - M_MEMORY_FULL(sizeof(M_F(name, _lf_node_t))); \ + M_MEMORY_FULL(M_F(name, _lf_node_t), 1); \ return NULL; \ } \ atomic_init(&node->next, (M_F(name, _lf_node_t) *) 0); \ @@ -322,7 +322,7 @@ M_BEGIN_PROTECTED_CODE M_F(name, _slist_node_ct) *n; \ n = M_MEMORY_ALLOC(M_F(name, _slist_node_ct)); \ if (M_UNLIKELY_NOMEM (n == NULL)) { \ - M_MEMORY_FULL(sizeof(M_F(name, _lf_node_t))); \ + M_MEMORY_FULL(M_F(name, _lf_node_t), 1); \ return NULL; \ } \ M_F(name, _slist_push)(node->list, n); \ @@ -466,7 +466,7 @@ M_BEGIN_PROTECTED_CODE /* Initialize the thread data of the mempool */ \ mem->thread_data = M_MEMORY_REALLOC(M_F(name, _lfmp_thread_ct), NULL, 0, max_thread); \ if (M_UNLIKELY_NOMEM (mem->thread_data == NULL)) { \ - M_MEMORY_FULL(max_thread * sizeof(M_F(name, _lfmp_thread_ct))); \ + M_MEMORY_FULL(M_F(name, _lfmp_thread_ct), max_thread); \ return; \ } \ for(unsigned i = 0; i < max_thread;i++) { \ @@ -589,7 +589,7 @@ m_gc_init(m_gc_t gc_mem, size_t max_thread) m_genint_init(gc_mem->thread_alloc, (unsigned int) max_thread); gc_mem->thread_data = M_MEMORY_REALLOC(m_gc_lfmp_thread_ct, NULL, 0, max_thread); if (M_UNLIKELY_NOMEM (gc_mem->thread_data == NULL)) { - M_MEMORY_FULL(max_thread * sizeof(m_gc_lfmp_thread_ct)); + M_MEMORY_FULL(m_gc_lfmp_thread_ct, max_thread); return; } for(unsigned i = 0; i < max_thread;i++) { @@ -759,7 +759,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, 0, max_thread); if (M_UNLIKELY_NOMEM (mem->thread_data == NULL)) { - M_MEMORY_FULL(max_thread * sizeof(m_vlapool_lfmp_thread_ct)); + M_MEMORY_FULL(m_vlapool_lfmp_thread_ct, max_thread); return; } for(unsigned i = 0; i < max_thread;i++) { diff --git a/m-core.h b/m-core.h index 65f5e0e8..1ef264d5 100644 --- a/m-core.h +++ b/m-core.h @@ -398,13 +398,14 @@ M_BEGIN_PROTECTED_CODE #endif /* This macro is called on memory allocation failure. - * By default, it raises a fatal error. + * By default, it raises a fatal error and abort execution. * NOTE: Can be overloaded by user code. */ #ifndef M_MEMORY_FULL -#define M_MEMORY_FULL(size) \ - M_RAISE_FATAL("Cannot allocate %zu bytes of memory at (%s:%s:%d).\n", \ - (size_t) (size), __FILE__, __func__, __LINE__) +#define M_MEMORY_FULL(type, number) \ + M_RAISE_FATAL("Cannot allocate %zu objects of type '%s' (size '%zu') at (%s:%s:%d).\n", \ + (size_t) (number), M_AS_STR(type), sizeof (type), \ + __FILE__, __func__, __LINE__) #endif diff --git a/m-deque.h b/m-deque.h index 54a7c898..268436ea 100644 --- a/m-deque.h +++ b/m-deque.h @@ -181,7 +181,7 @@ size_t def = d->default_size; \ /* Test for overflow of the size computation */ \ if (M_UNLIKELY_NOMEM (def > SIZE_MAX / sizeof (type) - sizeof(node_t))) { \ - M_MEMORY_FULL(sizeof(node_t)+def * sizeof(type)); \ + M_MEMORY_FULL(char, sizeof(node_t)+def * sizeof(type)); \ abort(); \ return NULL; \ } \ @@ -190,7 +190,7 @@ M_CALL_REALLOC(oplist, char, NULL, 0, \ sizeof(node_t) + def * sizeof(type) ); \ if (M_UNLIKELY_NOMEM (n==NULL)) { \ - M_MEMORY_FULL(sizeof(node_t)+def * sizeof(type)); \ + M_MEMORY_FULL(char, sizeof(node_t)+def * sizeof(type)); \ abort(); \ return NULL; \ } \ diff --git a/m-dict.h b/m-dict.h index f988a258..e7ff592d 100644 --- a/m-dict.h +++ b/m-dict.h @@ -339,14 +339,14 @@ M_ARRAY_DEF(m_array_index, m_indexhash_t, M_POD_OPLIST) /* The first 2 buckets are reserved for (empty) and (deleted) access. Allocation could be avoided */ \ map->data = M_CALL_REALLOC(key_oplist, M_F(name, _freelist_ct), NULL, 0, (size_t) 1+2+map->upper_limit); \ if (M_UNLIKELY_NOMEM (map->data == NULL)) { \ - M_MEMORY_FULL( (2+M_D1CT_INITIAL_SIZE) * sizeof (M_F(name, _freelist_ct))); \ + M_MEMORY_FULL(M_F(name, _freelist_ct), 2+M_D1CT_INITIAL_SIZE); \ return ; \ } \ map->freelist_first_data = 0; \ map->freelist_count = 2; \ map->index = M_CALL_REALLOC(key_oplist, m_indexhash_t, NULL, 0, (size_t)(0+M_D1CT_INITIAL_SIZE)); \ if (M_UNLIKELY_NOMEM (map->index == NULL)) { \ - M_MEMORY_FULL( (2+M_D1CT_INITIAL_SIZE) * sizeof (m_indexhash_t)); \ + M_MEMORY_FULL(m_indexhash_t, 2+M_D1CT_INITIAL_SIZE); \ return ; \ } \ /* Populate the initial table with the 'empty' representation which is 0 */ \ @@ -475,13 +475,13 @@ M_ARRAY_DEF(m_array_index, m_indexhash_t, M_POD_OPLIST) /*FIXME; oldsize incorrect */ \ h->data = M_CALL_REALLOC(key_oplist, M_F(name, _freelist_ct), h->data, -1, (size_t) 1+2+h->upper_limit); \ if (M_UNLIKELY_NOMEM (h->data == NULL) ) { \ - M_MEMORY_FULL((2+newSize)*sizeof (M_F(name, _freelist_ct))); \ + M_MEMORY_FULL(M_F(name, _freelist_ct), 2+newSize); \ return ; \ } \ } \ m_indexhash_t *index = M_CALL_REALLOC(key_oplist, m_indexhash_t, h->index, oldSize, (size_t)0+newSize); \ if (M_UNLIKELY_NOMEM (index == NULL) ) { \ - M_MEMORY_FULL(newSize*sizeof(m_indexhash_t)); \ + M_MEMORY_FULL(m_indexhash_t, newSize); \ return ; \ } \ h->index = index; \ @@ -655,7 +655,7 @@ M_ARRAY_DEF(m_array_index, m_indexhash_t, M_POD_OPLIST) if (map->count > newSize/2) { \ newSize += newSize; \ if (M_UNLIKELY_NOMEM (newSize <= map->mask+1)) { \ - M_MEMORY_FULL((size_t)-1); \ + M_MEMORY_FULL(char, (size_t)-1); \ } \ } \ M_C3(m_d1ct_,name,_resize_up)(map, newSize, true); \ @@ -714,7 +714,7 @@ M_ARRAY_DEF(m_array_index, m_indexhash_t, M_POD_OPLIST) if (map->count > newSize/2) { \ newSize += newSize; \ if (M_UNLIKELY_NOMEM (newSize <= map->mask+1)) { \ - M_MEMORY_FULL((size_t)-1); \ + M_MEMORY_FULL(char, (size_t)-1); \ } \ } \ M_C3(m_d1ct_,name,_resize_up)(map, newSize, true); \ @@ -972,7 +972,7 @@ M_ARRAY_DEF(m_array_index, m_indexhash_t, M_POD_OPLIST) M_ASSERT (M_POWEROF2_P(size)); \ /* Test for overflow of the computation */ \ if (M_UNLIKELY_NOMEM (size < capacity)) { \ - M_MEMORY_FULL((size_t)-1); \ + M_MEMORY_FULL(char, (size_t)-1); \ } \ if (size > dict->mask+1) { \ dict->upper_limit = (M_F(name, _index_ct)) ((double) size * M_D1CT_OA_UPPER_BOUND) - 1; \ @@ -1489,7 +1489,7 @@ enum m_d1ct_oa_element_e { M_C3(m_d1ct_,name,_update_limit)(dict, M_D1CT_INITIAL_SIZE); \ dict->data = M_CALL_REALLOC(key_oplist, M_F(name, _pair_ct), NULL, 0, M_D1CT_INITIAL_SIZE); \ if (M_UNLIKELY_NOMEM (dict->data == NULL)) { \ - M_MEMORY_FULL(sizeof (M_F(name, _pair_ct)) * M_D1CT_INITIAL_SIZE); \ + M_MEMORY_FULL(M_F(name, _pair_ct), M_D1CT_INITIAL_SIZE); \ return ; \ } \ /* Populate the initial table with the 'empty' representation */ \ @@ -1570,7 +1570,7 @@ enum m_d1ct_oa_element_e { if (newSize > oldSize) { \ data = M_CALL_REALLOC(key_oplist, M_F(name, _pair_ct), data, oldSize, newSize); \ if (M_UNLIKELY_NOMEM (data == NULL) ) { \ - M_MEMORY_FULL(sizeof (M_F(name, _pair_ct)) * newSize); \ + M_MEMORY_FULL(M_F(name, _pair_ct), newSize); \ return ; \ } \ \ @@ -1695,7 +1695,7 @@ enum m_d1ct_oa_element_e { if (dict->count > (dict->mask / 2)) { \ newSize += newSize; \ if (M_UNLIKELY_NOMEM (newSize <= dict->mask+1)) { \ - M_MEMORY_FULL((size_t)-1); \ + M_MEMORY_FULL(char, (size_t)-1); \ } \ } \ M_C3(m_d1ct_,name,_resize_up)(dict, newSize, true); \ @@ -1749,7 +1749,7 @@ enum m_d1ct_oa_element_e { if (dict->count > (dict->mask / 2)) { \ newSize += newSize; \ if (M_UNLIKELY_NOMEM (newSize <= dict->mask+1)) { \ - M_MEMORY_FULL((size_t)-1); \ + M_MEMORY_FULL(char, (size_t)-1); \ } \ } \ M_C3(m_d1ct_,name,_resize_up)(dict, newSize, true); \ @@ -2114,7 +2114,7 @@ M_F(name, _bulk_set)(dict_t dict, unsigned n, value_type const val[M_VLA(n)], ke if (dict->count > (dict->mask / 2)) { \ newSize += newSize; \ if (M_UNLIKELY_NOMEM (newSize <= dict->mask+1)) { \ - M_MEMORY_FULL((size_t)-1); \ + M_MEMORY_FULL(char, (size_t)-1); \ } \ } \ M_C3(m_d1ct_,name,_resize_up)(dict, newSize, true); \ @@ -2177,7 +2177,7 @@ M_F(name, _bulk_update)(dict_t dict, unsigned n, value_type val[M_VLA(n)], key_t if (dict->count > (dict->mask / 2)) { \ newSize += newSize; \ if (M_UNLIKELY_NOMEM (newSize <= dict->mask+1)) { \ - M_MEMORY_FULL((size_t)-1); \ + M_MEMORY_FULL(char, (size_t)-1); \ } \ } \ M_C3(m_d1ct_,name,_resize_up)(dict, newSize, true); \ diff --git a/m-genint.h b/m-genint.h index 1bacf991..2c4e1f19 100644 --- a/m-genint.h +++ b/m-genint.h @@ -111,7 +111,7 @@ m_genint_init(m_genint_t s, unsigned int n) const unsigned int index = n % M_GEN1NT_LIMBSIZE; atomic_ullong *ptr = M_MEMORY_REALLOC (atomic_ullong, NULL, 0, alloc); if (M_UNLIKELY_NOMEM (ptr == NULL)) { - M_MEMORY_FULL(alloc); + M_MEMORY_FULL(atomic_ullong, alloc); return; } s->n = n; diff --git a/m-i-shared.h b/m-i-shared.h index 0caa361b..d1bcc1cd 100644 --- a/m-i-shared.h +++ b/m-i-shared.h @@ -192,7 +192,7 @@ M_BEGIN_PROTECTED_CODE { \ type *ptr = M_CALL_NEW(oplist, type); \ if (M_UNLIKELY_NOMEM (ptr == NULL)) { \ - M_MEMORY_FULL(sizeof(type)); \ + M_MEMORY_FULL(type, 1); \ return NULL; \ } \ M_CALL_INIT(oplist, *ptr); \ diff --git a/m-list.h b/m-list.h index 7c1918a0..bdda2f60 100644 --- a/m-list.h +++ b/m-list.h @@ -278,7 +278,7 @@ struct M_F(name, _s) *next; \ next = M_C3(m_l1st_,name,_new)(); \ if (M_UNLIKELY_NOMEM (next == NULL)) { \ - M_MEMORY_FULL(sizeof (struct M_F(name, _s))); \ + M_MEMORY_FULL(struct M_F(name, _s), 1); \ return NULL; \ } \ type *ret = &next->data; \ @@ -499,7 +499,7 @@ M_ASSERT(M_F(name, _sublist_p)(list, insertion_point)); \ struct M_F(name, _s) *next = M_C3(m_l1st_,name,_new)(); \ if (M_UNLIKELY_NOMEM (next == NULL)) { \ - M_MEMORY_FULL(sizeof (struct M_F(name, _s))); \ + M_MEMORY_FULL(struct M_F(name, _s), 1); \ return; \ } \ M_ON_EXCEPTION( M_C3(m_l1st_,name,_del)(next)) \ @@ -552,7 +552,7 @@ while (it_org != NULL) { \ next = M_C3(m_l1st_,name,_new)(); \ if (M_UNLIKELY_NOMEM (next == NULL)) { \ - M_MEMORY_FULL(sizeof (struct M_F(name, _s))); \ + M_MEMORY_FULL(struct M_F(name, _s), 1); \ *update_list = NULL; \ return; \ } \ @@ -1062,7 +1062,7 @@ M_L1ST_DUAL_PUSH_CONTRACT(v); \ struct M_F(name, _s) *next = M_C3(m_l1st_,name,_new)(); \ if (M_UNLIKELY_NOMEM (next == NULL)) { \ - M_MEMORY_FULL(sizeof (struct M_F(name, _s))); \ + M_MEMORY_FULL(struct M_F(name, _s), 1); \ return NULL; \ } \ type *ret = &next->data; \ @@ -1180,7 +1180,7 @@ M_L1ST_DUAL_PUSH_CONTRACT(v); \ struct M_F(name, _s) *next = M_C3(m_l1st_,name,_new)(); \ if (M_UNLIKELY_NOMEM (next == NULL)) { \ - M_MEMORY_FULL(sizeof (struct M_F(name, _s))); \ + M_MEMORY_FULL(struct M_F(name, _s), 1); \ return NULL; \ } \ type *ret = &next->data; \ @@ -1344,7 +1344,7 @@ M_ASSERT (insertion_point != NULL); \ struct M_F(name, _s) *m_volatile next = M_C3(m_l1st_,name,_new)(); \ if (M_UNLIKELY_NOMEM (next == NULL)) { \ - M_MEMORY_FULL(sizeof (struct M_F(name, _s))); \ + M_MEMORY_FULL(struct M_F(name, _s), 1); \ return; \ } \ M_ON_EXCEPTION( M_C3(m_l1st_,name,_del)(next)) \ @@ -1406,7 +1406,7 @@ while (it_org != NULL) { \ next = M_C3(m_l1st_,name,_new)(); \ if (M_UNLIKELY_NOMEM (next == NULL)) { \ - M_MEMORY_FULL(sizeof (struct M_F(name, _s))); \ + M_MEMORY_FULL(struct M_F(name, _s), 1); \ return; \ } \ M_CALL_INIT_SET(oplist, next->data, it_org->data); \ diff --git a/m-mempool.h b/m-mempool.h index f08f7da7..adb4ad71 100644 --- a/m-mempool.h +++ b/m-mempool.h @@ -115,7 +115,7 @@ mem->free_list = NULL; \ mem->current_segment = M_MEMORY_ALLOC(M_F(name,_segment_ct)); \ if (M_UNLIKELY_NOMEM(mem->current_segment == NULL)) { \ - M_MEMORY_FULL(sizeof (M_F(name,_segment_ct))); \ + M_MEMORY_FULL(M_F(name,_segment_ct), 1); \ return; \ } \ mem->current_segment->next = NULL; \ @@ -157,7 +157,7 @@ if (M_UNLIKELY (count >= M_USE_MEMPOOL_MAX_PER_SEGMENT(type))) { \ M_F(name,_segment_ct) *new_segment = M_MEMORY_ALLOC (M_F(name,_segment_ct)); \ if (M_UNLIKELY_NOMEM (new_segment == NULL)) { \ - M_MEMORY_FULL(sizeof (M_F(name,_segment_ct))); \ + M_MEMORY_FULL(M_F(name,_segment_ct), 1); \ return NULL; \ } \ new_segment->next = segment; \ diff --git a/m-rbtree.h b/m-rbtree.h index c4fd1ac7..d07e6173 100644 --- a/m-rbtree.h +++ b/m-rbtree.h @@ -318,7 +318,7 @@ typedef enum { if (n == NULL) { \ n = M_C3(m_rbtr33_,name,_new)(); \ if (M_UNLIKELY_NOMEM (n == NULL)) { \ - M_MEMORY_FULL(sizeof (node_t)); \ + M_MEMORY_FULL(node_t, 1); \ return; \ } \ /* Copy the data in the root node */ \ @@ -359,7 +359,7 @@ typedef enum { /* Create new node to store the data */ \ n = M_C3(m_rbtr33_,name,_new)(); \ if (M_UNLIKELY_NOMEM (n == NULL) ) { \ - M_MEMORY_FULL (sizeof (node_t)); \ + M_MEMORY_FULL (node_t, 1); \ return; \ } \ /* Copy the data and mark the node as red */ \ @@ -690,7 +690,7 @@ typedef enum { if (o == NULL) return NULL; \ node_t *n = M_C3(m_rbtr33_,name,_new)(); \ if (M_UNLIKELY_NOMEM (n == NULL) ) { \ - M_MEMORY_FULL (sizeof (node_t)); \ + M_MEMORY_FULL (node_t, 1); \ return NULL; \ } \ M_CALL_INIT_SET(oplist, n->data, o->data); \ diff --git a/m-shared-ptr.h b/m-shared-ptr.h index fe928523..059811a9 100644 --- a/m-shared-ptr.h +++ b/m-shared-ptr.h @@ -615,7 +615,7 @@ M_IF_METHOD(INIT, oplist)( \ { \ shared_t *out = M_CALL_NEW(oplist, shared_t); \ if (M_UNLIKELY_NOMEM( out == NULL)) { \ - M_MEMORY_FULL(sizeof (shared_t)); \ + M_MEMORY_FULL(shared_t, 1); \ abort(); \ } \ M_ON_EXCEPTION( M_CALL_DEL(oplist, out) ) \ @@ -631,7 +631,7 @@ M_IF_METHOD(INIT_SET, oplist)( \ M_ASSERT(src != NULL); \ shared_t *out = M_CALL_NEW(oplist, shared_t); \ if (M_UNLIKELY_NOMEM( out == NULL)) { \ - M_MEMORY_FULL(sizeof (shared_t)); \ + M_MEMORY_FULL(shared_t, 1); \ abort(); \ } \ M_F(name, _read_lock)(src); \ @@ -648,7 +648,7 @@ M_IF_METHOD(INIT_SET, oplist)( \ { \ shared_t *out = M_CALL_NEW(oplist, shared_t); \ if (M_UNLIKELY_NOMEM( out == NULL)) { \ - M_MEMORY_FULL(sizeof (shared_t)); \ + M_MEMORY_FULL(shared_t, 1); \ abort(); \ } \ M_ON_EXCEPTION( M_CALL_DEL(oplist, out) ) \ @@ -706,7 +706,7 @@ M_PAIR_2 name_attr shared_t *function_name(M_EMPLACE_LIST_TYPE_VAR_ALTER(a, exp_ { \ shared_t *out = M_CALL_NEW(oplist, shared_t); \ if (M_UNLIKELY_NOMEM( out == NULL)) { \ - M_MEMORY_FULL(sizeof (shared_t)); \ + M_MEMORY_FULL(shared_t, 1); \ abort(); \ } \ M_ON_EXCEPTION( M_CALL_DEL(oplist, out) ) \ diff --git a/m-shared.h b/m-shared.h index 6becc2e0..59622be6 100644 --- a/m-shared.h +++ b/m-shared.h @@ -211,7 +211,7 @@ M_INLINE int m_shar3d_integer_cref(int *p) { return *p; } } \ ptr = M_CALL_NEW(oplist, struct M_F(name, _s)); \ if (M_UNLIKELY_NOMEM (ptr == NULL)) { \ - M_MEMORY_FULL(sizeof(struct M_F(name, _s))); \ + M_MEMORY_FULL(struct M_F(name, _s), 1); \ return; \ } \ ptr->data = data; \ @@ -229,7 +229,7 @@ M_INLINE int m_shar3d_integer_cref(int *p) { return *p; } struct M_F(name, _combine_s) *p = \ M_CALL_NEW(oplist, struct M_F(name, _combine_s)); \ if (M_UNLIKELY_NOMEM (p == NULL)) { \ - M_MEMORY_FULL(sizeof(struct M_F(name, _combine_s))); \ + M_MEMORY_FULL(struct M_F(name, _combine_s), 1); \ return; \ } \ struct M_F(name, _s) *ptr = &p->ptr; \ @@ -376,7 +376,7 @@ M_INLINE int m_shar3d_integer_cref(int *p) { return *p; } struct M_F(name, _combine_s) *p = \ M_CALL_NEW(oplist, struct M_F(name, _combine_s)); \ if (M_UNLIKELY_NOMEM (p == NULL)) { \ - M_MEMORY_FULL(sizeof(struct M_F(name, _combine_s))); \ + M_MEMORY_FULL(struct M_F(name, _combine_s), 1); \ return; \ } \ struct M_F(name, _s) *ptr = &p->ptr; \ @@ -447,7 +447,7 @@ M_INLINE int m_shar3d_integer_cref(int *p) { return *p; } M_ASSERT (n > 0 && n < UINT_MAX); \ s->buffer = M_CALL_REALLOC(oplist, M_F(name, _atype_ct), NULL, 0, n); \ if (M_UNLIKELY_NOMEM (s->buffer == NULL)) { \ - M_MEMORY_FULL(sizeof(M_F(name, _atype_ct)) * n); \ + M_MEMORY_FULL(M_F(name, _atype_ct), n); \ return; \ } \ for(size_t i = 0; i < n; i++) { \ diff --git a/m-snapshot.h b/m-snapshot.h index fd03fc52..eb7dfd43 100644 --- a/m-snapshot.h +++ b/m-snapshot.h @@ -393,7 +393,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, 0, n); if (M_UNLIKELY_NOMEM (ptr == NULL)) { - M_MEMORY_FULL(sizeof (atomic_uint) * n); + M_MEMORY_FULL(atomic_uint, n); return; } s->cptTab = ptr; @@ -647,7 +647,7 @@ m_snapsh0t_mrsw_read_end(m_snapsh0t_mrsw_ct s, unsigned int idx) snap->data = M_CALL_REALLOC(oplist, M_F(name, _aligned_type_ct), \ NULL, 0, nReader+M_SNAPSH0T_SPMC_EXTRA_BUFFER); \ if (M_UNLIKELY_NOMEM (snap->data == NULL)) { \ - M_MEMORY_FULL(sizeof(M_F(name, _aligned_type_ct)) * \ + M_MEMORY_FULL(M_F(name, _aligned_type_ct), \ (nReader+M_SNAPSH0T_SPMC_EXTRA_BUFFER)); \ return; \ } \ diff --git a/m-string.h b/m-string.h index e4c29078..b5db698a 100644 --- a/m-string.h +++ b/m-string.h @@ -313,7 +313,7 @@ m_string_clear_get_cstr(m_string_t v) size_t alloc = m_string_size(v)+1; char *ptr = M_MEMORY_REALLOC (char, NULL, 0, alloc); if (M_UNLIKELY_NOMEM (ptr == NULL)) { - M_MEMORY_FULL(sizeof (char) * alloc); + M_MEMORY_FULL(char, alloc); return NULL; } M_ASSERT(ptr != NULL && p != NULL); @@ -386,7 +386,7 @@ m_str1ng_fit2size (m_string_t v, size_t size_alloc) alloc = m_str1ng_round_capacity(&m, &e, (m_str1ng_size_t) alloc); if (M_UNLIKELY_NOMEM (alloc <= size_alloc)) { /* Overflow in alloc computation */ - M_MEMORY_FULL(sizeof (char) * alloc); + M_MEMORY_FULL(char, alloc); // NOTE: Return is currently broken. abort(); return NULL; @@ -395,7 +395,7 @@ m_str1ng_fit2size (m_string_t v, size_t size_alloc) //FIXME: old_alloc may not be NULL if ptr is NULL. ptr = M_MEMORY_REALLOC (char, ptr, old_alloc, alloc); if (M_UNLIKELY_NOMEM (ptr == NULL)) { - M_MEMORY_FULL(sizeof (char) * alloc); + M_MEMORY_FULL(char, alloc); // NOTE: Return is currently broken. abort(); return NULL; @@ -452,13 +452,13 @@ m_string_reserve(m_string_t v, size_t alloc) unsigned char m, e; size_t r_alloc = m_str1ng_round_capacity(&m, &e, (m_str1ng_size_t) alloc); if (M_UNLIKELY_NOMEM (alloc > r_alloc)) { - M_MEMORY_FULL(sizeof (char) * alloc); + M_MEMORY_FULL(char, alloc); return; } char *ptr = m_str1ng_embedded_p(v) ? NULL : v->u.heap.ptr; ptr = M_MEMORY_REALLOC (char, ptr, m_string_capacity(v), r_alloc); if (M_UNLIKELY_NOMEM (ptr == NULL) ) { - M_MEMORY_FULL(sizeof (char) * alloc); + M_MEMORY_FULL(char, alloc); return; } if (m_str1ng_embedded_p(v)) { diff --git a/m-tree.h b/m-tree.h index 929a47c6..7e4f0ca9 100644 --- a/m-tree.h +++ b/m-tree.h @@ -260,7 +260,7 @@ typedef int32_t m_tr33_index_t; } \ /* Realloc the array */ \ if (M_UNLIKELY_NOMEM (alloc >= INT32_MAX)) { \ - M_MEMORY_FULL(sizeof (struct M_F(name, _node_s)) * alloc); \ + M_MEMORY_FULL(struct M_F(name, _node_s), alloc); \ return; \ } \ /* Allocate one more term in the array so that tab[-1] exists. \ @@ -270,7 +270,7 @@ typedef int32_t m_tr33_index_t; struct M_F(name,_node_s)*ptr = tree->tab == NULL ? NULL : tree->tab-1;\ ptr = M_CALL_REALLOC(oplist, struct M_F(name, _node_s), ptr, tree->capacity+1, alloc+1); \ if (M_UNLIKELY_NOMEM (ptr == NULL) ) { \ - M_MEMORY_FULL(sizeof (struct M_F(name, _node_s)) * alloc); \ + M_MEMORY_FULL(struct M_F(name, _node_s), alloc); \ return; \ } \ /* Skip the first term to keep it as empty & unused */ \ @@ -314,7 +314,7 @@ typedef int32_t m_tr33_index_t; /* Take into account if realloc is allowed */ \ alloc += tree->allow_realloc; \ if (M_UNLIKELY_NOMEM (alloc >= INT32_MAX)) { \ - M_MEMORY_FULL(sizeof (struct M_F(name, _node_s)) * alloc); \ + M_MEMORY_FULL(struct M_F(name, _node_s), alloc); \ return M_TR33_NO_NODE; \ } \ /* Allocate one more term in the array so that tab[-1] exists. \ @@ -324,7 +324,7 @@ typedef int32_t m_tr33_index_t; struct M_F(name,_node_s)*ptr = tree->tab == NULL ? NULL : tree->tab-1; \ ptr = M_CALL_REALLOC(oplist, struct M_F(name, _node_s), ptr, tree->capacity+1, alloc+1); \ if (M_UNLIKELY_NOMEM (ptr == NULL) ) { \ - M_MEMORY_FULL(sizeof (struct M_F(name, _node_s)) * alloc); \ + M_MEMORY_FULL(struct M_F(name, _node_s), alloc); \ return M_TR33_NO_NODE; \ } \ /* Skip the first term to keep it as empty & unused */ \ @@ -1136,7 +1136,7 @@ typedef int32_t m_tr33_index_t; struct M_F(name, _node_s) *ptr = \ M_CALL_REALLOC(oplist, struct M_F(name, _node_s), NULL, 0, alloc+1); \ if (M_UNLIKELY_NOMEM (ptr == NULL) ) { \ - M_MEMORY_FULL(sizeof(struct M_F(name, _node_s)) * alloc); \ + M_MEMORY_FULL(struct M_F(name, _node_s), alloc); \ return; \ } \ tree->tab = ++ptr; \ diff --git a/m-try.h b/m-try.h index fc367130..15c77cd3 100644 --- a/m-try.h +++ b/m-try.h @@ -620,7 +620,7 @@ _Pragma("GCC diagnostic pop") // In case of MEMORY FULL errors, throw an error instead of aborting. #undef M_MEMORY_FULL -#define M_MEMORY_FULL(size) M_THROW(M_ERROR_MEMORY, (intptr_t)(size)) +#define M_MEMORY_FULL(type, size) M_THROW(M_ERROR_MEMORY, (intptr_t)sizeof(type), (intptr_t)(size)) // Add attribute volatile if exceptions are enabled #undef m_volatile diff --git a/m-worker.h b/m-worker.h index e78d213e..7022483e 100644 --- a/m-worker.h +++ b/m-worker.h @@ -266,7 +266,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_NOMEM(p == NULL)) { \ - M_MEMORY_FULL(sizeof (struct M_C3(m_worker_, name, _s))); \ + M_MEMORY_FULL(struct M_C3(m_worker_, name, _s), 1); \ } \ p->callback = callback; \ M_MAP3(M_WORK3R_SPAWN_EXTEND_DEF_EMPLACE_FIELD_COPY, data, __VA_ARGS__) \ @@ -411,7 +411,7 @@ m_worker_init(m_worker_t g, int numWorker, unsigned int extraQueue, void (*reset size_t numWorker_st = (size_t) numWorker; g->worker = M_MEMORY_REALLOC(m_work3r_thread_ct, NULL, 0, numWorker_st); if (M_UNLIKELY_NOMEM (g->worker == NULL)) { - M_MEMORY_FULL(sizeof (m_work3r_thread_ct) * numWorker_st); + M_MEMORY_FULL(m_work3r_thread_ct, numWorker_st); return; } m_work3r_queue_init(g->queue_g, numWorker_st + extraQueue);