prefer &mut __Userdata over *mut UserData
This commit is contained in:
parent
bc5a9cc3aa
commit
648aadf5ab
2 changed files with 7 additions and 25 deletions
|
|
@ -271,7 +271,7 @@ impl ErrorContext {
|
||||||
pub(super) fn get_nix_err_name(&self) -> Option<String> {
|
pub(super) fn get_nix_err_name(&self) -> Option<String> {
|
||||||
unsafe {
|
unsafe {
|
||||||
// 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: *mut __UserData, ctx: &ErrorContext| {
|
wrap::nix_string_callback!(|callback, userdata: &mut __UserData, ctx: &ErrorContext| {
|
||||||
sys::nix_err_name(ctx.as_ptr(), self.as_ptr(), Some(callback), userdata)
|
sys::nix_err_name(ctx.as_ptr(), self.as_ptr(), Some(callback), userdata)
|
||||||
})
|
})
|
||||||
.ok()
|
.ok()
|
||||||
|
|
@ -316,7 +316,7 @@ impl ErrorContext {
|
||||||
pub(super) fn get_nix_err_info_msg(&self) -> Option<String> {
|
pub(super) fn get_nix_err_info_msg(&self) -> Option<String> {
|
||||||
unsafe {
|
unsafe {
|
||||||
// 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, user_data, ctx| {
|
wrap::nix_string_callback!(|callback, user_data, ctx: &ErrorContext| {
|
||||||
sys::nix_err_info_msg(ctx.as_ptr(), self.as_ptr(), Some(callback), user_data)
|
sys::nix_err_info_msg(ctx.as_ptr(), self.as_ptr(), Some(callback), user_data)
|
||||||
})
|
})
|
||||||
.ok()
|
.ok()
|
||||||
|
|
|
||||||
|
|
@ -103,18 +103,17 @@ macro_rules! nix_callback {
|
||||||
|
|
||||||
unsafe extern "C" fn __wrapper_callback(
|
unsafe extern "C" fn __wrapper_callback(
|
||||||
$($( $pre: $pre_ty, )*)?
|
$($( $pre: $pre_ty, )*)?
|
||||||
$userdata: *mut ::std::ffi::c_void,
|
$userdata: &mut __UserData,
|
||||||
$($( $post: $post_ty, )*)?
|
$($( $post: $post_ty, )*)?
|
||||||
) {
|
) {
|
||||||
let ud = unsafe { &mut *($userdata as *mut __UserData) };
|
let stored_retval = &raw mut $userdata.retval;
|
||||||
let stored_retval = &raw mut ud.retval;
|
|
||||||
|
|
||||||
let retval = unsafe {
|
let retval = unsafe {
|
||||||
__captured_fn(
|
__captured_fn(
|
||||||
$($( $pre, )*)?
|
$($( $pre, )*)?
|
||||||
ud,
|
$userdata,
|
||||||
$($( $post, )*)?
|
$($( $post, )*)?
|
||||||
);
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
@ -122,29 +121,12 @@ macro_rules! nix_callback {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn __captured_function(
|
|
||||||
// callback: unsafe extern "C" fn(
|
|
||||||
// $userdata: *mut ::std::ffi::c_void,
|
|
||||||
// $(
|
|
||||||
// $arg_name: $arg_type,
|
|
||||||
// )*
|
|
||||||
// ),
|
|
||||||
// state: *mut __UserData,
|
|
||||||
// ctx: &$crate::errors::ErrorContext,
|
|
||||||
// ) {
|
|
||||||
// $function(callback, state, ctx);
|
|
||||||
// }
|
|
||||||
|
|
||||||
let mut __ctx: $crate::errors::ErrorContext = $crate::errors::ErrorContext::new();
|
let mut __ctx: $crate::errors::ErrorContext = $crate::errors::ErrorContext::new();
|
||||||
let mut __state: ::std::mem::MaybeUninit<__UserData> = ::std::mem::MaybeUninit::uninit();
|
let mut __state: ::std::mem::MaybeUninit<__UserData> = ::std::mem::MaybeUninit::uninit();
|
||||||
|
|
||||||
$function(__wrapper_callback, __state.as_mut_ptr(), &__ctx);
|
$function(__wrapper_callback, &mut __state, &__ctx);
|
||||||
|
|
||||||
__ctx.pop().and_then(|_| unsafe { __state.assume_init().retval })
|
__ctx.pop().and_then(|_| unsafe { __state.assume_init().retval })
|
||||||
|
|
||||||
// add type annotations for compiler
|
|
||||||
// let __result: $ret = __ctx.pop().and_then(|_| unsafe { __state.assume_init().retval });
|
|
||||||
// __result
|
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
pub(crate) use nix_callback;
|
pub(crate) use nix_callback;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue