refact: Resolve some clippy warnings
(cherry picked from commit dc4bfaa993eb2d712d53f70551db9ac34b0cda08)
This commit is contained in:
parent
12d3d62108
commit
1e3cce7742
5 changed files with 15 additions and 14 deletions
|
|
@ -1,4 +1,3 @@
|
||||||
use bindgen;
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,8 +52,8 @@ impl EvalStateWeak {
|
||||||
pub fn upgrade(&self) -> Option<EvalState> {
|
pub fn upgrade(&self) -> Option<EvalState> {
|
||||||
self.inner.upgrade().and_then(|eval_state| {
|
self.inner.upgrade().and_then(|eval_state| {
|
||||||
self.store.upgrade().map(|store| EvalState {
|
self.store.upgrade().map(|store| EvalState {
|
||||||
eval_state: eval_state,
|
eval_state,
|
||||||
store: store,
|
store,
|
||||||
context: Context::new(),
|
context: Context::new(),
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -55,10 +55,7 @@ impl PrimOp {
|
||||||
// TODO: Use the GC with finalizer, if possible.
|
// TODO: Use the GC with finalizer, if possible.
|
||||||
let user_data = ManuallyDrop::new(Box::new(PrimOpContext {
|
let user_data = ManuallyDrop::new(Box::new(PrimOpContext {
|
||||||
arity: N,
|
arity: N,
|
||||||
function: Box::new(move |eval_state, args| {
|
function: Box::new(move |eval_state, args| f(eval_state, args.try_into().unwrap())),
|
||||||
let r = f(eval_state, args.try_into().unwrap());
|
|
||||||
r
|
|
||||||
}),
|
|
||||||
eval_state: eval_state.weak_ref(),
|
eval_state: eval_state.weak_ref(),
|
||||||
}));
|
}));
|
||||||
user_data.as_ref() as *const PrimOpContext as *mut c_void
|
user_data.as_ref() as *const PrimOpContext as *mut c_void
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,9 @@ impl Context {
|
||||||
// We're almost certainly going to crash anyways.
|
// We're almost certainly going to crash anyways.
|
||||||
panic!("nix_c_context_create returned a null pointer");
|
panic!("nix_c_context_create returned a null pointer");
|
||||||
}
|
}
|
||||||
let ctx = Context {
|
Context {
|
||||||
inner: NonNull::new(ctx).unwrap(),
|
inner: NonNull::new(ctx).unwrap(),
|
||||||
};
|
}
|
||||||
ctx
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Access the C context pointer.
|
/// Access the C context pointer.
|
||||||
|
|
@ -36,7 +35,7 @@ impl Context {
|
||||||
/// We recommend to use `check_call!` if possible.
|
/// We recommend to use `check_call!` if possible.
|
||||||
pub fn check_err(&self) -> Result<()> {
|
pub fn check_err(&self) -> Result<()> {
|
||||||
let err = unsafe { raw::err_code(self.inner.as_ptr()) };
|
let err = unsafe { raw::err_code(self.inner.as_ptr()) };
|
||||||
if err != raw::err_NIX_OK.try_into().unwrap() {
|
if err != raw::err_NIX_OK {
|
||||||
// msgp is a borrowed pointer (pointing into the context), so we don't need to free it
|
// msgp is a borrowed pointer (pointing into the context), so we don't need to free it
|
||||||
let msgp = unsafe { raw::err_msg(null_mut(), self.inner.as_ptr(), null_mut()) };
|
let msgp = unsafe { raw::err_msg(null_mut(), self.inner.as_ptr(), null_mut()) };
|
||||||
// Turn the i8 pointer into a Rust string by copying
|
// Turn the i8 pointer into a Rust string by copying
|
||||||
|
|
@ -50,7 +49,7 @@ impl Context {
|
||||||
unsafe {
|
unsafe {
|
||||||
raw::set_err_msg(
|
raw::set_err_msg(
|
||||||
self.inner.as_ptr(),
|
self.inner.as_ptr(),
|
||||||
raw::err_NIX_OK.try_into().unwrap(),
|
raw::err_NIX_OK,
|
||||||
b"\0".as_ptr() as *const i8,
|
b"\0".as_ptr() as *const i8,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,12 @@ use anyhow::Result;
|
||||||
/// This function is used by the other nix_* crates, and you should never need to call it yourself.
|
/// This function is used by the other nix_* crates, and you should never need to call it yourself.
|
||||||
///
|
///
|
||||||
/// Some functions in the nix library "return" strings without giving you ownership over them, by letting you pass a callback function that gets to look at that string. This callback simply turns that string pointer into an owned rust String.
|
/// Some functions in the nix library "return" strings without giving you ownership over them, by letting you pass a callback function that gets to look at that string. This callback simply turns that string pointer into an owned rust String.
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// _Manual memory management_
|
||||||
|
///
|
||||||
|
/// Only for passing to the nix C API. Do not call this function directly.
|
||||||
pub unsafe extern "C" fn callback_get_result_string(
|
pub unsafe extern "C" fn callback_get_result_string(
|
||||||
start: *const ::std::os::raw::c_char,
|
start: *const ::std::os::raw::c_char,
|
||||||
n: std::os::raw::c_uint,
|
n: std::os::raw::c_uint,
|
||||||
|
|
@ -12,7 +18,7 @@ pub unsafe extern "C" fn callback_get_result_string(
|
||||||
) {
|
) {
|
||||||
let ret = user_data as *mut Result<String>;
|
let ret = user_data as *mut Result<String>;
|
||||||
|
|
||||||
if start == std::ptr::null() {
|
if start.is_null() {
|
||||||
if n != 0 {
|
if n != 0 {
|
||||||
panic!("callback_get_result_string: start is null but n is not zero");
|
panic!("callback_get_result_string: start is null but n is not zero");
|
||||||
}
|
}
|
||||||
|
|
@ -22,7 +28,7 @@ pub unsafe extern "C" fn callback_get_result_string(
|
||||||
|
|
||||||
let slice = std::slice::from_raw_parts(start as *const u8, n as usize);
|
let slice = std::slice::from_raw_parts(start as *const u8, n as usize);
|
||||||
|
|
||||||
if !(*ret).is_err() {
|
if (*ret).is_ok() {
|
||||||
panic!(
|
panic!(
|
||||||
"callback_get_result_string: Result must be initialized to Err. Did Nix call us twice?"
|
"callback_get_result_string: Result must be initialized to Err. Did Nix call us twice?"
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue