mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 20:11:17 +00:00
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:
committed by
Christoffer Lerno
parent
8ad8af861e
commit
dd4edfb747
@@ -6,35 +6,25 @@ module std::core::mem::array;
|
||||
/**
|
||||
* @require usz.max / elements > $Type.sizeof
|
||||
**/
|
||||
macro alloc($Type, usz elements)
|
||||
{
|
||||
$Type* ptr = malloc($Type.sizeof * elements);
|
||||
return ptr[:elements];
|
||||
}
|
||||
macro alloc($Type, usz elements) @deprecated => malloc($Type, elements);
|
||||
|
||||
/**
|
||||
* @require usz.max / elements > $Type.sizeof
|
||||
**/
|
||||
macro talloc($Type, usz elements)
|
||||
macro talloc($Type, usz elements) @deprecated => tmalloc($Type, elements);
|
||||
|
||||
/**
|
||||
* @require (usz.max / elements > $Type.sizeof)
|
||||
**/
|
||||
macro make($Type, usz elements, Allocator* allocator = mem::current_allocator()) @deprecated
|
||||
{
|
||||
$Type* ptr = tmalloc($Type.sizeof * elements, $Type[1].alignof);
|
||||
return ptr[:elements];
|
||||
return calloc($Type, elements, .using = allocator);
|
||||
}
|
||||
|
||||
/**
|
||||
* @require (usz.max / elements > $Type.sizeof)
|
||||
**/
|
||||
macro make($Type, usz elements, Allocator* allocator = mem::current_allocator())
|
||||
macro tmake($Type, usz elements) @deprecated
|
||||
{
|
||||
$Type* ptr = allocator.calloc($Type.sizeof * elements)!!;
|
||||
return ptr[:elements];
|
||||
}
|
||||
|
||||
/**
|
||||
* @require (usz.max / elements > $Type.sizeof)
|
||||
**/
|
||||
macro tmake($Type, usz elements)
|
||||
{
|
||||
$Type* ptr = tcalloc($Type.sizeof * elements, $Type[1].alignof);
|
||||
return ptr[:elements];
|
||||
return tcalloc($Type, elements);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user