Updated malloc/calloc/realloc/free deprecation of old helper functions. Add checks to prevent incorrect alignment on types when using malloc. Better errors from $assert. Added @deprecated. Fixed issue using named arguments after varargs.

This commit is contained in:
Christoffer Lerno
2023-02-27 14:51:35 +01:00
committed by Christoffer Lerno
parent 8ad8af861e
commit dd4edfb747
28 changed files with 705 additions and 343 deletions

View File

@@ -36,7 +36,7 @@ fn Stream ByteWriter.as_stream(ByteWriter* writer)
fn void ByteWriter.destroy(ByteWriter* writer)
{
if (!writer.allocator) return;
if (void* ptr = writer.bytes.ptr) writer.allocator.free(ptr)!!;
if (void* ptr = writer.bytes.ptr) free(ptr, .using = writer.allocator);
*writer = { };
}
@@ -50,7 +50,7 @@ fn void! ByteWriter.ensure_capacity(ByteWriter* writer, usz len) @inline
if (writer.bytes.len > len) return;
if (len < 16) len = 16;
usz new_capacity = math::next_power_of_2(len);
char* new_ptr = writer.allocator.realloc(writer.bytes.ptr, new_capacity)?;
char* new_ptr = realloc_checked(writer.bytes.ptr, new_capacity, .using = writer.allocator)?;
writer.bytes = new_ptr[:new_capacity];
}