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.rsdiffbeforeafterboth--- a/bindings/jsonnet/src/interop.rs
+++ b/bindings/jsonnet/src/interop.rs
@@ -8,8 +8,7 @@
use crate::VM;
- extern "C" {
-
+ unsafe extern "C" {
pub fn _jrsonnet_static_import_callback(
ctx: *mut c_void,
base: *const c_char,
@@ -27,7 +26,7 @@
) -> *mut Val;
}
- #[no_mangle]
+ #[unsafe(no_mangle)]
#[cfg(feature = "interop-wasm")]
// ctx arg is passed as-is to callback
#[allow(clippy::not_unsafe_ptr_arg_deref)]
@@ -38,7 +37,7 @@
/// # Safety
///
/// `name` and `raw_params` should be correctly initialized
- #[no_mangle]
+ #[unsafe(no_mangle)]
#[cfg(feature = "interop-wasm")]
pub unsafe extern "C" fn jrsonnet_apply_static_native_callback(
vm: &VM,
@@ -64,7 +63,7 @@
use crate::VM;
- #[no_mangle]
+ #[unsafe(no_mangle)]
pub extern "C" fn jrsonnet_set_trace_format(vm: &mut VM, format: u8) {
match format {
0 => {
@@ -105,7 +104,7 @@
///
/// Current thread GC will be broken after this call, need to call
/// `jrsonet_enter_thread` before doing anything.
- #[no_mangle]
+ #[unsafe(no_mangle)]
pub unsafe extern "C" fn jrsonnet_exit_thread() -> *mut ThreadCTX {
Box::into_raw(Box::new(ThreadCTX {
interner: jrsonnet_interner::interop::exit_thread(),
@@ -113,7 +112,7 @@
}))
}
- #[no_mangle]
+ #[unsafe(no_mangle)]
pub extern "C" fn jrsonnet_reenter_thread(mut ctx: Box<ThreadCTX>) {
use std::ptr::null_mut;
assert!(
@@ -132,12 +131,12 @@
// boxing.
pub enum JrThreadId {}
- #[no_mangle]
+ #[unsafe(no_mangle)]
pub extern "C" fn jrsonnet_thread_id() -> *mut JrThreadId {
Box::into_raw(Box::new(std::thread::current().id())).cast()
}
- #[no_mangle]
+ #[unsafe(no_mangle)]
pub extern "C" fn jrsonnet_thread_id_compare(
a: *const JrThreadId,
b: *const JrThreadId,
@@ -147,7 +146,7 @@
i32::from(*a == *b)
}
- #[no_mangle]
+ #[unsafe(no_mangle)]
pub unsafe extern "C" fn jrsonnet_thread_id_free(id: *mut JrThreadId) {
let _id: Box<ThreadId> = unsafe { Box::from_raw(id.cast()) };
}
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.rsdiffbeforeafterboth1use std::{2 ffi::{CStr, c_void},3 os::raw::{c_char, c_int},4};56use jrsonnet_evaluator::{7 IStr, Val,8 error::{Error, ErrorKind},9 function::builtin::{NativeCallback, NativeCallbackHandler},10 typed::FromUntyped as _,11};1213use crate::VM;1415/// The returned `JsonnetJsonValue*` should be allocated with `jsonnet_realloc`. It will be cleaned up16/// along with the objects rooted at `argv` by `libjsonnet` when no-longer needed. Return a string upon17/// failure, which will appear in Jsonnet as an error. The `argv` pointer is an array whose size18/// matches the array of parameters supplied when the native callback was originally registered.19///20/// - `ctx` User pointer, given in `jsonnet_native_callback`.21/// - `argv` Array of arguments from Jsonnet code.22/// - `param` success Set this byref param to 1 to indicate success and 0 for failure.23///24/// Returns the content of the imported file, or an error message.25type JsonnetNativeCallback = unsafe extern "C" fn(26 ctx: *const c_void,27 argv: *const *const Val,28 success: *mut c_int,29) -> *mut Val;3031#[derive(jrsonnet_gcmodule::Trace)]32struct JsonnetNativeCallbackHandler {33 #[trace(skip)]34 ctx: *const c_void,35 #[trace(skip)]36 cb: JsonnetNativeCallback,37}38impl NativeCallbackHandler for JsonnetNativeCallbackHandler {39 fn call(&self, args: &[Val]) -> Result<Val, Error> {40 let mut n_args = Vec::new();41 for a in args {42 n_args.push(Some(Box::new(a.clone())));43 }44 n_args.push(None);45 let mut success = 1;46 let v = unsafe { (self.cb)(self.ctx, n_args.as_ptr().cast(), &raw mut success) };47 let v = unsafe { *Box::from_raw(v) };48 if success == 1 {49 Ok(v)50 } else {51 let e = IStr::from_untyped(v).expect("error msg should be a string");52 Err(ErrorKind::RuntimeError(e).into())53 }54 }55}5657/// Callback to provide native extensions to Jsonnet.58///59/// # Safety60///61/// `vm` should be a vm allocated by `jsonnet_make`62/// `name` should be a NUL-terminated string63/// `cb` should be a function pointer64/// `raw_params` should point to a NULL-terminated array of NUL-terminated strings65#[no_mangle]66pub unsafe extern "C" fn jsonnet_native_callback(67 vm: &VM,68 name: *const c_char,69 cb: JsonnetNativeCallback,70 ctx: *const c_void,71 mut raw_params: *const *const c_char,72) {73 let name = unsafe { CStr::from_ptr(name).to_str().expect("name is not utf-8") };74 let mut params = Vec::new();75 loop {76 if (unsafe { *raw_params }).is_null() {77 break;78 }79 let param = unsafe {80 CStr::from_ptr(*raw_params)81 .to_str()82 .expect("param name is not utf-8")83 };84 params.push(param.into());85 raw_params = unsafe { raw_params.offset(1) };86 }8788 let any_resolver = vm.state.context_initializer();89 any_resolver90 .as_any()91 .downcast_ref::<jrsonnet_stdlib::ContextInitializer>()92 .expect("only stdlib context initializer supported")93 .add_native(94 name,95 #[allow(deprecated)]96 NativeCallback::new(params, JsonnetNativeCallbackHandler { ctx, cb }),97 );98}1use std::{2 ffi::{CStr, c_void},3 os::raw::{c_char, c_int},4};56use jrsonnet_evaluator::{7 IStr, Val,8 error::{Error, ErrorKind},9 function::builtin::{NativeCallback, NativeCallbackHandler},10 typed::FromUntyped as _,11};1213use crate::VM;1415/// The returned `JsonnetJsonValue*` should be allocated with `jsonnet_realloc`. It will be cleaned up16/// along with the objects rooted at `argv` by `libjsonnet` when no-longer needed. Return a string upon17/// failure, which will appear in Jsonnet as an error. The `argv` pointer is an array whose size18/// matches the array of parameters supplied when the native callback was originally registered.19///20/// - `ctx` User pointer, given in `jsonnet_native_callback`.21/// - `argv` Array of arguments from Jsonnet code.22/// - `param` success Set this byref param to 1 to indicate success and 0 for failure.23///24/// Returns the content of the imported file, or an error message.25type JsonnetNativeCallback = unsafe extern "C" fn(26 ctx: *const c_void,27 argv: *const *const Val,28 success: *mut c_int,29) -> *mut Val;3031#[derive(jrsonnet_gcmodule::Trace)]32struct JsonnetNativeCallbackHandler {33 #[trace(skip)]34 ctx: *const c_void,35 #[trace(skip)]36 cb: JsonnetNativeCallback,37}38impl NativeCallbackHandler for JsonnetNativeCallbackHandler {39 fn call(&self, args: &[Val]) -> Result<Val, Error> {40 let mut n_args = Vec::new();41 for a in args {42 n_args.push(Some(Box::new(a.clone())));43 }44 n_args.push(None);45 let mut success = 1;46 let v = unsafe { (self.cb)(self.ctx, n_args.as_ptr().cast(), &raw mut success) };47 let v = unsafe { *Box::from_raw(v) };48 if success == 1 {49 Ok(v)50 } else {51 let e = IStr::from_untyped(v).expect("error msg should be a string");52 Err(ErrorKind::RuntimeError(e).into())53 }54 }55}5657/// Callback to provide native extensions to Jsonnet.58///59/// # Safety60///61/// `vm` should be a vm allocated by `jsonnet_make`62/// `name` should be a NUL-terminated string63/// `cb` should be a function pointer64/// `raw_params` should point to a NULL-terminated array of NUL-terminated strings65#[unsafe(no_mangle)]66pub unsafe extern "C" fn jsonnet_native_callback(67 vm: &VM,68 name: *const c_char,69 cb: JsonnetNativeCallback,70 ctx: *const c_void,71 mut raw_params: *const *const c_char,72) {73 let name = unsafe { CStr::from_ptr(name).to_str().expect("name is not utf-8") };74 let mut params = Vec::new();75 loop {76 if (unsafe { *raw_params }).is_null() {77 break;78 }79 let param = unsafe {80 CStr::from_ptr(*raw_params)81 .to_str()82 .expect("param name is not utf-8")83 };84 params.push(param.into());85 raw_params = unsafe { raw_params.add(1) };86 }8788 let any_resolver = vm.state.context_initializer();89 any_resolver90 .as_any()91 .downcast_ref::<jrsonnet_stdlib::ContextInitializer>()92 .expect("only stdlib context initializer supported")93 .add_native(94 name,95 #[allow(deprecated)]96 NativeCallback::new(params, JsonnetNativeCallbackHandler { ctx, cb }),97 );98}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) };