From 379b7e8abfaa27ab3b9b9eb1b43045d2289e1e9b Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Thu, 27 Jun 2024 19:03:22 +0200 Subject: [PATCH] fix(windows): prevent @intCast crash on windows --- include/thespian/c/metronome.h | 6 ++++-- include/thespian/c/timeout.h | 7 +++++-- src/c/metronome.cpp | 4 ++-- src/c/timeout.cpp | 4 ++-- src/thespian.zig | 4 ++-- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/include/thespian/c/metronome.h b/include/thespian/c/metronome.h index b440b00..d7d06b9 100644 --- a/include/thespian/c/metronome.h +++ b/include/thespian/c/metronome.h @@ -5,11 +5,13 @@ extern "C" { #endif +#include + struct thespian_metronome_handle; struct thespian_metronome_handle * -thespian_metronome_create_ms(unsigned long ms); +thespian_metronome_create_ms(uint64_t ms); struct thespian_metronome_handle * -thespian_metronome_create_us(unsigned long us); +thespian_metronome_create_us(uint64_t us); int thespian_metronome_start(struct thespian_metronome_handle *); int thespian_metronome_stop(struct thespian_metronome_handle *); void thespian_metronome_destroy(struct thespian_metronome_handle *); diff --git a/include/thespian/c/timeout.h b/include/thespian/c/timeout.h index 7e18970..e66b802 100644 --- a/include/thespian/c/timeout.h +++ b/include/thespian/c/timeout.h @@ -2,16 +2,19 @@ #include + // NOLINTBEGIN(modernize-use-trailing-return-type) #ifdef __cplusplus extern "C" { #endif +#include + struct thespian_timeout_handle; struct thespian_timeout_handle * -thespian_timeout_create_ms(unsigned long ms, cbor_buffer m); +thespian_timeout_create_ms(uint64_t ms, cbor_buffer m); struct thespian_timeout_handle * -thespian_timeout_create_us(unsigned long us, cbor_buffer m); +thespian_timeout_create_us(uint64_t us, cbor_buffer m); int thespian_timeout_cancel(struct thespian_timeout_handle *); void thespian_timeout_destroy(struct thespian_timeout_handle *); diff --git a/src/c/metronome.cpp b/src/c/metronome.cpp index be37566..62ed79d 100644 --- a/src/c/metronome.cpp +++ b/src/c/metronome.cpp @@ -14,7 +14,7 @@ using thespian::stop_metronome; extern "C" { -auto thespian_metronome_create_ms(unsigned long ms) +auto thespian_metronome_create_ms(uint64_t ms) -> thespian_metronome_handle * { try { auto *handle = thespian::create_metronome(milliseconds(ms)).ref.release(); @@ -27,7 +27,7 @@ auto thespian_metronome_create_ms(unsigned long ms) return nullptr; } } -auto thespian_metronome_create_us(unsigned long us) +auto thespian_metronome_create_us(uint64_t us) -> thespian_metronome_handle * { try { auto *handle = thespian::create_metronome(microseconds(us)).ref.release(); diff --git a/src/c/timeout.cpp b/src/c/timeout.cpp index a518deb..b93ab42 100644 --- a/src/c/timeout.cpp +++ b/src/c/timeout.cpp @@ -13,7 +13,7 @@ using thespian::timeout_ref; extern "C" { -auto thespian_timeout_create_ms(unsigned long ms, cbor_buffer m) +auto thespian_timeout_create_ms(uint64_t ms, cbor_buffer m) -> thespian_timeout_handle * { try { cbor::buffer buf; @@ -31,7 +31,7 @@ auto thespian_timeout_create_ms(unsigned long ms, cbor_buffer m) return nullptr; } } -auto thespian_timeout_create_us(unsigned long us, cbor_buffer m) +auto thespian_timeout_create_us(uint64_t us, cbor_buffer m) -> thespian_timeout_handle * { try { cbor::buffer buf; diff --git a/src/thespian.zig b/src/thespian.zig index 3994c59..97d0b45 100644 --- a/src/thespian.zig +++ b/src/thespian.zig @@ -681,11 +681,11 @@ pub const timeout = struct { const Self = @This(); pub fn init(tick_time_us: u64, m: message) !Self { - return .{ .handle = c.thespian_timeout_create_us(@intCast(tick_time_us), m.to(c.cbor_buffer)) orelse return error.ThespianTimeoutInitFailed }; + return .{ .handle = c.thespian_timeout_create_us(tick_time_us, m.to(c.cbor_buffer)) orelse return error.ThespianTimeoutInitFailed }; } pub fn init_ms(tick_time_us: u64, m: message) !Self { - return .{ .handle = c.thespian_timeout_create_ms(@intCast(tick_time_us), m.to(c.cbor_buffer)) orelse return error.ThespianTimeoutInitFailed }; + return .{ .handle = c.thespian_timeout_create_ms(tick_time_us, m.to(c.cbor_buffer)) orelse return error.ThespianTimeoutInitFailed }; } pub fn cancel(self: *const Self) !void {