Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal: Use named exports to clarify intentions #31

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ futures-channel = "0.3.30"
futures-core = { version = "0.3.30", default-features = false }
futures-util = { version = "0.3.30", default-features = false }
log = "0.4.20"
open62541-sys = "0.2.2"
open62541-sys = "0.3.2"
paste = "1.0.14"
serde = { version = "1.0.194", optional = true }
serde_json = { version = "1.0.111", optional = true }
Expand Down
15 changes: 8 additions & 7 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use std::{
};

use open62541_sys::{
va_end, vsnprintf, UA_ClientConfig, UA_ClientConfig_setDefault, UA_Client_connect,
UA_Client_getConfig, UA_LogCategory, UA_LogLevel, UA_STATUSCODE_GOOD,
vsnprintf_va_copy, vsnprintf_va_end, UA_ClientConfig, UA_ClientConfig_setDefault,
UA_Client_connect, UA_Client_getConfig, UA_LogCategory, UA_LogLevel, UA_STATUSCODE_GOOD,
};

use crate::{ua, Error};
Expand Down Expand Up @@ -228,15 +228,16 @@ const FORMAT_MESSAGE_MAXIMUM_BUFFER_LEN: usize = 65536;
fn format_message(msg: *const c_char, args: open62541_sys::va_list_) -> Option<Vec<u8>> {
// Delegate string formatting to `vsnprintf()`, the length-checked string buffer variant of the
// variadic `vprintf` family.

// Delegate string formatting to the custom `vsnprintf()` provided by open62541_sys.
//
// We use the custom `vsnprintf_va_copy()` provided by `open62541_sys`. This copies the va args
// and requires an explicit call to `vsnprintf_va_end()` afterwards.

// Allocate default buffer first. Only when the message doesn't fit, we need to allocate larger
// buffer below.
let mut msg_buffer: Vec<u8> = vec![0; FORMAT_MESSAGE_DEFAULT_BUFFER_LEN];
loop {
let result = unsafe {
vsnprintf(
vsnprintf_va_copy(
msg_buffer.as_mut_ptr().cast::<c_char>(),
msg_buffer.len(),
msg,
Expand All @@ -247,7 +248,7 @@ fn format_message(msg: *const c_char, args: open62541_sys::va_list_) -> Option<V
// Negative result is an error in the format string. Nothing we can do.
debug_assert!(result < 0);
// Free the `va_list` argument that is no consumed by `vsnprintf()`!
unsafe { va_end(args) }
unsafe { vsnprintf_va_end(args) }
return None;
};
let buffer_len = msg_len + 1;
Expand All @@ -273,7 +274,7 @@ fn format_message(msg: *const c_char, args: open62541_sys::va_list_) -> Option<V
}

// Free the `va_list` argument that is not consumed by `vsnprintf()`!
unsafe { va_end(args) }
unsafe { vsnprintf_va_end(args) }

// Last byte must always be the NUL terminator.
debug_assert_eq!(msg_buffer.last(), Some(&0));
Expand Down