mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 00:24:34 +00:00
Acknowledge possibility of roc_alloc failing
This commit is contained in:
parent
9b05d8dd50
commit
778d32f6b2
4 changed files with 20 additions and 11 deletions
|
@ -750,7 +750,8 @@ pub fn dictWalk(
|
||||||
const alignment_u32 = alignment.toU32();
|
const alignment_u32 = alignment.toU32();
|
||||||
// allocate space to write the result of the stepper into
|
// allocate space to write the result of the stepper into
|
||||||
// experimentally aliasing the accum and output pointers is not a good idea
|
// experimentally aliasing the accum and output pointers is not a good idea
|
||||||
const bytes_ptr: [*]u8 = utils.alloc(accum_width, alignment_u32);
|
// TODO handle alloc failing!
|
||||||
|
const bytes_ptr: [*]u8 = utils.alloc(accum_width, alignment_u32) orelse unreachable;
|
||||||
var b1 = output orelse unreachable;
|
var b1 = output orelse unreachable;
|
||||||
var b2 = bytes_ptr;
|
var b2 = bytes_ptr;
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,8 @@ pub fn getExpectFailures() []Failure {
|
||||||
|
|
||||||
// defensively clone failures, in case someone modifies the originals after the mutex has been released.
|
// defensively clone failures, in case someone modifies the originals after the mutex has been released.
|
||||||
const num_bytes = failure_length * @sizeOf(Failure);
|
const num_bytes = failure_length * @sizeOf(Failure);
|
||||||
const raw_clones = utils.alloc(num_bytes, @alignOf(Failure));
|
// TODO handle the possibility of alloc failing
|
||||||
|
const raw_clones = utils.alloc(num_bytes, @alignOf(Failure)) orelse unreachable;
|
||||||
const clones = @ptrCast([*]Failure, @alignCast(@alignOf(Failure), raw_clones));
|
const clones = @ptrCast([*]Failure, @alignCast(@alignOf(Failure), raw_clones));
|
||||||
|
|
||||||
utils.memcpy(@ptrCast([*]u8, clones), @ptrCast([*]u8, raw_clones), num_bytes);
|
utils.memcpy(@ptrCast([*]u8, clones), @ptrCast([*]u8, raw_clones), num_bytes);
|
||||||
|
|
|
@ -550,7 +550,8 @@ pub fn listKeepResult(
|
||||||
var output = RocList.allocate(alignment, list.len(), list.len() * after_width);
|
var output = RocList.allocate(alignment, list.len(), list.len() * after_width);
|
||||||
const target_ptr = output.bytes orelse unreachable;
|
const target_ptr = output.bytes orelse unreachable;
|
||||||
|
|
||||||
var temporary = @ptrCast([*]u8, utils.alloc(result_width, alignment));
|
// TODO handle alloc failing!
|
||||||
|
var temporary = utils.alloc(result_width, alignment) orelse unreachable;
|
||||||
|
|
||||||
if (data_is_owned) {
|
if (data_is_owned) {
|
||||||
inc_n_data(data, size);
|
inc_n_data(data, size);
|
||||||
|
@ -614,7 +615,8 @@ pub fn listWalk(
|
||||||
inc_n_data(data, list.len());
|
inc_n_data(data, list.len());
|
||||||
}
|
}
|
||||||
|
|
||||||
const bytes_ptr: [*]u8 = utils.alloc(accum_width, alignment);
|
// TODO handle alloc failing!
|
||||||
|
const bytes_ptr: [*]u8 = utils.alloc(accum_width, alignment) orelse unreachable;
|
||||||
var b1 = output orelse unreachable;
|
var b1 = output orelse unreachable;
|
||||||
var b2 = bytes_ptr;
|
var b2 = bytes_ptr;
|
||||||
|
|
||||||
|
@ -660,7 +662,8 @@ pub fn listWalkBackwards(
|
||||||
inc_n_data(data, list.len());
|
inc_n_data(data, list.len());
|
||||||
}
|
}
|
||||||
|
|
||||||
const bytes_ptr: [*]u8 = utils.alloc(accum_width, alignment);
|
// TODO handle alloc failing!
|
||||||
|
const bytes_ptr: [*]u8 = utils.alloc(accum_width, alignment) orelse unreachable;
|
||||||
var b1 = output orelse unreachable;
|
var b1 = output orelse unreachable;
|
||||||
var b2 = bytes_ptr;
|
var b2 = bytes_ptr;
|
||||||
|
|
||||||
|
@ -708,7 +711,8 @@ pub fn listWalkUntil(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bytes_ptr: [*]u8 = utils.alloc(continue_stop_width, alignment);
|
// TODO handle alloc failing!
|
||||||
|
const bytes_ptr: [*]u8 = utils.alloc(continue_stop_width, alignment) orelse unreachable;
|
||||||
|
|
||||||
// NOTE: assumes data bytes are the first bytes in a tag
|
// NOTE: assumes data bytes are the first bytes in a tag
|
||||||
@memcpy(bytes_ptr, accum orelse unreachable, accum_width);
|
@memcpy(bytes_ptr, accum orelse unreachable, accum_width);
|
||||||
|
|
|
@ -65,8 +65,8 @@ fn testing_roc_memcpy(dest: *c_void, src: *c_void, bytes: usize) callconv(.C) ?*
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn alloc(size: usize, alignment: u32) [*]u8 {
|
pub fn alloc(size: usize, alignment: u32) ?[*]u8 {
|
||||||
return @ptrCast([*]u8, @call(.{ .modifier = always_inline }, roc_alloc, .{ size, alignment }));
|
return @ptrCast(?[*]u8, @call(.{ .modifier = always_inline }, roc_alloc, .{ size, alignment }));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn realloc(c_ptr: [*]u8, new_size: usize, old_size: usize, alignment: u32) [*]u8 {
|
pub fn realloc(c_ptr: [*]u8, new_size: usize, old_size: usize, alignment: u32) [*]u8 {
|
||||||
|
@ -189,7 +189,8 @@ pub fn allocateWithRefcount(
|
||||||
|
|
||||||
switch (alignment) {
|
switch (alignment) {
|
||||||
16 => {
|
16 => {
|
||||||
var new_bytes: [*]align(16) u8 = @alignCast(16, alloc(length, alignment));
|
// TODO handle alloc failing!
|
||||||
|
var new_bytes: [*]align(16) u8 = @alignCast(16, alloc(length, alignment) orelse unreachable);
|
||||||
|
|
||||||
var as_usize_array = @ptrCast([*]usize, new_bytes);
|
var as_usize_array = @ptrCast([*]usize, new_bytes);
|
||||||
as_usize_array[0] = 0;
|
as_usize_array[0] = 0;
|
||||||
|
@ -201,7 +202,8 @@ pub fn allocateWithRefcount(
|
||||||
return first_slot;
|
return first_slot;
|
||||||
},
|
},
|
||||||
8 => {
|
8 => {
|
||||||
var raw = alloc(length, alignment);
|
// TODO handle alloc failing!
|
||||||
|
var raw = alloc(length, alignment) orelse unreachable;
|
||||||
var new_bytes: [*]align(8) u8 = @alignCast(8, raw);
|
var new_bytes: [*]align(8) u8 = @alignCast(8, raw);
|
||||||
|
|
||||||
var as_isize_array = @ptrCast([*]isize, new_bytes);
|
var as_isize_array = @ptrCast([*]isize, new_bytes);
|
||||||
|
@ -213,7 +215,8 @@ pub fn allocateWithRefcount(
|
||||||
return first_slot;
|
return first_slot;
|
||||||
},
|
},
|
||||||
4 => {
|
4 => {
|
||||||
var raw = alloc(length, alignment);
|
// TODO handle alloc failing!
|
||||||
|
var raw = alloc(length, alignment) orelse unreachable;
|
||||||
var new_bytes: [*]align(@alignOf(isize)) u8 = @alignCast(@alignOf(isize), raw);
|
var new_bytes: [*]align(@alignOf(isize)) u8 = @alignCast(@alignOf(isize), raw);
|
||||||
|
|
||||||
var as_isize_array = @ptrCast([*]isize, new_bytes);
|
var as_isize_array = @ptrCast([*]isize, new_bytes);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue