Skip to content

Commit

Permalink
Fix additional 2024 Edition warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoles committed Jan 31, 2025
1 parent e10c5e8 commit 4f060e1
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 23 deletions.
7 changes: 3 additions & 4 deletions crates/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#![deny(rustdoc::broken_intra_doc_links)]

use core::alloc::{GlobalAlloc, Layout};
use core::ffi::c_void;

use flipperzero_sys as sys;

Expand All @@ -14,18 +13,18 @@ pub struct FuriAlloc;
unsafe impl GlobalAlloc for FuriAlloc {
#[inline]
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
sys::aligned_malloc(layout.size(), layout.align()) as *mut u8
unsafe { sys::aligned_malloc(layout.size(), layout.align()).cast() }
}

#[inline]
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
sys::aligned_free(ptr as *mut c_void);
unsafe { sys::aligned_free(ptr.cast()) }
}

#[inline]
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
// https://github.com/flipperdevices/flipperzero-firmware/issues/1747#issuecomment-1253636552
self.alloc(layout)
unsafe { self.alloc(layout) }
}
}

Expand Down
36 changes: 22 additions & 14 deletions crates/flipperzero/examples/view_dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,32 @@ impl Drop for App {
pub unsafe extern "C" fn text_input_callback(context: *mut c_void) {
let app = context as *mut App;
let mut message = FuriString::from("Hello ");
message.push_c_str(CStr::from_ptr((*app).name.as_ptr()));
sys::widget_add_string_element(
(*app).widget.as_ptr(),
128 / 2,
64 / 2,
sys::AlignCenter,
sys::AlignCenter,
sys::FontPrimary,
message.as_c_ptr(),
);
sys::view_dispatcher_switch_to_view((*app).view_dispatcher.as_ptr(), AppView::Widget as u32);
unsafe {
message.push_c_str(CStr::from_ptr((*app).name.as_ptr()));
sys::widget_add_string_element(
(*app).widget.as_ptr(),
128 / 2,
64 / 2,
sys::AlignCenter,
sys::AlignCenter,
sys::FontPrimary,
message.as_c_ptr(),
);
sys::view_dispatcher_switch_to_view(
(*app).view_dispatcher.as_ptr(),
AppView::Widget as u32,
);
}
}

pub unsafe extern "C" fn navigation_event_callback(context: *mut c_void) -> bool {
let view_dispatcher = context as *mut sys::ViewDispatcher;
sys::view_dispatcher_stop(view_dispatcher);
sys::view_dispatcher_remove_view(view_dispatcher, AppView::Widget as u32);
sys::view_dispatcher_remove_view(view_dispatcher, AppView::TextInput as u32);
unsafe {
sys::view_dispatcher_stop(view_dispatcher);
sys::view_dispatcher_remove_view(view_dispatcher, AppView::Widget as u32);
sys::view_dispatcher_remove_view(view_dispatcher, AppView::TextInput as u32);
}

true
}

Expand Down
3 changes: 2 additions & 1 deletion crates/flipperzero/src/furi/string/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ pub unsafe fn next_code_point<'a, I: Iterator<Item = &'a u8>>(bytes: &mut I) ->
let mut state = sys::FuriStringUTF8StateStarting;
let mut unicode = 0u32;
loop {
sys::furi_string_utf8_decode(*bytes.next()? as c_char, &mut state, &mut unicode);
unsafe { sys::furi_string_utf8_decode(*bytes.next()? as c_char, &mut state, &mut unicode) };

match state {
sys::FuriStringUTF8StateStarting => break Some(unicode),
sys::FuriStringUTF8StateError => break Some(0xfffd), // �
Expand Down
6 changes: 3 additions & 3 deletions crates/rt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ mod thread;
/// # Safety
///
/// This should never be called manually.
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn _start(args: *mut u8) -> i32 {
extern "Rust" {
unsafe extern "Rust" {
fn main(args: *mut u8) -> i32;
}

main(args)
unsafe { main(args) }
}

/// Defines the entry point.
Expand Down
2 changes: 1 addition & 1 deletion crates/rt/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const DEFAULT_STACK_SIZE: u16 = 2048; // 2 KiB
#[macro_export]
macro_rules! manifest {
($($field:ident = $value:expr),* $(,)?) => {
#[no_mangle]
#[unsafe(no_mangle)]
#[link_section = ".fapmeta"]
static FAP_MANIFEST: $crate::manifest::ApplicationManifestV1 = $crate::manifest::ApplicationManifestV1 {
$( $field: $crate::_manifest_field!($field = $value), )*
Expand Down

0 comments on commit 4f060e1

Please sign in to comment.