File tree 1 file changed +12
-5
lines changed
1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change 26
26
//! }
27
27
//! ```
28
28
29
- use std:: ffi:: { CStr , CString } ;
29
+ use std:: ffi:: CString ;
30
30
31
31
pub use kclvm_api:: gpyrpc:: * ;
32
32
use kclvm_api:: service:: capi:: { kclvm_service_call_with_length, kclvm_service_new} ;
@@ -36,14 +36,21 @@ use anyhow::Result;
36
36
37
37
pub type API = KclvmServiceImpl ;
38
38
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 ;
40
41
let result_ptr = {
41
42
let args = CString :: new ( args) ?;
42
43
let call = CString :: new ( name) ?;
43
44
let serv = kclvm_service_new ( 0 ) ;
44
- let mut result_len: usize = 0 ;
45
45
kclvm_service_call_with_length ( serv, call. as_ptr ( ) , args. as_ptr ( ) , & mut result_len)
46
46
} ;
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)
49
56
}
You can’t perform that action at this time.
0 commit comments