From 29f990e19bb06d19749ce944ee498029e9b27cbb Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Wed, 7 Sep 2022 15:21:39 +0200 Subject: [PATCH] Fix msg_id and client_id being size_t in C instead of u64 which is only valid on 64bit architectures. Fixes #5 --- speech-dispatcher/src/lib.rs | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/speech-dispatcher/src/lib.rs b/speech-dispatcher/src/lib.rs index d8b5697..1d980ed 100644 --- a/speech-dispatcher/src/lib.rs +++ b/speech-dispatcher/src/lib.rs @@ -122,12 +122,12 @@ fn c_int_to_result(r: c_int) -> Result<(), Error> { #[derive(Default)] struct Callbacks { - begin: Option>, - end: Option>, - index_mark: Option>, - cancel: Option>, - pause: Option>, - resume: Option>, + begin: Option>, + end: Option>, + index_mark: Option>, + cancel: Option>, + pause: Option>, + resume: Option>, } unsafe impl Send for Callbacks {} @@ -135,13 +135,13 @@ unsafe impl Send for Callbacks {} unsafe impl Sync for Callbacks {} lazy_static! { - static ref callbacks: Mutex> = { + static ref callbacks: Mutex> = { let m = HashMap::new(); Mutex::new(m) }; } -unsafe extern "C" fn cb(msg_id: u64, client_id: u64, state: u32) { +unsafe extern "C" fn cb(msg_id: size_t, client_id: size_t, state: u32) { let state = match state { SPDNotificationType_SPD_EVENT_BEGIN => Notification::Begin, SPDNotificationType_SPD_EVENT_END => Notification::End, @@ -165,7 +165,7 @@ unsafe extern "C" fn cb(msg_id: u64, client_id: u64, state: u32) { } } -unsafe extern "C" fn cb_im(msg_id: u64, client_id: u64, state: u32, index_mark: *mut c_char) { +unsafe extern "C" fn cb_im(msg_id: size_t, client_id: size_t, state: u32, index_mark: *mut c_char) { let index_mark = CStr::from_ptr(index_mark); let index_mark = index_mark.to_string_lossy().to_string(); let state = match state { @@ -205,7 +205,7 @@ impl fmt::Display for Error { } #[derive(Clone, Debug)] -pub struct Connection(pub Arc<*mut SPDConnection>, u64); +pub struct Connection(pub Arc<*mut SPDConnection>, size_t); impl Connection { pub fn open>( @@ -287,7 +287,7 @@ impl Connection { if let Some(client_id) = client_id { let client_id: Vec<&str> = client_id.split("-").collect(); if let Some(client_id) = client_id.get(1) { - if let Ok(client_id) = client_id.parse::() { + if let Ok(client_id) = client_id.parse::() { self.1 = client_id; } } @@ -693,7 +693,7 @@ impl Connection { } } - pub fn on_begin(&self, f: Option>) { + pub fn on_begin(&self, f: Option>) { if let Ok(mut cbs) = callbacks.lock() { let cb = cbs.get_mut(&self.1); if let Some(cb) = cb { @@ -702,7 +702,7 @@ impl Connection { } } - pub fn on_end(&self, f: Option>) { + pub fn on_end(&self, f: Option>) { if let Ok(mut cbs) = callbacks.lock() { let cb = cbs.get_mut(&self.1); if let Some(cb) = cb { @@ -711,7 +711,7 @@ impl Connection { } } - pub fn on_cancel(&self, f: Option>) { + pub fn on_cancel(&self, f: Option>) { if let Ok(mut cbs) = callbacks.lock() { let cb = cbs.get_mut(&self.1); if let Some(cb) = cb { @@ -720,7 +720,7 @@ impl Connection { } } - pub fn on_pause(&self, f: Option>) { + pub fn on_pause(&self, f: Option>) { if let Ok(mut cbs) = callbacks.lock() { let cb = cbs.get_mut(&self.1); if let Some(cb) = cb { @@ -729,7 +729,7 @@ impl Connection { } } - pub fn on_resume(&self, f: Option>) { + pub fn on_resume(&self, f: Option>) { if let Ok(mut cbs) = callbacks.lock() { let cb = cbs.get_mut(&self.1); if let Some(cb) = cb { @@ -738,7 +738,7 @@ impl Connection { } } - pub fn on_index_mark(&self, f: Option>) { + pub fn on_index_mark(&self, f: Option>) { if let Ok(mut cbs) = callbacks.lock() { let cb = cbs.get_mut(&self.1); if let Some(cb) = cb { @@ -784,7 +784,7 @@ impl Connection { Ok(modules) } - pub fn client_id(&self) -> u64 { + pub fn client_id(&self) -> size_t { self.1 } }