Merge pull request #1686 from rtfeldman/refcounting-cleanup

Refcounting cleanup
This commit is contained in:
Richard Feldman 2021-09-11 13:33:36 -04:00 committed by GitHub
commit 0dd1395331
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 120 additions and 160 deletions

View file

@ -108,6 +108,7 @@ const utils = @import("utils.zig");
comptime {
exportUtilsFn(utils.test_panic, "test_panic");
exportUtilsFn(utils.decrefC, "decref");
exportUtilsFn(utils.decrefCheckNullC, "decref_check_null");
@export(utils.panic, .{ .name = "roc_builtins.utils." ++ "panic", .linkage = .Weak });
}

View file

@ -117,6 +117,16 @@ pub fn decrefC(
return @call(.{ .modifier = always_inline }, decref_ptr_to_refcount, .{ bytes, alignment });
}
pub fn decrefCheckNullC(
bytes_or_null: ?[*]u8,
alignment: u32,
) callconv(.C) void {
if (bytes_or_null) |bytes| {
const isizes: [*]isize = @ptrCast([*]isize, @alignCast(@sizeOf(isize), bytes));
return @call(.{ .modifier = always_inline }, decref_ptr_to_refcount, .{ isizes - 1, alignment });
}
}
pub fn decref(
bytes_or_null: ?[*]u8,
data_bytes: usize,