difftreelog
feat upgrade bindings to new importbin result
in: master
2 files changed
bindings/jsonnet/src/import.rsdiffbeforeafterboth1//! Import resolution manipulation utilities1//! Import resolution manipulation utilities223use std::{3use std::{4 alloc::Layout,4 any::Any,5 any::Any,5 cell::RefCell,6 cell::RefCell,6 collections::HashMap,7 collections::HashMap,25 base: *const c_char,26 base: *const c_char,26 rel: *const c_char,27 rel: *const c_char,27 found_here: *mut *const c_char,28 found_here: *mut *const c_char,28 success: &mut c_int,29 buf: *mut *mut c_char,30 buflen: *mut usize,29) -> *mut c_char;31) -> c_int;303231/// Resolves imports using callback33/// Resolves imports using callback32#[derive(Trace)]34#[derive(Trace)]54 let rel = CString::new(path).unwrap();56 let rel = CString::new(path).unwrap();55 let found_here: *mut c_char = null_mut();57 let found_here: *mut c_char = null_mut();5859 let mut buf = null_mut();56 let mut success: i32 = 0;60 let mut buf_len = 0;57 let result_ptr = unsafe {61 let success = unsafe {58 (self.cb)(62 (self.cb)(59 self.ctx,63 self.ctx,60 base.as_ptr(),64 base.as_ptr(),61 rel.as_ptr(),65 rel.as_ptr(),62 &mut (found_here as *const _),66 &mut (found_here as *const _),63 &mut success,67 &mut buf,68 &mut buf_len,64 )69 )65 };70 };66 let result_raw = unsafe { CStr::from_ptr(result_ptr) };71 let buf_slice: &[u8] = unsafe { std::slice::from_raw_parts(buf.cast(), buf_len) };72 unsafe {73 std::alloc::dealloc(74 buf.cast(),75 Layout::from_size_align(buf_len, 1).expect("layout is valid"),76 );77 };67 let result_str = result_raw.to_str().unwrap();78 let buf_intern = buf_slice.to_vec();7968 assert!(success == 0 || success == 1);80 assert!(success == 0 || success == 1);69 if success == 0 {81 if success == 0 {70 unsafe { CString::from_raw(result_ptr) };71 let result = result_str.to_owned();82 let result = String::from_utf8(buf_intern).expect("error should be valid string");72 throw!(ImportCallbackError(result));83 throw!(ImportCallbackError(result));73 }84 }7485829383 let mut out = self.out.borrow_mut();94 let mut out = self.out.borrow_mut();84 if !out.contains_key(&found_here_buf) {95 if !out.contains_key(&found_here_buf) {85 out.insert(found_here_buf.clone(), result_str.into());96 out.insert(found_here_buf.clone(), buf_intern);86 unsafe { CString::from_raw(result_ptr) };87 }97 }889889 Ok(found_here_buf)99 Ok(found_here_buf)bindings/jsonnet/src/lib.rsdiffbeforeafterboth40/// then there is a mismatch between header and compiled library.40/// then there is a mismatch between header and compiled library.41#[no_mangle]41#[no_mangle]42pub extern "C" fn jsonnet_version() -> &'static [u8; 8] {42pub extern "C" fn jsonnet_version() -> &'static [u8; 8] {43 b"v0.16.0\0"43 b"v0.19.1\0"44}44}454546unsafe fn parse_path(input: &CStr) -> Cow<Path> {46unsafe fn parse_path(input: &CStr) -> Cow<Path> {