pibench_parser/
c_ffi.rs

1use super::PiBenchData;
2use libc::c_char;
3use std::ffi::{CStr, CString};
4
5#[no_mangle]
6pub extern "C" fn text_to_json(text: *const c_char) -> *mut c_char {
7    let c_str = unsafe {
8        assert!(!text.is_null());
9        CStr::from_ptr(text).to_str().unwrap()
10    };
11    let rv = PiBenchData::from_text(c_str).unwrap().to_json();
12    let c_str_rv = CString::new(rv).unwrap();
13    c_str_rv.into_raw()
14}
15
16#[no_mangle]
17pub extern "C" fn free_json_str(val: *mut c_char) {
18    unsafe {
19        if val.is_null() {
20            return;
21        }
22        CString::from_raw(val);
23    }
24}