difftreelog
fix(libjsonnet) update to rust 2024
in: master
8 files changed
bindings/jsonnet/src/import.rsdiffbeforeafterboth107/// # Safety107/// # Safety108///108///109/// It should be safe to call `cb` using valid values with passed `ctx`109/// It should be safe to call `cb` using valid values with passed `ctx`110#[no_mangle]110#[unsafe(no_mangle)]111pub unsafe extern "C" fn jsonnet_import_callback(111pub unsafe extern "C" fn jsonnet_import_callback(112 vm: &VM,112 vm: &VM,113 cb: JsonnetImportCallback,113 cb: JsonnetImportCallback,123/// # Safety123/// # Safety124///124///125/// `path` should be a NUL-terminated string125/// `path` should be a NUL-terminated string126#[no_mangle]126#[unsafe(no_mangle)]127pub unsafe extern "C" fn jsonnet_jpath_add(vm: &VM, path: *const c_char) {127pub unsafe extern "C" fn jsonnet_jpath_add(vm: &VM, path: *const c_char) {128 let cstr = unsafe { CStr::from_ptr(path) };128 let cstr = unsafe { CStr::from_ptr(path) };129 let path = PathBuf::from(cstr.to_str().unwrap());129 let path = PathBuf::from(cstr.to_str().unwrap());bindings/jsonnet/src/interop.rsdiffbeforeafterboth889 use crate::VM;9 use crate::VM;101011 extern "C" {11 unsafe extern "C" {1213 pub fn _jrsonnet_static_import_callback(12 pub fn _jrsonnet_static_import_callback(14 ctx: *mut c_void,13 ctx: *mut c_void,27 ) -> *mut Val;26 ) -> *mut Val;28 }27 }292830 #[no_mangle]29 #[unsafe(no_mangle)]31 #[cfg(feature = "interop-wasm")]30 #[cfg(feature = "interop-wasm")]32 // ctx arg is passed as-is to callback31 // ctx arg is passed as-is to callback33 #[allow(clippy::not_unsafe_ptr_arg_deref)]32 #[allow(clippy::not_unsafe_ptr_arg_deref)]38 /// # Safety37 /// # Safety39 ///38 ///40 /// `name` and `raw_params` should be correctly initialized39 /// `name` and `raw_params` should be correctly initialized41 #[no_mangle]40 #[unsafe(no_mangle)]42 #[cfg(feature = "interop-wasm")]41 #[cfg(feature = "interop-wasm")]43 pub unsafe extern "C" fn jrsonnet_apply_static_native_callback(42 pub unsafe extern "C" fn jrsonnet_apply_static_native_callback(44 vm: &VM,43 vm: &VM,646365 use crate::VM;64 use crate::VM;666567 #[no_mangle]66 #[unsafe(no_mangle)]68 pub extern "C" fn jrsonnet_set_trace_format(vm: &mut VM, format: u8) {67 pub extern "C" fn jrsonnet_set_trace_format(vm: &mut VM, format: u8) {69 match format {68 match format {70 0 => {69 0 => {105 ///104 ///106 /// Current thread GC will be broken after this call, need to call105 /// Current thread GC will be broken after this call, need to call107 /// `jrsonet_enter_thread` before doing anything.106 /// `jrsonet_enter_thread` before doing anything.108 #[no_mangle]107 #[unsafe(no_mangle)]109 pub unsafe extern "C" fn jrsonnet_exit_thread() -> *mut ThreadCTX {108 pub unsafe extern "C" fn jrsonnet_exit_thread() -> *mut ThreadCTX {110 Box::into_raw(Box::new(ThreadCTX {109 Box::into_raw(Box::new(ThreadCTX {111 interner: jrsonnet_interner::interop::exit_thread(),110 interner: jrsonnet_interner::interop::exit_thread(),112 gc: unsafe { jrsonnet_gcmodule::interop::exit_thread() },111 gc: unsafe { jrsonnet_gcmodule::interop::exit_thread() },113 }))112 }))114 }113 }115114116 #[no_mangle]115 #[unsafe(no_mangle)]117 pub extern "C" fn jrsonnet_reenter_thread(mut ctx: Box<ThreadCTX>) {116 pub extern "C" fn jrsonnet_reenter_thread(mut ctx: Box<ThreadCTX>) {118 use std::ptr::null_mut;117 use std::ptr::null_mut;119 assert!(118 assert!(132 // boxing.131 // boxing.133 pub enum JrThreadId {}132 pub enum JrThreadId {}134133135 #[no_mangle]134 #[unsafe(no_mangle)]136 pub extern "C" fn jrsonnet_thread_id() -> *mut JrThreadId {135 pub extern "C" fn jrsonnet_thread_id() -> *mut JrThreadId {137 Box::into_raw(Box::new(std::thread::current().id())).cast()136 Box::into_raw(Box::new(std::thread::current().id())).cast()138 }137 }139138140 #[no_mangle]139 #[unsafe(no_mangle)]141 pub extern "C" fn jrsonnet_thread_id_compare(140 pub extern "C" fn jrsonnet_thread_id_compare(142 a: *const JrThreadId,141 a: *const JrThreadId,143 b: *const JrThreadId,142 b: *const JrThreadId,147 i32::from(*a == *b)146 i32::from(*a == *b)148 }147 }149148150 #[no_mangle]149 #[unsafe(no_mangle)]151 pub unsafe extern "C" fn jrsonnet_thread_id_free(id: *mut JrThreadId) {150 pub unsafe extern "C" fn jrsonnet_thread_id_free(id: *mut JrThreadId) {152 let _id: Box<ThreadId> = unsafe { Box::from_raw(id.cast()) };151 let _id: Box<ThreadId> = unsafe { Box::from_raw(id.cast()) };153 }152 }bindings/jsonnet/src/lib.rsdiffbeforeafterboth43/// Conforms to [semantic versioning](http://semver.org/).43/// Conforms to [semantic versioning](http://semver.org/).44/// If this does not match `LIB_JSONNET_VERSION`44/// If this does not match `LIB_JSONNET_VERSION`45/// then there is a mismatch between header and compiled library.45/// then there is a mismatch between header and compiled library.46#[no_mangle]46#[unsafe(no_mangle)]47pub extern "C" fn jsonnet_version() -> &'static [u8; 12] {47pub extern "C" fn jsonnet_version() -> &'static [u8; 12] {48 b"v0.22.0-rc1\0"48 b"v0.22.0-rc1\0"49}49}130}130}131131132/// Creates a new Jsonnet virtual machine.132/// Creates a new Jsonnet virtual machine.133#[no_mangle]133#[unsafe(no_mangle)]134#[allow(clippy::box_default)]134#[allow(clippy::box_default)]135pub extern "C" fn jsonnet_make() -> *mut VM {135pub extern "C" fn jsonnet_make() -> *mut VM {136 let mut state = State::builder();136 let mut state = State::builder();147}147}148148149/// Complement of [`jsonnet_vm_make`].149/// Complement of [`jsonnet_vm_make`].150#[no_mangle]150#[unsafe(no_mangle)]151#[allow(clippy::boxed_local)]151#[allow(clippy::boxed_local)]152pub extern "C" fn jsonnet_destroy(vm: Box<VM>) {152pub extern "C" fn jsonnet_destroy(vm: Box<VM>) {153 drop(vm);153 drop(vm);154}154}155155156/// Set the maximum stack depth.156/// Set the maximum stack depth.157#[no_mangle]157#[unsafe(no_mangle)]158pub extern "C" fn jsonnet_max_stack(_vm: &VM, v: c_uint) {158pub extern "C" fn jsonnet_max_stack(_vm: &VM, v: c_uint) {159 set_stack_depth_limit(v as usize);159 set_stack_depth_limit(v as usize);160}160}161161162/// Set the number of objects required before a garbage collection cycle is allowed.162/// Set the number of objects required before a garbage collection cycle is allowed.163///163///164/// No-op for now164/// No-op for now165#[no_mangle]165#[unsafe(no_mangle)]166pub extern "C" fn jsonnet_gc_min_objects(_vm: &VM, _v: c_uint) {}166pub extern "C" fn jsonnet_gc_min_objects(_vm: &VM, _v: c_uint) {}167167168/// Run the garbage collector after this amount of growth in the number of objects168/// Run the garbage collector after this amount of growth in the number of objects169///169///170/// No-op for now170/// No-op for now171#[no_mangle]171#[unsafe(no_mangle)]172pub extern "C" fn jsonnet_gc_growth_trigger(_vm: &VM, _v: c_double) {}172pub extern "C" fn jsonnet_gc_growth_trigger(_vm: &VM, _v: c_double) {}173173174/// Expect a string as output and don't JSON encode it.174/// Expect a string as output and don't JSON encode it.175#[no_mangle]175#[unsafe(no_mangle)]176pub extern "C" fn jsonnet_string_output(vm: &mut VM, v: c_int) {176pub extern "C" fn jsonnet_string_output(vm: &mut VM, v: c_int) {177 vm.manifest_format = match v {177 vm.manifest_format = match v {178 0 => Box::new(JsonFormat::default()),178 0 => Box::new(JsonFormat::default()),189/// `buf` should be either previosly allocated by this library, or NULL189/// `buf` should be either previosly allocated by this library, or NULL190///190///191/// This function is most definitely broken, but it works somehow, see TODO inside191/// This function is most definitely broken, but it works somehow, see TODO inside192#[no_mangle]192#[unsafe(no_mangle)]193pub unsafe extern "C" fn jsonnet_realloc(_vm: &VM, buf: *mut u8, sz: usize) -> *mut u8 {193pub unsafe extern "C" fn jsonnet_realloc(_vm: &VM, buf: *mut u8, sz: usize) -> *mut u8 {194 if buf.is_null() {194 if buf.is_null() {195 if sz == 0 {195 if sz == 0 {214/// Clean up a JSON subtree.214/// Clean up a JSON subtree.215///215///216/// This is useful if you want to abort with an error mid-way through building a complex value.216/// This is useful if you want to abort with an error mid-way through building a complex value.217#[no_mangle]217#[unsafe(no_mangle)]218#[allow(clippy::boxed_local)]218#[allow(clippy::boxed_local)]219pub extern "C" fn jsonnet_json_destroy(_vm: &VM, v: Box<Val>) {219pub extern "C" fn jsonnet_json_destroy(_vm: &VM, v: Box<Val>) {220 drop(v);220 drop(v);221}221}222222223/// Set the number of lines of stack trace to display (0 for all of them).223/// Set the number of lines of stack trace to display (0 for all of them).224#[no_mangle]224#[unsafe(no_mangle)]225pub extern "C" fn jsonnet_max_trace(vm: &mut VM, v: c_uint) {225pub extern "C" fn jsonnet_max_trace(vm: &mut VM, v: c_uint) {226 if let Some(format) = vm.trace_format.as_any_mut().downcast_mut::<CompactFormat>() {226 if let Some(format) = vm.trace_format.as_any_mut().downcast_mut::<CompactFormat>() {227 format.max_trace = v as usize;227 format.max_trace = v as usize;237/// # Safety237/// # Safety238///238///239/// `filename` should be a NUL-terminated string239/// `filename` should be a NUL-terminated string240#[no_mangle]240#[unsafe(no_mangle)]241pub unsafe extern "C" fn jsonnet_evaluate_file(241pub unsafe extern "C" fn jsonnet_evaluate_file(242 vm: &VM,242 vm: &VM,243 filename: *const c_char,243 filename: *const c_char,270/// # Safety270/// # Safety271///271///272/// `filename`, `snippet` should be a NUL-terminated strings272/// `filename`, `snippet` should be a NUL-terminated strings273#[no_mangle]273#[unsafe(no_mangle)]274pub unsafe extern "C" fn jsonnet_evaluate_snippet(274pub unsafe extern "C" fn jsonnet_evaluate_snippet(275 vm: &VM,275 vm: &VM,276 filename: *const c_char,276 filename: *const c_char,330}330}331331332/// # Safety332/// # Safety333#[no_mangle]333#[unsafe(no_mangle)]334pub unsafe extern "C" fn jsonnet_evaluate_file_multi(334pub unsafe extern "C" fn jsonnet_evaluate_file_multi(335 vm: &VM,335 vm: &VM,336 filename: *const c_char,336 filename: *const c_char,357}357}358358359/// # Safety359/// # Safety360#[no_mangle]360#[unsafe(no_mangle)]361pub unsafe extern "C" fn jsonnet_evaluate_snippet_multi(361pub unsafe extern "C" fn jsonnet_evaluate_snippet_multi(362 vm: &VM,362 vm: &VM,363 filename: *const c_char,363 filename: *const c_char,412}412}413413414/// # Safety414/// # Safety415#[no_mangle]415#[unsafe(no_mangle)]416pub unsafe extern "C" fn jsonnet_evaluate_file_stream(416pub unsafe extern "C" fn jsonnet_evaluate_file_stream(417 vm: &VM,417 vm: &VM,418 filename: *const c_char,418 filename: *const c_char,439}439}440440441/// # Safety441/// # Safety442#[no_mangle]442#[unsafe(no_mangle)]443pub unsafe extern "C" fn jsonnet_evaluate_snippet_stream(443pub unsafe extern "C" fn jsonnet_evaluate_snippet_stream(444 vm: &VM,444 vm: &VM,445 filename: *const c_char,445 filename: *const c_char,bindings/jsonnet/src/native.rsdiffbeforeafterboth62/// `name` should be a NUL-terminated string62/// `name` should be a NUL-terminated string63/// `cb` should be a function pointer63/// `cb` should be a function pointer64/// `raw_params` should point to a NULL-terminated array of NUL-terminated strings64/// `raw_params` should point to a NULL-terminated array of NUL-terminated strings65#[no_mangle]65#[unsafe(no_mangle)]66pub unsafe extern "C" fn jsonnet_native_callback(66pub unsafe extern "C" fn jsonnet_native_callback(67 vm: &VM,67 vm: &VM,68 name: *const c_char,68 name: *const c_char,82 .expect("param name is not utf-8")82 .expect("param name is not utf-8")83 };83 };84 params.push(param.into());84 params.push(param.into());85 raw_params = unsafe { raw_params.offset(1) };85 raw_params = unsafe { raw_params.add(1) };86 }86 }878788 let any_resolver = vm.state.context_initializer();88 let any_resolver = vm.state.context_initializer();bindings/jsonnet/src/val_extract.rsdiffbeforeafterboth10use crate::VM;10use crate::VM;111112/// If the value is a string, return it as UTF-8, otherwise return `NULL`.12/// If the value is a string, return it as UTF-8, otherwise return `NULL`.13#[no_mangle]13#[unsafe(no_mangle)]14pub extern "C" fn jsonnet_json_extract_string(_vm: &VM, v: &Val) -> *mut c_char {14pub extern "C" fn jsonnet_json_extract_string(_vm: &VM, v: &Val) -> *mut c_char {15 match v {15 match v {16 Val::Str(s) => {16 Val::Str(s) => {22}22}232324/// If the value is a number, return `1` and store the number in out, otherwise return `0`.24/// If the value is a number, return `1` and store the number in out, otherwise return `0`.25#[no_mangle]25#[unsafe(no_mangle)]26pub extern "C" fn jsonnet_json_extract_number(_vm: &VM, v: &Val, out: &mut c_double) -> c_int {26pub extern "C" fn jsonnet_json_extract_number(_vm: &VM, v: &Val, out: &mut c_double) -> c_int {27 match v {27 match v {28 Val::Num(n) => {28 Val::Num(n) => {34}34}353536/// Return `0` if the value is `false`, `1` if it is `true`, and `2` if it is not a `bool`.36/// Return `0` if the value is `false`, `1` if it is `true`, and `2` if it is not a `bool`.37#[no_mangle]37#[unsafe(no_mangle)]38pub extern "C" fn jsonnet_json_extract_bool(_vm: &VM, v: &Val) -> c_int {38pub extern "C" fn jsonnet_json_extract_bool(_vm: &VM, v: &Val) -> c_int {39 match v {39 match v {40 Val::Bool(false) => 0,40 Val::Bool(false) => 0,44}44}454546/// Return `1` if the value is `null`, otherwise return `0`.46/// Return `1` if the value is `null`, otherwise return `0`.47#[no_mangle]47#[unsafe(no_mangle)]48pub extern "C" fn jsonnet_json_extract_null(_vm: &VM, v: &Val) -> c_int {48pub extern "C" fn jsonnet_json_extract_null(_vm: &VM, v: &Val) -> c_int {49 match v {49 match v {50 Val::Null => 1,50 Val::Null => 1,bindings/jsonnet/src/val_make.rsdiffbeforeafterboth14/// # Safety14/// # Safety15///15///16/// `v` should be a NUL-terminated string16/// `v` should be a NUL-terminated string17#[no_mangle]17#[unsafe(no_mangle)]18pub unsafe extern "C" fn jsonnet_json_make_string(_vm: &VM, val: *const c_char) -> *mut Val {18pub unsafe extern "C" fn jsonnet_json_make_string(_vm: &VM, val: *const c_char) -> *mut Val {19 let val = unsafe { CStr::from_ptr(val) };19 let val = unsafe { CStr::from_ptr(val) };20 let val = val.to_str().expect("string is not utf-8");20 let val = val.to_str().expect("string is not utf-8");21 Box::into_raw(Box::new(Val::string(val)))21 Box::into_raw(Box::new(Val::string(val)))22}22}232324/// Convert the given double to a `JsonnetJsonValue`.24/// Convert the given double to a `JsonnetJsonValue`.25#[no_mangle]25#[unsafe(no_mangle)]26pub extern "C" fn jsonnet_json_make_number(_vm: &VM, v: c_double) -> *mut Val {26pub extern "C" fn jsonnet_json_make_number(_vm: &VM, v: c_double) -> *mut Val {27 Box::into_raw(Box::new(Val::Num(27 Box::into_raw(Box::new(Val::Num(28 NumValue::new(v).expect("jsonnet numbers are finite"),28 NumValue::new(v).expect("jsonnet numbers are finite"),29 )))29 )))30}30}313132/// Convert the given `bool` (`1` or `0`) to a `JsonnetJsonValue`.32/// Convert the given `bool` (`1` or `0`) to a `JsonnetJsonValue`.33#[no_mangle]33#[unsafe(no_mangle)]34pub extern "C" fn jsonnet_json_make_bool(_vm: &VM, v: c_int) -> *mut Val {34pub extern "C" fn jsonnet_json_make_bool(_vm: &VM, v: c_int) -> *mut Val {35 assert!(v == 0 || v == 1, "bad boolean value");35 assert!(v == 0 || v == 1, "bad boolean value");36 Box::into_raw(Box::new(Val::Bool(v == 1)))36 Box::into_raw(Box::new(Val::Bool(v == 1)))37}37}383839/// Make a `JsonnetJsonValue` representing `null`.39/// Make a `JsonnetJsonValue` representing `null`.40#[no_mangle]40#[unsafe(no_mangle)]41pub extern "C" fn jsonnet_json_make_null(_vm: &VM) -> *mut Val {41pub extern "C" fn jsonnet_json_make_null(_vm: &VM) -> *mut Val {42 Box::into_raw(Box::new(Val::Null))42 Box::into_raw(Box::new(Val::Null))43}43}444445/// Make a `JsonnetJsonValue` representing an array.45/// Make a `JsonnetJsonValue` representing an array.46///46///47/// Assign elements with [`jsonnet_json_array_append`].47/// Assign elements with [`jsonnet_json_array_append`].48#[no_mangle]48#[unsafe(no_mangle)]49pub extern "C" fn jsonnet_json_make_array(_vm: &VM) -> *mut Val {49pub extern "C" fn jsonnet_json_make_array(_vm: &VM) -> *mut Val {50 Box::into_raw(Box::new(Val::arr(())))50 Box::into_raw(Box::new(Val::arr(())))51}51}525253/// Make a `JsonnetJsonValue` representing an object.53/// Make a `JsonnetJsonValue` representing an object.54#[no_mangle]54#[unsafe(no_mangle)]55pub extern "C" fn jsonnet_json_make_object(_vm: &VM) -> *mut Val {55pub extern "C" fn jsonnet_json_make_object(_vm: &VM) -> *mut Val {56 Box::into_raw(Box::new(Val::Obj(ObjValue::empty())))56 Box::into_raw(Box::new(Val::Obj(ObjValue::empty())))57}57}bindings/jsonnet/src/val_modify.rsdiffbeforeafterboth14///14///15/// `arr` should be a pointer to array value allocated by `make_array`, or returned by other library call15/// `arr` should be a pointer to array value allocated by `make_array`, or returned by other library call16/// `val` should be a pointer to value allocated using this library16/// `val` should be a pointer to value allocated using this library17#[no_mangle]17#[unsafe(no_mangle)]18pub unsafe extern "C" fn jsonnet_json_array_append(_vm: &VM, arr: &mut Val, val: &Val) {18pub unsafe extern "C" fn jsonnet_json_array_append(_vm: &VM, arr: &mut Val, val: &Val) {19 match arr {19 match arr {20 Val::Arr(old) => {20 Val::Arr(old) => {38///38///39/// `obj` should be a pointer to object value allocated by `make_object`, or returned by other library call39/// `obj` should be a pointer to object value allocated by `make_object`, or returned by other library call40/// `name` should be NUL-terminated string40/// `name` should be NUL-terminated string41#[no_mangle]41#[unsafe(no_mangle)]42pub unsafe extern "C" fn jsonnet_json_object_append(42pub unsafe extern "C" fn jsonnet_json_object_append(43 _vm: &VM,43 _vm: &VM,44 obj: &mut Val,44 obj: &mut Val,bindings/jsonnet/src/vars_tlas.rsdiffbeforeafterboth13/// # Safety13/// # Safety14///14///15/// `name`, `code` should be a NUL-terminated strings15/// `name`, `code` should be a NUL-terminated strings16#[no_mangle]16#[unsafe(no_mangle)]17pub unsafe extern "C" fn jsonnet_ext_var(vm: &VM, name: *const c_char, value: *const c_char) {17pub unsafe extern "C" fn jsonnet_ext_var(vm: &VM, name: *const c_char, value: *const c_char) {18 let name = unsafe { CStr::from_ptr(name) };18 let name = unsafe { CStr::from_ptr(name) };19 let value = unsafe { CStr::from_ptr(value) };19 let value = unsafe { CStr::from_ptr(value) };36/// # Safety36/// # Safety37///37///38/// `name`, `code` should be a NUL-terminated strings38/// `name`, `code` should be a NUL-terminated strings39#[no_mangle]39#[unsafe(no_mangle)]40pub unsafe extern "C" fn jsonnet_ext_code(vm: &VM, name: *const c_char, code: *const c_char) {40pub unsafe extern "C" fn jsonnet_ext_code(vm: &VM, name: *const c_char, code: *const c_char) {41 let name = unsafe { CStr::from_ptr(name) };41 let name = unsafe { CStr::from_ptr(name) };42 let code = unsafe { CStr::from_ptr(code) };42 let code = unsafe { CStr::from_ptr(code) };60/// # Safety60/// # Safety61///61///62/// `name`, `value` should be a NUL-terminated strings62/// `name`, `value` should be a NUL-terminated strings63#[no_mangle]63#[unsafe(no_mangle)]64pub unsafe extern "C" fn jsonnet_tla_var(vm: &mut VM, name: *const c_char, value: *const c_char) {64pub unsafe extern "C" fn jsonnet_tla_var(vm: &mut VM, name: *const c_char, value: *const c_char) {65 let name = unsafe { CStr::from_ptr(name) };65 let name = unsafe { CStr::from_ptr(name) };66 let value = unsafe { CStr::from_ptr(value) };66 let value = unsafe { CStr::from_ptr(value) };77/// # Safety77/// # Safety78///78///79/// `name`, `code` should be a NUL-terminated strings79/// `name`, `code` should be a NUL-terminated strings80#[no_mangle]80#[unsafe(no_mangle)]81pub unsafe extern "C" fn jsonnet_tla_code(vm: &mut VM, name: *const c_char, code: *const c_char) {81pub unsafe extern "C" fn jsonnet_tla_code(vm: &mut VM, name: *const c_char, code: *const c_char) {82 let name = unsafe { CStr::from_ptr(name) };82 let name = unsafe { CStr::from_ptr(name) };83 let code = unsafe { CStr::from_ptr(code) };83 let code = unsafe { CStr::from_ptr(code) };