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

fix: fix #1776 use assert add no overhead on release version #1781

Merged
merged 3 commits into from
Dec 24, 2024
Merged
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
6 changes: 6 additions & 0 deletions kclvm/runtime/src/api/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ pub fn mut_ptr_as_ref<'a, T>(p: *mut T) -> &'a mut T {

/// Copy str to mutable pointer with length
pub(crate) fn copy_str_to(v: &str, p: *mut c_char, size: *mut kclvm_size_t) {
assert!(!p.is_null() || !size.is_null());

unsafe {
let c_str_ptr = v.as_ptr() as *const c_char;
let c_str_len = v.len() as i32;
Expand All @@ -55,12 +57,16 @@ pub(crate) fn copy_str_to(v: &str, p: *mut c_char, size: *mut kclvm_size_t) {
/// Convert a C str pointer to a Rust &str.
/// Safety: The caller must ensure that `s` is a valid null-terminated C string.
pub fn c2str<'a>(p: *const c_char) -> &'a str {
assert!(!p.is_null());

let s = unsafe { std::ffi::CStr::from_ptr(p) }.to_str().unwrap();
s
}

/// Convert a C str pointer pointer to a Rust Vec<String>.
pub fn c2str_vec(ptr_array: *const *const c_char) -> Vec<String> {
assert!(!ptr_array.is_null());

let mut result = Vec::new();
let mut index = 0;

Expand Down
Loading