Skip to content

Commit

Permalink
(src) removed some unnecessary allow(clippy::...) attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxXSoft committed Nov 30, 2024
1 parent edb70e0 commit c30c5b0
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 15 deletions.
27 changes: 21 additions & 6 deletions crates/libkoopa/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ ffi! {
/// Updates the `program` if no errors occurred.
///
/// Returns the error code.
fn koopa_parse_from_file(path: *const c_char, program: &mut *mut Program) -> ErrorCode {
let path = unwrap_or_return!(unsafe { CStr::from_ptr(path) }.to_str(), InvalidUtf8String);
///
/// # Safety
///
/// The memory pointed to by `path` must contain a valid
/// null terminator at the end of the string.
unsafe fn koopa_parse_from_file(path: *const c_char, program: &mut *mut Program) -> ErrorCode {
let path = unwrap_or_return!(CStr::from_ptr(path).to_str(), InvalidUtf8String);
let driver = unwrap_or_return!(Driver::from_path(path), InvalidFile);
let prog = unwrap_or_return!(driver.generate_program(), InvalidKoopaProgram);
*program = new_pointer(prog);
Expand All @@ -24,8 +29,13 @@ ffi! {
/// Updates the `program` if no errors occurred.
///
/// Returns the error code.
fn koopa_parse_from_string(s: *const c_char, program: &mut *mut Program) -> ErrorCode {
let s = unwrap_or_return!(unsafe { CStr::from_ptr(s) }.to_str(), InvalidUtf8String);
///
/// # Safety
///
/// The memory pointed to by `s` must contain a valid
/// null terminator at the end of the string.
unsafe fn koopa_parse_from_string(s: *const c_char, program: &mut *mut Program) -> ErrorCode {
let s = unwrap_or_return!(CStr::from_ptr(s).to_str(), InvalidUtf8String);
let driver = Driver::from(s);
let prog = unwrap_or_return!(driver.generate_program(), InvalidKoopaProgram);
*program = new_pointer(prog);
Expand Down Expand Up @@ -60,7 +70,12 @@ ffi! {
///
/// All programs returned by Koopa IR library functions
/// should be deleted manually.
fn koopa_delete_program(program: *mut Program) {
unsafe { drop_pointer(program) };
///
/// # Safety
///
/// The `program` must be a valid program pointer returned by
/// Koopa IR library functions.
unsafe fn koopa_delete_program(program: *mut Program) {
drop_pointer(program);
}
}
1 change: 0 additions & 1 deletion crates/libkoopa/src/raw/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ impl RawProgramBuilder {
}

/// Builds on the given Koopa IR program.
#[allow(clippy::needless_collect)]
pub fn build_on(&mut self, program: &Program) -> RawProgram {
let mut info = ProgramInfo::new(program);
let raw = RawProgram {
Expand Down
9 changes: 7 additions & 2 deletions crates/libkoopa/src/raw/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ ffi! {
}

/// Frees allocated memory of the given raw program builder.
fn koopa_delete_raw_program_builder(builder: *mut RawProgramBuilder) {
unsafe { drop_pointer(builder) };
///
/// # Safety
///
/// The `builder` must be a valid raw program builder returned by
/// Koopa IR library functions.
unsafe fn koopa_delete_raw_program_builder(builder: *mut RawProgramBuilder) {
drop_pointer(builder);
}

/// Builds a raw program of the given Koopa IR program
Expand Down
25 changes: 19 additions & 6 deletions crates/libkoopa/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,27 @@ pub(crate) unsafe fn new_uninit_box<T>() -> Box<T> {
/// Defines FFI functions.
macro_rules! ffi {
{
$($(#[$attr:meta])*
$(#[$attr:meta])*
fn $name:ident$(<$($lt:lifetime)+>)?
($($arg:ident : $ty:ty),* $(,)?) $(-> $ret:ty)? $body:block)*
} => {
$($(#[$attr])*
#[allow(clippy::not_unsafe_ptr_arg_deref)]
($($arg:ident : $ty:ty),* $(,)?) $(-> $ret:ty)? $body:block
$($rest:tt)*
} => {
$(#[$attr])*
#[no_mangle]
pub extern "C" fn $name$(<$($lt)+>)?($($arg: $ty),*) $(-> $ret)? $body)*
pub extern "C" fn $name$(<$($lt)+>)? ($($arg: $ty),*) $(-> $ret)? $body
$crate::utils::ffi!($($rest)*);
};
{
$(#[$attr:meta])*
unsafe fn $name:ident$(<$($lt:lifetime)+>)?
($($arg:ident : $ty:ty),* $(,)?) $(-> $ret:ty)? $body:block
$($rest:tt)*
} => {
$(#[$attr])*
#[no_mangle]
pub unsafe extern "C" fn $name$(<$($lt)+>)? ($($arg: $ty),*) $(-> $ret)? $body
$crate::utils::ffi!($($rest)*);
};
() => {};
}
pub(crate) use ffi;

0 comments on commit c30c5b0

Please sign in to comment.