fix: c_void is gone use anyopaque

This commit is contained in:
rvcas 2022-02-09 19:04:09 -05:00
parent 0124e4d4b1
commit 94e4c2c381
No known key found for this signature in database
GPG key ID: C09B64E263F7D68C
2 changed files with 9 additions and 37 deletions

View file

@ -27,18 +27,8 @@ pub fn expectFailed(
// Lock the failures mutex before reading from any of the failures globals, // Lock the failures mutex before reading from any of the failures globals,
// and then release the lock once we're done modifying things. // and then release the lock once we're done modifying things.
failures_mutex.lock();
// TODO FOR ZIG 0.9: this API changed in https://github.com/ziglang/zig/commit/008b0ec5e58fc7e31f3b989868a7d1ea4df3f41d defer failures_mutex.unlock();
// to this: https://github.com/ziglang/zig/blob/c710d5eefe3f83226f1651947239730e77af43cb/lib/std/Thread/Mutex.zig
//
// ...so just use these two lines of code instead of the non-commented-out ones to make this work in Zig 0.9:
//
// failures_mutex.lock();
// defer failures_mutex.release();
//
// 👆 👆 👆 IF UPGRADING TO ZIG 0.9, LOOK HERE! 👆 👆 👆
const held = failures_mutex.acquire();
defer held.release();
// If we don't have enough capacity to add a failure, allocate a new failures pointer. // If we don't have enough capacity to add a failure, allocate a new failures pointer.
if (failure_length >= failure_capacity) { if (failure_length >= failure_capacity) {
@ -87,17 +77,8 @@ pub fn expectFailedC(
} }
pub fn getExpectFailures() []Failure { pub fn getExpectFailures() []Failure {
// TODO FOR ZIG 0.9: this API changed in https://github.com/ziglang/zig/commit/008b0ec5e58fc7e31f3b989868a7d1ea4df3f41d failures_mutex.lock();
// to this: https://github.com/ziglang/zig/blob/c710d5eefe3f83226f1651947239730e77af43cb/lib/std/Thread/Mutex.zig defer failures_mutex.unlock();
//
// ...so just use these two lines of code instead of the non-commented-out ones to make this work in Zig 0.9:
//
// failures_mutex.lock();
// defer failures_mutex.release();
//
// 👆 👆 👆 IF UPGRADING TO ZIG 0.9, LOOK HERE! 👆 👆 👆
const held = failures_mutex.acquire();
defer held.release();
if (failure_length > 0) { if (failure_length > 0) {
// 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.
@ -116,23 +97,14 @@ pub fn getExpectFailures() []Failure {
} }
pub fn getExpectFailuresC() callconv(.C) CSlice { pub fn getExpectFailuresC() callconv(.C) CSlice {
var bytes = @ptrCast(*c_void, failures); var bytes = @ptrCast(*anyopaque, failures);
return .{ .pointer = bytes, .len = failure_length }; return .{ .pointer = bytes, .len = failure_length };
} }
pub fn deinitFailures() void { pub fn deinitFailures() void {
// TODO FOR ZIG 0.9: this API changed in https://github.com/ziglang/zig/commit/008b0ec5e58fc7e31f3b989868a7d1ea4df3f41d failures_mutex.lock();
// to this: https://github.com/ziglang/zig/blob/c710d5eefe3f83226f1651947239730e77af43cb/lib/std/Thread/Mutex.zig defer failures_mutex.unlock();
//
// ...so just use these two lines of code instead of the non-commented-out ones to make this work in Zig 0.9:
//
// failures_mutex.lock();
// defer failures_mutex.release();
//
// 👆 👆 👆 IF UPGRADING TO ZIG 0.9, LOOK HERE! 👆 👆 👆
const held = failures_mutex.acquire();
defer held.release();
utils.dealloc(@ptrCast([*]u8, failures), @alignOf(Failure)); utils.dealloc(@ptrCast([*]u8, failures), @alignOf(Failure));
failure_length = 0; failure_length = 0;

View file

@ -57,7 +57,7 @@ fn testing_roc_panic(c_ptr: *anyopaque, tag_id: u32) callconv(.C) void {
@panic("Roc panicked"); @panic("Roc panicked");
} }
fn testing_roc_memcpy(dest: *c_void, src: *c_void, bytes: usize) callconv(.C) ?*c_void { fn testing_roc_memcpy(dest: *anyopaque, src: *anyopaque, bytes: usize) callconv(.C) ?*anyopaque {
const zig_dest = @ptrCast([*]u8, dest); const zig_dest = @ptrCast([*]u8, dest);
const zig_src = @ptrCast([*]u8, src); const zig_src = @ptrCast([*]u8, src);
@ -237,7 +237,7 @@ pub fn allocateWithRefcount(
} }
pub const CSlice = extern struct { pub const CSlice = extern struct {
pointer: *c_void, pointer: *anyopaque,
len: usize, len: usize,
}; };