Skip to content

Commit

Permalink
switch out bad pointer rep
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewJohnHeath committed Aug 30, 2024
1 parent a5bc19c commit 4da18e6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
8 changes: 4 additions & 4 deletions crates/compiler/builtins/bitcode/src/crypt.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ const list = @import("list.zig");
const utils = @import("utils.zig");

const Sha256 = extern struct{
location:usize,
location:[*]u8,
fn pointer(self : Sha256) *sha2.Sha256{
return @ptrFromInt(self.location);
return @alignCast(@ptrCast(self.location));
}
};

const EmptyStruct = extern struct{};

pub fn emptySha256(_: EmptyStruct) callconv(.C) Sha256{
const allocation = utils.allocateWithRefcount(@sizeOf(sha2.Sha256), @alignOf(sha2.Sha256));
const allocation = utils.allocateWithRefcount(@sizeOf(sha2.Sha256), @alignOf(sha2.Sha256), false);
const ptr:*sha2.Sha256 = @alignCast(@ptrCast(allocation));
ptr.* = sha2.Sha256.init(.{});
return Sha256{.location = @intFromPtr(ptr),};
return Sha256{.location = @alignCast(@ptrCast(ptr)),};
}

pub fn addBytes(sha: Sha256, data: list.RocList) callconv(.C) Sha256{
Expand Down
16 changes: 16 additions & 0 deletions crates/compiler/builtins/roc/Crypt.roc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module[
emptySha256,
addBytes,
digest,
hashSha256,
]
import List
emptySha256 : {} -> Sha256

addBytes : Sha256, List.List u8 -> Sha256

digest : Sha256 -> Digest256

hashSha256 : List u8 -> Digest256
hashSha256 = \bytes ->
digest ( addBytes (emptySha256 {}) bytes)
1 change: 1 addition & 0 deletions crates/compiler/builtins/roc/main.roc
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ package [
Box,
Inspect,
Task,
Crypt,
] {}

0 comments on commit 4da18e6

Please sign in to comment.