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"
|
// NOTE: an Err here only occurs when "Last error was not a nix error"
|
||||||
wrap::nix_string_callback!(
|
wrap::nix_string_callback!(
|
||||||
|callback, userdata: *mut __UserData, ctx: &ErrorContext| unsafe {
|
|callback, userdata: *mut __UserData, ctx: &ErrorContext| unsafe {
|
||||||
sys::nix_err_name(
|
sys::nix_err_name(ctx.as_ptr(), self.as_ptr(), Some(callback), userdata.cast())
|
||||||
ctx.as_ptr(),
|
|
||||||
self.as_ptr(),
|
|
||||||
Some(callback),
|
|
||||||
userdata as *mut c_void,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.ok()
|
.ok()
|
||||||
|
|
@ -356,14 +351,11 @@ impl ErrorContext {
|
||||||
///
|
///
|
||||||
fn get_nix_err_info_msg(&self) -> Option<String> {
|
fn get_nix_err_info_msg(&self) -> Option<String> {
|
||||||
// NOTE: an Err here only occurs when "Last error was not a nix error"
|
// NOTE: an Err here only occurs when "Last error was not a nix error"
|
||||||
wrap::nix_string_callback!(|callback, userdata, ctx: &ErrorContext| unsafe {
|
wrap::nix_string_callback!(
|
||||||
sys::nix_err_info_msg(
|
|callback, userdata: *mut __UserData, ctx: &ErrorContext| unsafe {
|
||||||
ctx.as_ptr(),
|
sys::nix_err_info_msg(ctx.as_ptr(), self.as_ptr(), Some(callback), userdata.cast())
|
||||||
self.as_ptr(),
|
}
|
||||||
Some(callback),
|
)
|
||||||
userdata as *mut c_void,
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.ok()
|
.ok()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::ffi::c_void;
|
|
||||||
use std::fmt::{Debug, Display, Formatter, Result as FmtResult};
|
use std::fmt::{Debug, Display, Formatter, Result as FmtResult};
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
@ -85,7 +84,7 @@ impl NixValue for NixString {
|
||||||
ctx.as_ptr(),
|
ctx.as_ptr(),
|
||||||
inner.as_ptr(),
|
inner.as_ptr(),
|
||||||
Some(callback),
|
Some(callback),
|
||||||
userdata as *mut c_void,
|
userdata.cast(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -64,8 +64,8 @@ impl FetchersSettings {
|
||||||
sys::nix_fetchers_settings_add_access_token(
|
sys::nix_fetchers_settings_add_access_token(
|
||||||
ctx.as_ptr(),
|
ctx.as_ptr(),
|
||||||
self.as_ptr(),
|
self.as_ptr(),
|
||||||
c_name.as_ptr() as *mut c_char,
|
c_name.as_ptr().cast_mut(),
|
||||||
c_value.as_ptr() as *mut c_char,
|
c_value.as_ptr().cast_mut(),
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
@ -90,7 +90,7 @@ impl FetchersSettings {
|
||||||
sys::nix_fetchers_settings_remove_access_token(
|
sys::nix_fetchers_settings_remove_access_token(
|
||||||
ctx.as_ptr(),
|
ctx.as_ptr(),
|
||||||
self.as_ptr(),
|
self.as_ptr(),
|
||||||
c_name.as_ptr() as *mut c_char,
|
c_name.as_ptr().cast_mut(),
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
@ -178,7 +178,7 @@ impl FetchersSettings {
|
||||||
sys::nix_fetchers_settings_set_global_flake_registry(
|
sys::nix_fetchers_settings_set_global_flake_registry(
|
||||||
ctx.as_ptr(),
|
ctx.as_ptr(),
|
||||||
self.as_ptr(),
|
self.as_ptr(),
|
||||||
c_registry.as_ptr() as *mut c_char,
|
c_registry.as_ptr().cast_mut(),
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
||||||
|
|
@ -30,19 +30,6 @@ pub struct FlakeLockFlags {
|
||||||
inner: NonNull<sys::NixFlakeLockFlags>,
|
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 {
|
impl Drop for FlakeLockFlags {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
@ -296,7 +283,7 @@ impl FlakeLockFlags {
|
||||||
sys::nix_flake_lock_flags_set_reference_lock_file_path(
|
sys::nix_flake_lock_flags_set_reference_lock_file_path(
|
||||||
ctx.as_ptr(),
|
ctx.as_ptr(),
|
||||||
self.as_ptr(),
|
self.as_ptr(),
|
||||||
c_path.as_ptr() as *mut c_char,
|
c_path.as_ptr().cast_mut(),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
@ -320,7 +307,7 @@ impl FlakeLockFlags {
|
||||||
sys::nix_flake_lock_flags_set_output_lock_file_path(
|
sys::nix_flake_lock_flags_set_output_lock_file_path(
|
||||||
ctx.as_ptr(),
|
ctx.as_ptr(),
|
||||||
self.as_ptr(),
|
self.as_ptr(),
|
||||||
c_path.as_ptr() as *mut c_char,
|
c_path.as_ptr().cast_mut(),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ impl FlakeRefBuilder {
|
||||||
self.reference.len(),
|
self.reference.len(),
|
||||||
&mut ptr,
|
&mut ptr,
|
||||||
Some(callback),
|
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(),
|
ctx.as_ptr(),
|
||||||
c_key.as_ptr(),
|
c_key.as_ptr(),
|
||||||
Some(callback),
|
Some(callback),
|
||||||
userdata as *mut c_void,
|
userdata.cast(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ mod path;
|
||||||
pub use path::*;
|
pub use path::*;
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::ffi::{CString, c_char, c_void};
|
use std::ffi::{CString, c_char};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::ptr::{NonNull, null, null_mut};
|
use std::ptr::{NonNull, null, null_mut};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
@ -88,7 +88,7 @@ impl Store {
|
||||||
ctx.as_ptr(),
|
ctx.as_ptr(),
|
||||||
self.as_ptr(),
|
self.as_ptr(),
|
||||||
Some(callback),
|
Some(callback),
|
||||||
userdata as *mut c_void,
|
userdata.cast(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
@ -99,12 +99,7 @@ impl Store {
|
||||||
pub fn uri(&self) -> NixideResult<String> {
|
pub fn uri(&self) -> NixideResult<String> {
|
||||||
wrap::nix_string_callback!(
|
wrap::nix_string_callback!(
|
||||||
|callback, userdata: *mut __UserData, ctx: &ErrorContext| unsafe {
|
|callback, userdata: *mut __UserData, ctx: &ErrorContext| unsafe {
|
||||||
sys::nix_store_get_uri(
|
sys::nix_store_get_uri(ctx.as_ptr(), self.as_ptr(), Some(callback), userdata.cast())
|
||||||
ctx.as_ptr(),
|
|
||||||
self.as_ptr(),
|
|
||||||
Some(callback),
|
|
||||||
userdata as *mut c_void,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -118,7 +113,7 @@ impl Store {
|
||||||
ctx.as_ptr(),
|
ctx.as_ptr(),
|
||||||
self.as_ptr(),
|
self.as_ptr(),
|
||||||
Some(callback),
|
Some(callback),
|
||||||
userdata as *mut c_void,
|
userdata.cast(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::ffi::{CString, c_char, c_void};
|
use std::ffi::{CString, c_char};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use super::Store;
|
use super::Store;
|
||||||
use crate::NixideResult;
|
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::stdext::CCharPtrExt as _;
|
||||||
use crate::sys;
|
use crate::sys;
|
||||||
use crate::util::panic_issue_call_failed;
|
use crate::util::panic_issue_call_failed;
|
||||||
|
|
@ -112,7 +112,7 @@ impl StorePath {
|
||||||
///
|
///
|
||||||
pub fn name(&self) -> NixideResult<String> {
|
pub fn name(&self) -> NixideResult<String> {
|
||||||
wrap::nix_string_callback!(|callback, userdata: *mut __UserData, _| unsafe {
|
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
|
// 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
|
// XXX: NOTE: now `nix_string_callback` is a macro this isn't necessary
|
||||||
// sys::nix_err_NIX_OK
|
// sys::nix_err_NIX_OK
|
||||||
|
|
@ -144,7 +144,7 @@ impl StorePath {
|
||||||
self.store_ref.borrow().as_ptr(),
|
self.store_ref.borrow().as_ptr(),
|
||||||
self.as_ptr(),
|
self.as_ptr(),
|
||||||
Some(callback),
|
Some(callback),
|
||||||
userdata as *mut c_void,
|
userdata.cast(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
@ -195,7 +195,7 @@ impl StorePath {
|
||||||
let store_ref = unsafe { (*userdata).inner.0.clone() };
|
let store_ref = unsafe { (*userdata).inner.0.clone() };
|
||||||
|
|
||||||
let path = &StorePath {
|
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,
|
store_ref,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -216,7 +216,7 @@ impl StorePath {
|
||||||
flip,
|
flip,
|
||||||
include_outputs,
|
include_outputs,
|
||||||
include_derivers,
|
include_derivers,
|
||||||
(*state).inner_ptr() as *mut c_void,
|
(*state).inner_ptr().cast(),
|
||||||
Some(callback));
|
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 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 {
|
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));
|
}).unwrap_or_else(|err| panic_issue_call_failed!("{}", err));
|
||||||
|
|
||||||
let store_ref = unsafe { (*userdata).inner.0.clone() };
|
let store_ref = unsafe { (*userdata).inner.0.clone() };
|
||||||
|
|
@ -302,7 +302,7 @@ impl StorePath {
|
||||||
ctx.as_ptr(),
|
ctx.as_ptr(),
|
||||||
self.store_ref.borrow().as_ptr(),
|
self.store_ref.borrow().as_ptr(),
|
||||||
self.as_ptr(),
|
self.as_ptr(),
|
||||||
(*state).inner_ptr() as *mut c_void,
|
(*state).inner_ptr().cast(),
|
||||||
Some(callback),
|
Some(callback),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ macro_rules! nix_callback {
|
||||||
__captured_fn(
|
__captured_fn(
|
||||||
$($( $pre, )*)?
|
$($( $pre, )*)?
|
||||||
// userdata_,
|
// userdata_,
|
||||||
$userdata as *mut __UserData,
|
$userdata.cast(),
|
||||||
$($( $post, )*)?
|
$($( $post, )*)?
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue