From ebcb2e9c66de9b79d98dd02faa4041c03ea13e69 Mon Sep 17 00:00:00 2001 From: _cry64 Date: Tue, 14 Apr 2026 14:08:40 +1000 Subject: [PATCH] prefer ::std::ptr::cast() --- nixide/src/errors/context.rs | 20 ++++++-------------- nixide/src/expr/values/string.rs | 3 +-- nixide/src/flake/fetchers_settings.rs | 8 ++++---- nixide/src/flake/flake_lock_flags.rs | 17 ++--------------- nixide/src/flake/flakeref_builder.rs | 2 +- nixide/src/nix_settings.rs | 2 +- nixide/src/store/mod.rs | 13 ++++--------- nixide/src/store/path.rs | 16 ++++++++-------- nixide/src/util/wrap.rs | 2 +- 9 files changed, 28 insertions(+), 55 deletions(-) diff --git a/nixide/src/errors/context.rs b/nixide/src/errors/context.rs index 13a3c6d..44b2666 100644 --- a/nixide/src/errors/context.rs +++ b/nixide/src/errors/context.rs @@ -306,12 +306,7 @@ impl ErrorContext { // NOTE: an Err here only occurs when "Last error was not a nix error" wrap::nix_string_callback!( |callback, userdata: *mut __UserData, ctx: &ErrorContext| unsafe { - sys::nix_err_name( - ctx.as_ptr(), - self.as_ptr(), - Some(callback), - userdata as *mut c_void, - ) + sys::nix_err_name(ctx.as_ptr(), self.as_ptr(), Some(callback), userdata.cast()) } ) .ok() @@ -356,14 +351,11 @@ impl ErrorContext { /// fn get_nix_err_info_msg(&self) -> Option { // NOTE: an Err here only occurs when "Last error was not a nix error" - wrap::nix_string_callback!(|callback, userdata, ctx: &ErrorContext| unsafe { - sys::nix_err_info_msg( - ctx.as_ptr(), - self.as_ptr(), - Some(callback), - userdata as *mut c_void, - ) - }) + wrap::nix_string_callback!( + |callback, userdata: *mut __UserData, ctx: &ErrorContext| unsafe { + sys::nix_err_info_msg(ctx.as_ptr(), self.as_ptr(), Some(callback), userdata.cast()) + } + ) .ok() } } diff --git a/nixide/src/expr/values/string.rs b/nixide/src/expr/values/string.rs index c514d45..af387df 100644 --- a/nixide/src/expr/values/string.rs +++ b/nixide/src/expr/values/string.rs @@ -1,5 +1,4 @@ use std::cell::RefCell; -use std::ffi::c_void; use std::fmt::{Debug, Display, Formatter, Result as FmtResult}; use std::ptr::NonNull; use std::rc::Rc; @@ -85,7 +84,7 @@ impl NixValue for NixString { ctx.as_ptr(), inner.as_ptr(), Some(callback), - userdata as *mut c_void, + userdata.cast(), ); } ) diff --git a/nixide/src/flake/fetchers_settings.rs b/nixide/src/flake/fetchers_settings.rs index bfe56dd..d56171f 100644 --- a/nixide/src/flake/fetchers_settings.rs +++ b/nixide/src/flake/fetchers_settings.rs @@ -64,8 +64,8 @@ impl FetchersSettings { sys::nix_fetchers_settings_add_access_token( ctx.as_ptr(), self.as_ptr(), - c_name.as_ptr() as *mut c_char, - c_value.as_ptr() as *mut c_char, + c_name.as_ptr().cast_mut(), + c_value.as_ptr().cast_mut(), ); }) .unwrap(); @@ -90,7 +90,7 @@ impl FetchersSettings { sys::nix_fetchers_settings_remove_access_token( ctx.as_ptr(), self.as_ptr(), - c_name.as_ptr() as *mut c_char, + c_name.as_ptr().cast_mut(), ); }) .unwrap(); @@ -178,7 +178,7 @@ impl FetchersSettings { sys::nix_fetchers_settings_set_global_flake_registry( ctx.as_ptr(), self.as_ptr(), - c_registry.as_ptr() as *mut c_char, + c_registry.as_ptr().cast_mut(), ); }) .unwrap(); diff --git a/nixide/src/flake/flake_lock_flags.rs b/nixide/src/flake/flake_lock_flags.rs index a1224e6..fb40ae0 100644 --- a/nixide/src/flake/flake_lock_flags.rs +++ b/nixide/src/flake/flake_lock_flags.rs @@ -30,19 +30,6 @@ pub struct FlakeLockFlags { inner: NonNull, } -// impl Clone for FlakeLockFlags { -// fn clone(&self) -> Self { -// wrap::nix_fn!(|ctx: &ErrorContext| unsafe { -// sys::nix_gc_incref(ctx.as_ptr(), self.as_ptr() as *mut c_void); -// }) -// .unwrap(); -// -// Self { -// inner: self.inner.clone(), -// } -// } -// } - impl Drop for FlakeLockFlags { fn drop(&mut self) { unsafe { @@ -296,7 +283,7 @@ impl FlakeLockFlags { sys::nix_flake_lock_flags_set_reference_lock_file_path( ctx.as_ptr(), self.as_ptr(), - c_path.as_ptr() as *mut c_char, + c_path.as_ptr().cast_mut(), ) }) .unwrap(); @@ -320,7 +307,7 @@ impl FlakeLockFlags { sys::nix_flake_lock_flags_set_output_lock_file_path( ctx.as_ptr(), self.as_ptr(), - c_path.as_ptr() as *mut c_char, + c_path.as_ptr().cast_mut(), ) }) .unwrap(); diff --git a/nixide/src/flake/flakeref_builder.rs b/nixide/src/flake/flakeref_builder.rs index 13eecf2..bbb2278 100644 --- a/nixide/src/flake/flakeref_builder.rs +++ b/nixide/src/flake/flakeref_builder.rs @@ -48,7 +48,7 @@ impl FlakeRefBuilder { self.reference.len(), &mut ptr, Some(callback), - userdata as *mut c_void, + userdata.cast(), ) } )?; diff --git a/nixide/src/nix_settings.rs b/nixide/src/nix_settings.rs index 166eb63..8b342fd 100644 --- a/nixide/src/nix_settings.rs +++ b/nixide/src/nix_settings.rs @@ -19,7 +19,7 @@ pub unsafe fn get_global_setting(key: &str) -> NixideResult { ctx.as_ptr(), c_key.as_ptr(), Some(callback), - userdata as *mut c_void, + userdata.cast(), ); } ) diff --git a/nixide/src/store/mod.rs b/nixide/src/store/mod.rs index b193109..ccd5be1 100644 --- a/nixide/src/store/mod.rs +++ b/nixide/src/store/mod.rs @@ -8,7 +8,7 @@ mod path; pub use path::*; use std::cell::RefCell; -use std::ffi::{CString, c_char, c_void}; +use std::ffi::{CString, c_char}; use std::path::PathBuf; use std::ptr::{NonNull, null, null_mut}; use std::rc::Rc; @@ -88,7 +88,7 @@ impl Store { ctx.as_ptr(), self.as_ptr(), Some(callback), - userdata as *mut c_void, + userdata.cast(), ) } ) @@ -99,12 +99,7 @@ impl Store { pub fn uri(&self) -> NixideResult { wrap::nix_string_callback!( |callback, userdata: *mut __UserData, ctx: &ErrorContext| unsafe { - sys::nix_store_get_uri( - ctx.as_ptr(), - self.as_ptr(), - Some(callback), - userdata as *mut c_void, - ) + sys::nix_store_get_uri(ctx.as_ptr(), self.as_ptr(), Some(callback), userdata.cast()) } ) } @@ -118,7 +113,7 @@ impl Store { ctx.as_ptr(), self.as_ptr(), Some(callback), - userdata as *mut c_void, + userdata.cast(), ) } ) diff --git a/nixide/src/store/path.rs b/nixide/src/store/path.rs index c0dea21..ad5187b 100644 --- a/nixide/src/store/path.rs +++ b/nixide/src/store/path.rs @@ -1,12 +1,12 @@ use std::cell::RefCell; -use std::ffi::{CString, c_char, c_void}; +use std::ffi::{CString, c_char}; use std::path::PathBuf; use std::ptr::NonNull; use std::rc::Rc; use super::Store; use crate::NixideResult; -use crate::errors::{ErrorContext, ToNixideResult as _, new_nixide_error}; +use crate::errors::{ErrorContext, ToNixideResult as _}; use crate::stdext::CCharPtrExt as _; use crate::sys; use crate::util::panic_issue_call_failed; @@ -112,7 +112,7 @@ impl StorePath { /// pub fn name(&self) -> NixideResult { wrap::nix_string_callback!(|callback, userdata: *mut __UserData, _| unsafe { - sys::nix_store_path_name(self.as_ptr(), Some(callback), userdata as *mut c_void); + sys::nix_store_path_name(self.as_ptr(), Some(callback), userdata.cast()); // NOTE: nix_store_path_name doesn't return nix_err, so we force it to return successfully // XXX: NOTE: now `nix_string_callback` is a macro this isn't necessary // sys::nix_err_NIX_OK @@ -144,7 +144,7 @@ impl StorePath { self.store_ref.borrow().as_ptr(), self.as_ptr(), Some(callback), - userdata as *mut c_void, + userdata.cast(), ) } ) @@ -195,7 +195,7 @@ impl StorePath { let store_ref = unsafe { (*userdata).inner.0.clone() }; let path = &StorePath { - inner: NonNull::new(unsafe { store_ref.borrow().as_ptr() } as *mut sys::StorePath).unwrap(), + inner: NonNull::new(unsafe { store_ref.borrow().as_ptr().cast() }).unwrap(), store_ref, }; @@ -216,7 +216,7 @@ impl StorePath { flip, include_outputs, include_derivers, - (*state).inner_ptr() as *mut c_void, + (*state).inner_ptr().cast(), Some(callback)); } ) @@ -276,7 +276,7 @@ impl StorePath { let output_name = output_name_ptr.to_utf8_string().unwrap_or_else(|err| panic_issue_call_failed!("{}", err)); let inner = wrap::nix_ptr_fn!(|ctx| unsafe { - sys::nix_store_path_clone(output_path_ptr as *mut sys::StorePath) + sys::nix_store_path_clone(output_path_ptr.cast()) }).unwrap_or_else(|err| panic_issue_call_failed!("{}", err)); let store_ref = unsafe { (*userdata).inner.0.clone() }; @@ -302,7 +302,7 @@ impl StorePath { ctx.as_ptr(), self.store_ref.borrow().as_ptr(), self.as_ptr(), - (*state).inner_ptr() as *mut c_void, + (*state).inner_ptr().cast(), Some(callback), ); } diff --git a/nixide/src/util/wrap.rs b/nixide/src/util/wrap.rs index 5b9898e..874e8a8 100644 --- a/nixide/src/util/wrap.rs +++ b/nixide/src/util/wrap.rs @@ -92,7 +92,7 @@ macro_rules! nix_callback { __captured_fn( $($( $pre, )*)? // userdata_, - $userdata as *mut __UserData, + $userdata.cast(), $($( $post, )*)? ); }