difftreelog
fix(libjsonnet) update to rust 2024
in: master
8 files changed
bindings/jsonnet/src/import.rsdiffbeforeafterboth--- a/bindings/jsonnet/src/import.rs
+++ b/bindings/jsonnet/src/import.rs
@@ -107,7 +107,7 @@
/// # Safety
///
/// It should be safe to call `cb` using valid values with passed `ctx`
-#[no_mangle]
+#[unsafe(no_mangle)]
pub unsafe extern "C" fn jsonnet_import_callback(
vm: &VM,
cb: JsonnetImportCallback,
@@ -123,7 +123,7 @@
/// # Safety
///
/// `path` should be a NUL-terminated string
-#[no_mangle]
+#[unsafe(no_mangle)]
pub unsafe extern "C" fn jsonnet_jpath_add(vm: &VM, path: *const c_char) {
let cstr = unsafe { CStr::from_ptr(path) };
let path = PathBuf::from(cstr.to_str().unwrap());
bindings/jsonnet/src/interop.rsdiffbeforeafterboth1//! Jrsonnet specific additional binding helpers23#[cfg(feature = "interop-wasm")]4pub mod wasm {5 use std::ffi::{c_char, c_int, c_void};67 use jrsonnet_evaluator::Val;89 use crate::VM;1011 extern "C" {1213 pub fn _jrsonnet_static_import_callback(14 ctx: *mut c_void,15 base: *const c_char,16 rel: *const c_char,17 found_here: *mut *const c_char,18 buf: *mut *mut c_char,19 buflen: *mut usize,20 ) -> c_int;2122 #[allow(improper_ctypes)]23 pub fn _jrsonnet_static_native_callback(24 ctx: *const c_void,25 argv: *const *const Val,26 success: *mut c_int,27 ) -> *mut Val;28 }2930 #[no_mangle]31 #[cfg(feature = "interop-wasm")]32 // ctx arg is passed as-is to callback33 #[allow(clippy::not_unsafe_ptr_arg_deref)]34 pub extern "C" fn jrsonnet_apply_static_import_callback(vm: &VM, ctx: *mut c_void) {35 unsafe { crate::import::jsonnet_import_callback(vm, _jrsonnet_static_import_callback, ctx) }36 }3738 /// # Safety39 ///40 /// `name` and `raw_params` should be correctly initialized41 #[no_mangle]42 #[cfg(feature = "interop-wasm")]43 pub unsafe extern "C" fn jrsonnet_apply_static_native_callback(44 vm: &VM,45 name: *const c_char,46 ctx: *mut c_void,47 raw_params: *const *const c_char,48 ) {49 unsafe {50 crate::native::jsonnet_native_callback(51 vm,52 name,53 _jrsonnet_static_native_callback,54 ctx,55 raw_params,56 );57 }58 }59}6061#[cfg(feature = "interop-common")]62mod common {63 use jrsonnet_evaluator::trace::{CompactFormat, HiDocFormat, JsFormat, PathResolver};6465 use crate::VM;6667 #[no_mangle]68 pub extern "C" fn jrsonnet_set_trace_format(vm: &mut VM, format: u8) {69 match format {70 0 => {71 vm.trace_format = Box::new(CompactFormat {72 max_trace: 20,73 resolver: PathResolver::new_cwd_fallback(),74 padding: 4,75 });76 }77 1 => vm.trace_format = Box::new(JsFormat { max_trace: 20 }),78 2 => {79 vm.trace_format = Box::new(HiDocFormat {80 resolver: PathResolver::new_cwd_fallback(),81 max_trace: 20,82 });83 }84 _ => panic!("unknown trace format"),85 }86 }87}8889#[cfg(feature = "interop-threading")]90mod threading {91 use std::{ffi::c_int, thread::ThreadId};9293 pub struct ThreadCTX {94 interner: *mut jrsonnet_interner::interop::PoolState,95 gc: *mut jrsonnet_gcmodule::interop::GcState,96 }9798 /// Golang jrsonnet bindings require Jsonnet VM to be movable.99 /// Jrsonnet uses `thread_local` in some places, thus making VM100 /// immovable by default. By using `jrsonnet_exit_thread` and101 /// `jrsonnet_reenter_thread`, you can move `thread_local` state to102 /// where it is more convinient to use it.103 ///104 /// # Safety105 ///106 /// Current thread GC will be broken after this call, need to call107 /// `jrsonet_enter_thread` before doing anything.108 #[no_mangle]109 pub unsafe extern "C" fn jrsonnet_exit_thread() -> *mut ThreadCTX {110 Box::into_raw(Box::new(ThreadCTX {111 interner: jrsonnet_interner::interop::exit_thread(),112 gc: unsafe { jrsonnet_gcmodule::interop::exit_thread() },113 }))114 }115116 #[no_mangle]117 pub extern "C" fn jrsonnet_reenter_thread(mut ctx: Box<ThreadCTX>) {118 use std::ptr::null_mut;119 assert!(120 !ctx.interner.is_null() && !ctx.gc.is_null(),121 "reused context?"122 );123 unsafe { jrsonnet_interner::interop::reenter_thread(ctx.interner) }124 unsafe { jrsonnet_gcmodule::interop::reenter_thread(ctx.gc) }125 // Just in case126 ctx.interner = null_mut();127 ctx.gc = null_mut();128 }129130 // ThreadId is compatible with u64, and there is unstable cast131 // method... But until it is stabilized, lets erase its type by132 // boxing.133 pub enum JrThreadId {}134135 #[no_mangle]136 pub extern "C" fn jrsonnet_thread_id() -> *mut JrThreadId {137 Box::into_raw(Box::new(std::thread::current().id())).cast()138 }139140 #[no_mangle]141 pub extern "C" fn jrsonnet_thread_id_compare(142 a: *const JrThreadId,143 b: *const JrThreadId,144 ) -> c_int {145 let a: &ThreadId = unsafe { *a.cast() };146 let b: &ThreadId = unsafe { *b.cast() };147 i32::from(*a == *b)148 }149150 #[no_mangle]151 pub unsafe extern "C" fn jrsonnet_thread_id_free(id: *mut JrThreadId) {152 let _id: Box<ThreadId> = unsafe { Box::from_raw(id.cast()) };153 }154}1//! Jrsonnet specific additional binding helpers23#[cfg(feature = "interop-wasm")]4pub mod wasm {5 use std::ffi::{c_char, c_int, c_void};67 use jrsonnet_evaluator::Val;89 use crate::VM;1011 unsafe extern "C" {12 pub fn _jrsonnet_static_import_callback(13 ctx: *mut c_void,14 base: *const c_char,15 rel: *const c_char,16 found_here: *mut *const c_char,17 buf: *mut *mut c_char,18 buflen: *mut usize,19 ) -> c_int;2021 #[allow(improper_ctypes)]22 pub fn _jrsonnet_static_native_callback(23 ctx: *const c_void,24 argv: *const *const Val,25 success: *mut c_int,26 ) -> *mut Val;27 }2829 #[unsafe(no_mangle)]30 #[cfg(feature = "interop-wasm")]31 // ctx arg is passed as-is to callback32 #[allow(clippy::not_unsafe_ptr_arg_deref)]33 pub extern "C" fn jrsonnet_apply_static_import_callback(vm: &VM, ctx: *mut c_void) {34 unsafe { crate::import::jsonnet_import_callback(vm, _jrsonnet_static_import_callback, ctx) }35 }3637 /// # Safety38 ///39 /// `name` and `raw_params` should be correctly initialized40 #[unsafe(no_mangle)]41 #[cfg(feature = "interop-wasm")]42 pub unsafe extern "C" fn jrsonnet_apply_static_native_callback(43 vm: &VM,44 name: *const c_char,45 ctx: *mut c_void,46 raw_params: *const *const c_char,47 ) {48 unsafe {49 crate::native::jsonnet_native_callback(50 vm,51 name,52 _jrsonnet_static_native_callback,53 ctx,54 raw_params,55 );56 }57 }58}5960#[cfg(feature = "interop-common")]61mod common {62 use jrsonnet_evaluator::trace::{CompactFormat, HiDocFormat, JsFormat, PathResolver};6364 use crate::VM;6566 #[unsafe(no_mangle)]67 pub extern "C" fn jrsonnet_set_trace_format(vm: &mut VM, format: u8) {68 match format {69 0 => {70 vm.trace_format = Box::new(CompactFormat {71 max_trace: 20,72 resolver: PathResolver::new_cwd_fallback(),73 padding: 4,74 });75 }76 1 => vm.trace_format = Box::new(JsFormat { max_trace: 20 }),77 2 => {78 vm.trace_format = Box::new(HiDocFormat {79 resolver: PathResolver::new_cwd_fallback(),80 max_trace: 20,81 });82 }83 _ => panic!("unknown trace format"),84 }85 }86}8788#[cfg(feature = "interop-threading")]89mod threading {90 use std::{ffi::c_int, thread::ThreadId};9192 pub struct ThreadCTX {93 interner: *mut jrsonnet_interner::interop::PoolState,94 gc: *mut jrsonnet_gcmodule::interop::GcState,95 }9697 /// Golang jrsonnet bindings require Jsonnet VM to be movable.98 /// Jrsonnet uses `thread_local` in some places, thus making VM99 /// immovable by default. By using `jrsonnet_exit_thread` and100 /// `jrsonnet_reenter_thread`, you can move `thread_local` state to101 /// where it is more convinient to use it.102 ///103 /// # Safety104 ///105 /// Current thread GC will be broken after this call, need to call106 /// `jrsonet_enter_thread` before doing anything.107 #[unsafe(no_mangle)]108 pub unsafe extern "C" fn jrsonnet_exit_thread() -> *mut ThreadCTX {109 Box::into_raw(Box::new(ThreadCTX {110 interner: jrsonnet_interner::interop::exit_thread(),111 gc: unsafe { jrsonnet_gcmodule::interop::exit_thread() },112 }))113 }114115 #[unsafe(no_mangle)]116 pub extern "C" fn jrsonnet_reenter_thread(mut ctx: Box<ThreadCTX>) {117 use std::ptr::null_mut;118 assert!(119 !ctx.interner.is_null() && !ctx.gc.is_null(),120 "reused context?"121 );122 unsafe { jrsonnet_interner::interop::reenter_thread(ctx.interner) }123 unsafe { jrsonnet_gcmodule::interop::reenter_thread(ctx.gc) }124 // Just in case125 ctx.interner = null_mut();126 ctx.gc = null_mut();127 }128129 // ThreadId is compatible with u64, and there is unstable cast130 // method... But until it is stabilized, lets erase its type by131 // boxing.132 pub enum JrThreadId {}133134 #[unsafe(no_mangle)]135 pub extern "C" fn jrsonnet_thread_id() -> *mut JrThreadId {136 Box::into_raw(Box::new(std::thread::current().id())).cast()137 }138139 #[unsafe(no_mangle)]140 pub extern "C" fn jrsonnet_thread_id_compare(141 a: *const JrThreadId,142 b: *const JrThreadId,143 ) -> c_int {144 let a: &ThreadId = unsafe { *a.cast() };145 let b: &ThreadId = unsafe { *b.cast() };146 i32::from(*a == *b)147 }148149 #[unsafe(no_mangle)]150 pub unsafe extern "C" fn jrsonnet_thread_id_free(id: *mut JrThreadId) {151 let _id: Box<ThreadId> = unsafe { Box::from_raw(id.cast()) };152 }153}bindings/jsonnet/src/lib.rsdiffbeforeafterboth--- a/bindings/jsonnet/src/lib.rs
+++ b/bindings/jsonnet/src/lib.rs
@@ -43,7 +43,7 @@
/// Conforms to [semantic versioning](http://semver.org/).
/// If this does not match `LIB_JSONNET_VERSION`
/// then there is a mismatch between header and compiled library.
-#[no_mangle]
+#[unsafe(no_mangle)]
pub extern "C" fn jsonnet_version() -> &'static [u8; 12] {
b"v0.22.0-rc1\0"
}
@@ -130,7 +130,7 @@
}
/// Creates a new Jsonnet virtual machine.
-#[no_mangle]
+#[unsafe(no_mangle)]
#[allow(clippy::box_default)]
pub extern "C" fn jsonnet_make() -> *mut VM {
let mut state = State::builder();
@@ -147,14 +147,14 @@
}
/// Complement of [`jsonnet_vm_make`].
-#[no_mangle]
+#[unsafe(no_mangle)]
#[allow(clippy::boxed_local)]
pub extern "C" fn jsonnet_destroy(vm: Box<VM>) {
drop(vm);
}
/// Set the maximum stack depth.
-#[no_mangle]
+#[unsafe(no_mangle)]
pub extern "C" fn jsonnet_max_stack(_vm: &VM, v: c_uint) {
set_stack_depth_limit(v as usize);
}
@@ -162,17 +162,17 @@
/// Set the number of objects required before a garbage collection cycle is allowed.
///
/// No-op for now
-#[no_mangle]
+#[unsafe(no_mangle)]
pub extern "C" fn jsonnet_gc_min_objects(_vm: &VM, _v: c_uint) {}
/// Run the garbage collector after this amount of growth in the number of objects
///
/// No-op for now
-#[no_mangle]
+#[unsafe(no_mangle)]
pub extern "C" fn jsonnet_gc_growth_trigger(_vm: &VM, _v: c_double) {}
/// Expect a string as output and don't JSON encode it.
-#[no_mangle]
+#[unsafe(no_mangle)]
pub extern "C" fn jsonnet_string_output(vm: &mut VM, v: c_int) {
vm.manifest_format = match v {
0 => Box::new(JsonFormat::default()),
@@ -189,7 +189,7 @@
/// `buf` should be either previosly allocated by this library, or NULL
///
/// This function is most definitely broken, but it works somehow, see TODO inside
-#[no_mangle]
+#[unsafe(no_mangle)]
pub unsafe extern "C" fn jsonnet_realloc(_vm: &VM, buf: *mut u8, sz: usize) -> *mut u8 {
if buf.is_null() {
if sz == 0 {
@@ -214,14 +214,14 @@
/// Clean up a JSON subtree.
///
/// This is useful if you want to abort with an error mid-way through building a complex value.
-#[no_mangle]
+#[unsafe(no_mangle)]
#[allow(clippy::boxed_local)]
pub extern "C" fn jsonnet_json_destroy(_vm: &VM, v: Box<Val>) {
drop(v);
}
/// Set the number of lines of stack trace to display (0 for all of them).
-#[no_mangle]
+#[unsafe(no_mangle)]
pub extern "C" fn jsonnet_max_trace(vm: &mut VM, v: c_uint) {
if let Some(format) = vm.trace_format.as_any_mut().downcast_mut::<CompactFormat>() {
format.max_trace = v as usize;
@@ -237,7 +237,7 @@
/// # Safety
///
/// `filename` should be a NUL-terminated string
-#[no_mangle]
+#[unsafe(no_mangle)]
pub unsafe extern "C" fn jsonnet_evaluate_file(
vm: &VM,
filename: *const c_char,
@@ -270,7 +270,7 @@
/// # Safety
///
/// `filename`, `snippet` should be a NUL-terminated strings
-#[no_mangle]
+#[unsafe(no_mangle)]
pub unsafe extern "C" fn jsonnet_evaluate_snippet(
vm: &VM,
filename: *const c_char,
@@ -330,7 +330,7 @@
}
/// # Safety
-#[no_mangle]
+#[unsafe(no_mangle)]
pub unsafe extern "C" fn jsonnet_evaluate_file_multi(
vm: &VM,
filename: *const c_char,
@@ -357,7 +357,7 @@
}
/// # Safety
-#[no_mangle]
+#[unsafe(no_mangle)]
pub unsafe extern "C" fn jsonnet_evaluate_snippet_multi(
vm: &VM,
filename: *const c_char,
@@ -412,7 +412,7 @@
}
/// # Safety
-#[no_mangle]
+#[unsafe(no_mangle)]
pub unsafe extern "C" fn jsonnet_evaluate_file_stream(
vm: &VM,
filename: *const c_char,
@@ -439,7 +439,7 @@
}
/// # Safety
-#[no_mangle]
+#[unsafe(no_mangle)]
pub unsafe extern "C" fn jsonnet_evaluate_snippet_stream(
vm: &VM,
filename: *const c_char,
bindings/jsonnet/src/native.rsdiffbeforeafterboth--- a/bindings/jsonnet/src/native.rs
+++ b/bindings/jsonnet/src/native.rs
@@ -62,7 +62,7 @@
/// `name` should be a NUL-terminated string
/// `cb` should be a function pointer
/// `raw_params` should point to a NULL-terminated array of NUL-terminated strings
-#[no_mangle]
+#[unsafe(no_mangle)]
pub unsafe extern "C" fn jsonnet_native_callback(
vm: &VM,
name: *const c_char,
@@ -82,7 +82,7 @@
.expect("param name is not utf-8")
};
params.push(param.into());
- raw_params = unsafe { raw_params.offset(1) };
+ raw_params = unsafe { raw_params.add(1) };
}
let any_resolver = vm.state.context_initializer();
bindings/jsonnet/src/val_extract.rsdiffbeforeafterboth--- a/bindings/jsonnet/src/val_extract.rs
+++ b/bindings/jsonnet/src/val_extract.rs
@@ -10,7 +10,7 @@
use crate::VM;
/// If the value is a string, return it as UTF-8, otherwise return `NULL`.
-#[no_mangle]
+#[unsafe(no_mangle)]
pub extern "C" fn jsonnet_json_extract_string(_vm: &VM, v: &Val) -> *mut c_char {
match v {
Val::Str(s) => {
@@ -22,7 +22,7 @@
}
/// If the value is a number, return `1` and store the number in out, otherwise return `0`.
-#[no_mangle]
+#[unsafe(no_mangle)]
pub extern "C" fn jsonnet_json_extract_number(_vm: &VM, v: &Val, out: &mut c_double) -> c_int {
match v {
Val::Num(n) => {
@@ -34,7 +34,7 @@
}
/// Return `0` if the value is `false`, `1` if it is `true`, and `2` if it is not a `bool`.
-#[no_mangle]
+#[unsafe(no_mangle)]
pub extern "C" fn jsonnet_json_extract_bool(_vm: &VM, v: &Val) -> c_int {
match v {
Val::Bool(false) => 0,
@@ -44,7 +44,7 @@
}
/// Return `1` if the value is `null`, otherwise return `0`.
-#[no_mangle]
+#[unsafe(no_mangle)]
pub extern "C" fn jsonnet_json_extract_null(_vm: &VM, v: &Val) -> c_int {
match v {
Val::Null => 1,
bindings/jsonnet/src/val_make.rsdiffbeforeafterboth--- a/bindings/jsonnet/src/val_make.rs
+++ b/bindings/jsonnet/src/val_make.rs
@@ -14,7 +14,7 @@
/// # Safety
///
/// `v` should be a NUL-terminated string
-#[no_mangle]
+#[unsafe(no_mangle)]
pub unsafe extern "C" fn jsonnet_json_make_string(_vm: &VM, val: *const c_char) -> *mut Val {
let val = unsafe { CStr::from_ptr(val) };
let val = val.to_str().expect("string is not utf-8");
@@ -22,7 +22,7 @@
}
/// Convert the given double to a `JsonnetJsonValue`.
-#[no_mangle]
+#[unsafe(no_mangle)]
pub extern "C" fn jsonnet_json_make_number(_vm: &VM, v: c_double) -> *mut Val {
Box::into_raw(Box::new(Val::Num(
NumValue::new(v).expect("jsonnet numbers are finite"),
@@ -30,14 +30,14 @@
}
/// Convert the given `bool` (`1` or `0`) to a `JsonnetJsonValue`.
-#[no_mangle]
+#[unsafe(no_mangle)]
pub extern "C" fn jsonnet_json_make_bool(_vm: &VM, v: c_int) -> *mut Val {
assert!(v == 0 || v == 1, "bad boolean value");
Box::into_raw(Box::new(Val::Bool(v == 1)))
}
/// Make a `JsonnetJsonValue` representing `null`.
-#[no_mangle]
+#[unsafe(no_mangle)]
pub extern "C" fn jsonnet_json_make_null(_vm: &VM) -> *mut Val {
Box::into_raw(Box::new(Val::Null))
}
@@ -45,13 +45,13 @@
/// Make a `JsonnetJsonValue` representing an array.
///
/// Assign elements with [`jsonnet_json_array_append`].
-#[no_mangle]
+#[unsafe(no_mangle)]
pub extern "C" fn jsonnet_json_make_array(_vm: &VM) -> *mut Val {
Box::into_raw(Box::new(Val::arr(())))
}
/// Make a `JsonnetJsonValue` representing an object.
-#[no_mangle]
+#[unsafe(no_mangle)]
pub extern "C" fn jsonnet_json_make_object(_vm: &VM) -> *mut Val {
Box::into_raw(Box::new(Val::Obj(ObjValue::empty())))
}
bindings/jsonnet/src/val_modify.rsdiffbeforeafterboth--- a/bindings/jsonnet/src/val_modify.rs
+++ b/bindings/jsonnet/src/val_modify.rs
@@ -14,7 +14,7 @@
///
/// `arr` should be a pointer to array value allocated by `make_array`, or returned by other library call
/// `val` should be a pointer to value allocated using this library
-#[no_mangle]
+#[unsafe(no_mangle)]
pub unsafe extern "C" fn jsonnet_json_array_append(_vm: &VM, arr: &mut Val, val: &Val) {
match arr {
Val::Arr(old) => {
@@ -38,7 +38,7 @@
///
/// `obj` should be a pointer to object value allocated by `make_object`, or returned by other library call
/// `name` should be NUL-terminated string
-#[no_mangle]
+#[unsafe(no_mangle)]
pub unsafe extern "C" fn jsonnet_json_object_append(
_vm: &VM,
obj: &mut Val,
bindings/jsonnet/src/vars_tlas.rsdiffbeforeafterboth--- a/bindings/jsonnet/src/vars_tlas.rs
+++ b/bindings/jsonnet/src/vars_tlas.rs
@@ -13,7 +13,7 @@
/// # Safety
///
/// `name`, `code` should be a NUL-terminated strings
-#[no_mangle]
+#[unsafe(no_mangle)]
pub unsafe extern "C" fn jsonnet_ext_var(vm: &VM, name: *const c_char, value: *const c_char) {
let name = unsafe { CStr::from_ptr(name) };
let value = unsafe { CStr::from_ptr(value) };
@@ -36,7 +36,7 @@
/// # Safety
///
/// `name`, `code` should be a NUL-terminated strings
-#[no_mangle]
+#[unsafe(no_mangle)]
pub unsafe extern "C" fn jsonnet_ext_code(vm: &VM, name: *const c_char, code: *const c_char) {
let name = unsafe { CStr::from_ptr(name) };
let code = unsafe { CStr::from_ptr(code) };
@@ -60,7 +60,7 @@
/// # Safety
///
/// `name`, `value` should be a NUL-terminated strings
-#[no_mangle]
+#[unsafe(no_mangle)]
pub unsafe extern "C" fn jsonnet_tla_var(vm: &mut VM, name: *const c_char, value: *const c_char) {
let name = unsafe { CStr::from_ptr(name) };
let value = unsafe { CStr::from_ptr(value) };
@@ -77,7 +77,7 @@
/// # Safety
///
/// `name`, `code` should be a NUL-terminated strings
-#[no_mangle]
+#[unsafe(no_mangle)]
pub unsafe extern "C" fn jsonnet_tla_code(vm: &mut VM, name: *const c_char, code: *const c_char) {
let name = unsafe { CStr::from_ptr(name) };
let code = unsafe { CStr::from_ptr(code) };