plugin_framework, debug config, mid commit

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou
2023-04-24 18:45:22 +08:00
parent 8340573277
commit d8dc56a743
15 changed files with 623 additions and 276 deletions

View File

@@ -1,4 +1,4 @@
use hbb_common::ResultType;
use hbb_common::{libc, ResultType};
use std::ffi::{c_char, c_void, CStr};
mod callback_msg;
@@ -27,6 +27,21 @@ fn cstr_to_string(cstr: *const c_char) -> ResultType<String> {
})?)
}
#[inline]
pub fn str_to_cstr_ret(s: &str) -> *const c_char {
let mut s = s.as_bytes().to_vec();
s.push(0);
unsafe {
let r = libc::malloc(s.len()) as *mut c_char;
libc::memcpy(
r as *mut libc::c_void,
s.as_ptr() as *const libc::c_void,
s.len(),
);
r
}
}
#[inline]
fn get_code_msg_from_ret(ret: *const c_void) -> (i32, String) {
assert!(ret.is_null() == false);
@@ -38,3 +53,12 @@ fn get_code_msg_from_ret(ret: *const c_void) -> (i32, String) {
.to_string();
(code, msg)
}
#[inline]
fn free_c_ptr(ret: *mut c_void) {
if !ret.is_null() {
unsafe {
libc::free(ret);
}
}
}