Skip to content

Commit 7e097e1

Browse files
committed
fix: fix protobuf error
Signed-off-by: zongz <[email protected]>
1 parent 3ffb82e commit 7e097e1

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/lib.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
//! }
2727
//! ```
2828
29-
use std::ffi::{CStr, CString};
29+
use std::ffi::CString;
3030

3131
pub use kclvm_api::gpyrpc::*;
3232
use kclvm_api::service::capi::{kclvm_service_call_with_length, kclvm_service_new};
@@ -36,14 +36,21 @@ use anyhow::Result;
3636

3737
pub type API = KclvmServiceImpl;
3838

39-
pub fn call<'a>(name: &'a [u8], args: &'a [u8]) -> Result<&'a [u8]> {
39+
pub fn call<'a>(name: &'a [u8], args: &'a [u8]) -> Result<Vec<u8>> {
40+
let mut result_len: usize = 0;
4041
let result_ptr = {
4142
let args = CString::new(args)?;
4243
let call = CString::new(name)?;
4344
let serv = kclvm_service_new(0);
44-
let mut result_len: usize = 0;
4545
kclvm_service_call_with_length(serv, call.as_ptr(), args.as_ptr(), &mut result_len)
4646
};
47-
let result = unsafe { CStr::from_ptr(result_ptr) };
48-
Ok(result.to_bytes())
47+
let result = unsafe {
48+
let mut dest_data: Vec<u8> = Vec::with_capacity(result_len);
49+
let dest_ptr: *mut u8 = dest_data.as_mut_ptr();
50+
std::ptr::copy_nonoverlapping(result_ptr as *const u8, dest_ptr, result_len);
51+
dest_data.set_len(result_len);
52+
dest_data
53+
};
54+
55+
Ok(result)
4956
}

0 commit comments

Comments
 (0)