Port to new memory model
This commit is contained in:
1 parent
5b4c9cd618
commit
1f2584ccea
16 files changed
+95
-86
No files matched your search
+6
-5
@@ -286,7 +286,7 @@ m_string_clear(m_string_t v)
|
||||
{
|
||||
M_STR1NG_CONTRACT(v);
|
||||
if (!m_str1ng_embedded_p(v)) {
|
||||
M_MEMORY_FREE(v->u.heap.ptr);
|
||||
M_MEMORY_FREE(char, v->u.heap.ptr, m_string_capacity(v));
|
||||
v->u.heap.ptr = NULL;
|
||||
}
|
||||
/* This is not needed but is safer to make
|
||||
@@ -311,7 +311,7 @@ m_string_clear_get_cstr(m_string_t v)
|
||||
p = &v->u.buffer[0];
|
||||
// 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);
|
||||
char *ptr = M_MEMORY_REALLOC (char, NULL, 0, alloc);
|
||||
if (M_UNLIKELY_NOMEM (ptr == NULL)) {
|
||||
M_MEMORY_FULL(sizeof (char) * alloc);
|
||||
return NULL;
|
||||
@@ -392,7 +392,8 @@ m_str1ng_fit2size (m_string_t v, size_t size_alloc)
|
||||
return NULL;
|
||||
}
|
||||
char *ptr = m_str1ng_embedded_p(v) ? NULL : v->u.heap.ptr;
|
||||
ptr = M_MEMORY_REALLOC (char, ptr, 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);
|
||||
// NOTE: Return is currently broken.
|
||||
@@ -439,7 +440,7 @@ m_string_reserve(m_string_t v, size_t alloc)
|
||||
char *oldptr = v->u.heap.ptr;
|
||||
memcpy(ptr, oldptr, size+1);
|
||||
// Free the allocated memory on the heap
|
||||
M_MEMORY_FREE(oldptr);
|
||||
M_MEMORY_FREE(char, oldptr, m_string_capacity(v));
|
||||
v->u.buffer[sizeof(m_string_t)-2] = 0;
|
||||
v->u.buffer[sizeof(m_string_t)-1] = (char) size;
|
||||
} else {
|
||||
@@ -455,7 +456,7 @@ m_string_reserve(m_string_t v, size_t alloc)
|
||||
return;
|
||||
}
|
||||
char *ptr = m_str1ng_embedded_p(v) ? NULL : v->u.heap.ptr;
|
||||
ptr = M_MEMORY_REALLOC (char, ptr, r_alloc);
|
||||
ptr = M_MEMORY_REALLOC (char, ptr, m_string_capacity(v), r_alloc);
|
||||
if (M_UNLIKELY_NOMEM (ptr == NULL) ) {
|
||||
M_MEMORY_FULL(sizeof (char) * alloc);
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user