Skip to content

Commit

Permalink
refactor: fix clippy errors missed due to buggy ci stage
Browse files Browse the repository at this point in the history
  • Loading branch information
wmmc88 committed Jan 5, 2024
1 parent 083e9bd commit 712e63f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
32 changes: 16 additions & 16 deletions crates/wdk-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,33 +84,33 @@ pub fn call_unsafe_wdf_function_binding(input_tokens: TokenStream) -> TokenStrea
}

struct CallUnsafeWDFFunctionInput {
function_pointer_type: Ident,
function_table_index: Ident,
function_arguments: syn::punctuated::Punctuated<Expr, Token![,]>,
pointer_type: Ident,
table_index: Ident,
arguments: syn::punctuated::Punctuated<Expr, Token![,]>,
}

impl Parse for CallUnsafeWDFFunctionInput {
fn parse(input: ParseStream) -> Result<Self, Error> {
let c_function_name: String = input.parse::<Ident>()?.to_string();
input.parse::<Token![,]>()?;
let function_arguments = input.parse_terminated(Expr::parse, Token![,])?;
let arguments = input.parse_terminated(Expr::parse, Token![,])?;

Ok(Self {
function_pointer_type: format_ident!(
pointer_type: format_ident!(
"PFN_{uppercase_c_function_name}",
uppercase_c_function_name = c_function_name.to_uppercase()
),
function_table_index: format_ident!("{c_function_name}TableIndex"),
function_arguments,
table_index: format_ident!("{c_function_name}TableIndex"),
arguments,
})
}
}

fn call_unsafe_wdf_function_binding_impl(input_tokens: TokenStream2) -> TokenStream2 {
let CallUnsafeWDFFunctionInput {
function_pointer_type,
function_table_index,
function_arguments,
pointer_type,
table_index,
arguments,
} = match parse2::<CallUnsafeWDFFunctionInput>(input_tokens) {
Ok(syntax_tree) => syntax_tree,
Err(err) => return err.to_compile_error(),
Expand All @@ -129,7 +129,7 @@ fn call_unsafe_wdf_function_binding_impl(input_tokens: TokenStream2) -> TokenStr
force_unsafe();

// Get handle to WDF function from the function table
let wdf_function: wdk_sys::#function_pointer_type = Some(
let wdf_function: wdk_sys::#pointer_type = Some(
// SAFETY: This `transmute` from a no-argument function pointer to a function pointer with the correct
// arguments for the WDF function is safe befause WDF maintains the strict mapping between the
// function table index and the correct function pointer type.
Expand All @@ -138,7 +138,7 @@ fn call_unsafe_wdf_function_binding_impl(input_tokens: TokenStream2) -> TokenStr
unsafe {
core::mem::transmute(
// FIXME: investigate why _WDFFUNCENUM does not have a generated type alias without the underscore prefix
wdk_sys::WDF_FUNCTION_TABLE[wdk_sys::_WDFFUNCENUM::#function_table_index as usize],
wdk_sys::WDF_FUNCTION_TABLE[wdk_sys::_WDFFUNCENUM::#table_index as usize],
)
}
);
Expand All @@ -147,15 +147,15 @@ fn call_unsafe_wdf_function_binding_impl(input_tokens: TokenStream2) -> TokenStr
// the various wdf headers(ex. wdfdriver.h)
if let Some(wdf_function) = wdf_function {
// SAFETY: The WDF function pointer is always valid because its an entry in
// `wdk_sys::WDF_FUNCTION_TABLE` indexed by `function_table_index` and guarded by the type-safety of
// `function_pointer_type`. The passed arguments are also guaranteed to be of a compatible type due to
// `function_pointer_type`.
// `wdk_sys::WDF_FUNCTION_TABLE` indexed by `table_index` and guarded by the type-safety of
// `pointer_type`. The passed arguments are also guaranteed to be of a compatible type due to
// `pointer_type`.
#[allow(unused_unsafe)]
#[allow(clippy::multiple_unsafe_ops_per_block)]
unsafe {
(wdf_function)(
wdk_sys::WdfDriverGlobals,
#function_arguments
#arguments
)
}
} else {
Expand Down
16 changes: 14 additions & 2 deletions crates/wdk-sys/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,20 @@
#[allow(clippy::cast_possible_truncation)]
#[allow(clippy::cognitive_complexity)]
#[allow(clippy::default_trait_access)]
#[rustversion::attr(before(2023-09-10), allow(clippy::incorrect_clone_impl_on_copy_type))]
#[rustversion::attr(since(2023-09-10), allow(clippy::non_canonical_clone_impl))]
#[rustversion::attr(
any(
all(not(nightly), before(1.74)),
all(nightly, before(2023-09-13)),
),
allow(clippy::incorrect_clone_impl_on_copy_type)
)]
#[rustversion::attr(
any(
all(not(nightly), since(1.74)),
all(nightly, since(2023-09-13)),
),
allow(clippy::non_canonical_clone_impl)
)]
#[allow(clippy::missing_safety_doc)]
#[allow(clippy::missing_const_for_fn)]
#[allow(clippy::module_name_repetitions)]
Expand Down

0 comments on commit 712e63f

Please sign in to comment.