use decref to deallocate RocStr in zig code

This commit is contained in:
Folkert 2021-04-14 16:53:36 +02:00
parent 6d941e242e
commit 870adb20a8
2 changed files with 3 additions and 6 deletions

View file

@ -79,12 +79,8 @@ pub const RocStr = extern struct {
pub fn deinit(self: RocStr, allocator: *Allocator) void {
if (!self.isSmallStr() and !self.isEmpty()) {
const str_bytes_ptr: [*]u8 = self.str_bytes orelse unreachable;
// include the refcount bytes
const refcount_bytes = @sizeOf(usize);
const str_bytes: []u8 = (str_bytes_ptr - refcount_bytes)[0 .. self.str_len + refcount_bytes];
allocator.free(str_bytes);
const alignment = @alignOf(usize);
utils.decref(allocator, alignment, self.str_bytes, self.str_len);
}
}

View file

@ -1,6 +1,7 @@
const std = @import("std");
const Allocator = std.mem.Allocator;
const REFCOUNT_MAX_ISIZE: comptime isize = 0;
const REFCOUNT_ONE_ISIZE: comptime isize = std.math.minInt(isize);
pub const REFCOUNT_ONE: usize = @bitCast(usize, REFCOUNT_ONE_ISIZE);