Update prototype of memory functions
to always get the memory context parameter (even if it is not needed) to provide a cleaner and simpler user interface (instead of requesting the user to use directly m_context).
This commit is contained in:
1 parent
f585167fa8
commit
3721129da1
19 files changed
+155
-118
No files matched your search
+6
-6
@@ -104,7 +104,7 @@ m_bitset_reset(m_bitset_t t)
|
||||
M_P(void, m_bitset, _clear, m_bitset_t t)
|
||||
{
|
||||
m_bitset_reset(t);
|
||||
M_MEMORY_FREE(m_b1tset_limb_ct, t->ptr, t->alloc);
|
||||
M_MEMORY_FREE(m_context, m_b1tset_limb_ct, t->ptr, t->alloc);
|
||||
// This is not really needed, but is safer
|
||||
// This representation is invalid and will be detected by the contract.
|
||||
// A C compiler should be able to optimize out theses initializations.
|
||||
@@ -122,7 +122,7 @@ M_P(void, m_bitset, _set, m_bitset_t d, const m_bitset_t s)
|
||||
if (M_LIKELY (s->size > 0)) {
|
||||
// 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, d->alloc, needAlloc);
|
||||
m_b1tset_limb_ct *ptr = M_MEMORY_REALLOC (m_context, m_b1tset_limb_ct, d->ptr, d->alloc, needAlloc);
|
||||
if (M_UNLIKELY_NOMEM (ptr == NULL)) {
|
||||
M_MEMORY_FULL(m_b1tset_limb_ct, needAlloc);
|
||||
}
|
||||
@@ -209,7 +209,7 @@ M_P(void, m_bitset, _push_back, m_bitset_t v, bool x)
|
||||
M_MEMORY_FULL(m_b1tset_limb_ct, needAlloc);
|
||||
}
|
||||
// Alloc memory
|
||||
m_b1tset_limb_ct *ptr = M_MEMORY_REALLOC (m_b1tset_limb_ct, v->ptr, v->alloc, needAlloc);
|
||||
m_b1tset_limb_ct *ptr = M_MEMORY_REALLOC (m_context, m_b1tset_limb_ct, v->ptr, v->alloc, needAlloc);
|
||||
// Check if success
|
||||
if (M_UNLIKELY_NOMEM (ptr == NULL) ) {
|
||||
M_MEMORY_FULL(m_b1tset_limb_ct, needAlloc);
|
||||
@@ -245,7 +245,7 @@ M_P(void, m_bitset, _resize, m_bitset_t v, size_t size)
|
||||
size_t newAlloc = M_B1TSET_TO_ALLOC (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, v->alloc, newAlloc);
|
||||
m_b1tset_limb_ct *ptr = M_MEMORY_REALLOC (m_context, m_b1tset_limb_ct, v->ptr, v->alloc, newAlloc);
|
||||
if (M_UNLIKELY_NOMEM (ptr == NULL) ) {
|
||||
M_MEMORY_FULL(m_b1tset_limb_ct, newAlloc);
|
||||
}
|
||||
@@ -290,12 +290,12 @@ M_P(void, m_bitset, _reserve, m_bitset_t v, size_t alloc)
|
||||
}
|
||||
if (M_UNLIKELY (newAlloc == 0)) {
|
||||
// Free all memory used by the bitsets
|
||||
M_MEMORY_FREE (m_b1tset_limb_ct, v->ptr, v->alloc);
|
||||
M_MEMORY_FREE (m_context, m_b1tset_limb_ct, v->ptr, v->alloc);
|
||||
v->size = v->alloc = 0;
|
||||
v->ptr = NULL;
|
||||
} else {
|
||||
// Allocate more memory or reduce memory usage
|
||||
m_b1tset_limb_ct *ptr = M_MEMORY_REALLOC (m_b1tset_limb_ct, v->ptr, v->alloc, newAlloc);
|
||||
m_b1tset_limb_ct *ptr = M_MEMORY_REALLOC (m_context, m_b1tset_limb_ct, v->ptr, v->alloc, newAlloc);
|
||||
if (M_UNLIKELY_NOMEM (ptr == NULL) ) {
|
||||
M_MEMORY_FULL(m_b1tset_limb_ct, newAlloc);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user