git.delta.rocks / jrsonnet / refs/commits / d86715261b8b

difftreelog

fix(libjsonnet) update to rust 2024

sxswykxuYaroslav Bolyukin2026-05-05parent: #be410fc.patch.diff
in: master

8 files changed

modifiedbindings/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());
modifiedbindings/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()) };
 	}
modifiedbindings/jsonnet/src/lib.rsdiffbeforeafterboth
43/// 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}
131131
132/// 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}
148148
149/// 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}
155155
156/// 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}
161161
162/// 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 now
165#[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) {}
167167
168/// 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 objects
169///169///
170/// No-op for now170/// No-op for now
171#[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) {}
173173
174/// 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 NULL
190///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 inside
192#[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}
222222
223/// 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/// # Safety
238///238///
239/// `filename` should be a NUL-terminated string239/// `filename` should be a NUL-terminated string
240#[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/// # Safety
271///271///
272/// `filename`, `snippet` should be a NUL-terminated strings272/// `filename`, `snippet` should be a NUL-terminated strings
273#[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}
331331
332/// # Safety332/// # Safety
333#[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}
358358
359/// # Safety359/// # Safety
360#[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}
413413
414/// # Safety414/// # Safety
415#[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}
440440
441/// # Safety441/// # Safety
442#[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,
modifiedbindings/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();
modifiedbindings/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,
modifiedbindings/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())))
 }
modifiedbindings/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,
modifiedbindings/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) };