prefer ::std::ptr::cast()
This commit is contained in:
parent
4ca2857500
commit
ebcb2e9c66
9 changed files with 28 additions and 55 deletions
|
|
@ -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<String> {
|
||||
// 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()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
);
|
||||
}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -30,19 +30,6 @@ pub struct FlakeLockFlags {
|
|||
inner: NonNull<sys::NixFlakeLockFlags>,
|
||||
}
|
||||
|
||||
// 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();
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ impl FlakeRefBuilder {
|
|||
self.reference.len(),
|
||||
&mut ptr,
|
||||
Some(callback),
|
||||
userdata as *mut c_void,
|
||||
userdata.cast(),
|
||||
)
|
||||
}
|
||||
)?;
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ pub unsafe fn get_global_setting(key: &str) -> NixideResult<String> {
|
|||
ctx.as_ptr(),
|
||||
c_key.as_ptr(),
|
||||
Some(callback),
|
||||
userdata as *mut c_void,
|
||||
userdata.cast(),
|
||||
);
|
||||
}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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<String> {
|
||||
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(),
|
||||
)
|
||||
}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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<String> {
|
||||
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),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ macro_rules! nix_callback {
|
|||
__captured_fn(
|
||||
$($( $pre, )*)?
|
||||
// userdata_,
|
||||
$userdata as *mut __UserData,
|
||||
$userdata.cast(),
|
||||
$($( $post, )*)?
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue