mirror of
https://github.com/roc-lang/roc.git
synced 2025-07-24 06:55:15 +00:00
aligns as 8
This commit is contained in:
parent
b33f1b0981
commit
82a70c79b8
1 changed files with 6 additions and 4 deletions
|
@ -75,12 +75,13 @@ comptime {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn testing_roc_alloc(size: usize, alignment: u32) callconv(.C) ?*anyopaque {
|
fn testing_roc_alloc(size: usize, alignment: u32) callconv(.C) ?*anyopaque {
|
||||||
if (alignment > @alignOf(usize)) {
|
const real_alignment = 8;
|
||||||
@panic("alignments larger than that of usize are not currently supported");
|
if (alignment > real_alignment) {
|
||||||
|
@panic("alignments larger than 8 are not currently supported");
|
||||||
}
|
}
|
||||||
// We store an extra usize which is the size of the full allocation.
|
// We store an extra usize which is the size of the full allocation.
|
||||||
const full_size = size + @sizeOf(usize);
|
const full_size = size + @sizeOf(usize);
|
||||||
var raw_ptr = (std.testing.allocator.alignedAlloc(u8, @alignOf(usize), full_size) catch unreachable).ptr;
|
var raw_ptr = (std.testing.allocator.alignedAlloc(u8, real_alignment, full_size) catch unreachable).ptr;
|
||||||
@as([*]usize, @alignCast(@ptrCast(raw_ptr)))[0] = full_size;
|
@as([*]usize, @alignCast(@ptrCast(raw_ptr)))[0] = full_size;
|
||||||
raw_ptr += @sizeOf(usize);
|
raw_ptr += @sizeOf(usize);
|
||||||
const ptr = @as(?*anyopaque, @ptrCast(raw_ptr));
|
const ptr = @as(?*anyopaque, @ptrCast(raw_ptr));
|
||||||
|
@ -110,7 +111,8 @@ fn testing_roc_realloc(c_ptr: *anyopaque, new_size: usize, old_size: usize, _: u
|
||||||
}
|
}
|
||||||
|
|
||||||
fn testing_roc_dealloc(c_ptr: *anyopaque, _: u32) callconv(.C) void {
|
fn testing_roc_dealloc(c_ptr: *anyopaque, _: u32) callconv(.C) void {
|
||||||
const raw_ptr = @as([*]align(@alignOf(usize)) u8, @alignCast(@ptrCast(c_ptr))) - @sizeOf(usize);
|
const actual_alignment = 8;
|
||||||
|
const raw_ptr = @as([*]align(actual_alignment) u8, @alignCast(@ptrCast(c_ptr))) - @sizeOf(usize);
|
||||||
const full_size = @as([*]usize, @alignCast(@ptrCast(raw_ptr)))[0];
|
const full_size = @as([*]usize, @alignCast(@ptrCast(raw_ptr)))[0];
|
||||||
const slice = raw_ptr[0..full_size];
|
const slice = raw_ptr[0..full_size];
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue