mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Fix ordering of @builtin. malloc <-> alloc, malloc, calloc, realloc, free builtins.
This commit is contained in:
@@ -25,7 +25,7 @@ private fn void*! arena_allocator_function(Allocator* data, usize size, usize al
|
||||
if (!size) return null;
|
||||
alignment = alignment_for_allocation(alignment);
|
||||
void* mem = arena._alloc(size, alignment, offset)?;
|
||||
if (clear) mem::memset(mem, 0, size, false, DEFAULT_MEM_ALIGNMENT);
|
||||
if (clear) mem::clear(mem, size, DEFAULT_MEM_ALIGNMENT);
|
||||
return mem;
|
||||
case ALIGNED_REALLOC:
|
||||
case REALLOC:
|
||||
@@ -114,6 +114,6 @@ private fn void*! ArenaAllocator._realloc(ArenaAllocator* this, void *old_pointe
|
||||
}
|
||||
// Otherwise just allocate new memory.
|
||||
void* mem = this._alloc(size, alignment, offset)?;
|
||||
mem::memcpy(mem, old_pointer, old_size, false, DEFAULT_MEM_ALIGNMENT, DEFAULT_MEM_ALIGNMENT);
|
||||
mem::copy(mem, old_pointer, old_size, DEFAULT_MEM_ALIGNMENT, DEFAULT_MEM_ALIGNMENT);
|
||||
return mem;
|
||||
}
|
||||
@@ -58,7 +58,7 @@ private fn void*! DynamicArenaAllocator._realloc(DynamicArenaAllocator* this, vo
|
||||
return old_pointer;
|
||||
}
|
||||
void* new_mem = this._alloc(size, alignment, offset)?;
|
||||
mem::memcpy(new_mem, old_pointer, old_size, false, DEFAULT_MEM_ALIGNMENT);
|
||||
mem::copy(new_mem, old_pointer, old_size, DEFAULT_MEM_ALIGNMENT);
|
||||
return new_mem;
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ private fn void*! dynamic_arena_allocator_function(Allocator* data, usize size,
|
||||
assert(!old_pointer, "Unexpected no old pointer for calloc.");
|
||||
if (!size) return null;
|
||||
void* mem = allocator._alloc(size, alignment, offset)?;
|
||||
mem::memset(mem, 0, size, false, DEFAULT_MEM_ALIGNMENT);
|
||||
mem::clear(mem, size, DEFAULT_MEM_ALIGNMENT);
|
||||
return mem;
|
||||
case ALLOC:
|
||||
case ALIGNED_ALLOC:
|
||||
|
||||
@@ -66,7 +66,7 @@ private fn void* _libc_aligned_realloc(void* old_pointer, usize bytes, usize ali
|
||||
AlignedBlock* desc = (AlignedBlock*)old_pointer - 1;
|
||||
void* data_start = desc.start;
|
||||
void* new_data = _libc_aligned_calloc(bytes, alignment, offset);
|
||||
mem::memcpy(new_data, old_pointer, desc.len > bytes ? desc.len : bytes, false, DEFAULT_MEM_ALIGNMENT, DEFAULT_MEM_ALIGNMENT);
|
||||
mem::copy(new_data, old_pointer, desc.len > bytes ? desc.len : bytes, DEFAULT_MEM_ALIGNMENT, DEFAULT_MEM_ALIGNMENT);
|
||||
libc::free(data_start);
|
||||
return new_data;
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ private fn void*! TempAllocator._realloc_page(TempAllocator* this, TempAllocator
|
||||
usize page_size = page.pagesize();
|
||||
// Clear on size > original size.
|
||||
void* data = this._alloc(size, alignment, offset, false)?;
|
||||
mem::memcpy(data, &page.data[0], page_size, false, DEFAULT_MEM_ALIGNMENT, DEFAULT_MEM_ALIGNMENT);
|
||||
mem::copy(data, &page.data[0], page_size, DEFAULT_MEM_ALIGNMENT, DEFAULT_MEM_ALIGNMENT);
|
||||
if (page.is_aligned())
|
||||
{
|
||||
this.backing_allocator.free_aligned(real_pointer)?;
|
||||
@@ -161,7 +161,7 @@ private fn void*! TempAllocator._realloc(TempAllocator* this, void* pointer, usi
|
||||
|
||||
// TODO optimize last allocation
|
||||
TempAllocatorChunk* data = this._alloc(size, alignment, offset, size > chunk.size)?;
|
||||
mem::memcpy(data, pointer, chunk.size, false, DEFAULT_MEM_ALIGNMENT, DEFAULT_MEM_ALIGNMENT);
|
||||
mem::copy(data, pointer, chunk.size, DEFAULT_MEM_ALIGNMENT, DEFAULT_MEM_ALIGNMENT);
|
||||
|
||||
return data;
|
||||
}
|
||||
@@ -190,7 +190,7 @@ private fn void*! TempAllocator._alloc(TempAllocator* this, usize size, usize al
|
||||
TempAllocatorChunk* chunk_start = mem - TempAllocatorChunk.sizeof;
|
||||
chunk_start.size = size;
|
||||
this.used = new_usage;
|
||||
if (clear) mem::memset(mem, 0, size, false, DEFAULT_MEM_ALIGNMENT);
|
||||
if (clear) mem::clear(mem, size, DEFAULT_MEM_ALIGNMENT);
|
||||
return mem;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user