Skip to content

Commit

Permalink
Fix platform-specific char constants
Browse files Browse the repository at this point in the history
The return type for `CStr::as_ptr` is `*const c_char` which may be
either a `*const i8` or `*const u8` depending on the platform.

This can cause compilation to fail in certain situations.
  • Loading branch information
dcoles committed Jan 26, 2025
1 parent 8949cf0 commit 0e833a5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion crates/flipperzero/src/furi/log/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ macro_rules! log {
use $crate::__macro_support::ufmt;

if $lvl <= $crate::furi::log::LevelFilter::current() {
const TARGET: *const ::core::primitive::i8 =
const TARGET: *const ::core::ffi::c_char =
match ::core::ffi::CStr::from_bytes_with_nul(
::core::concat!($target, "\0").as_bytes(),
) {
Expand Down
10 changes: 5 additions & 5 deletions crates/flipperzero/src/furi/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ impl FuriString {
pub fn push(&mut self, ch: char) {
match ch.len_utf8() {
1 => unsafe { sys::furi_string_push_back(self.0.as_ptr(), ch as c_char) },
_ => unsafe { sys::furi_string_utf8_push(self.0.as_ptr(), ch as u32) },
_ => unsafe {
sys::furi_string_utf8_push(self.0.as_ptr(), ch as sys::FuriStringUnicodeValue)
},
}
}

Expand Down Expand Up @@ -869,9 +871,7 @@ impl ufmt::uWrite for FuriString {

#[flipperzero_test::tests]
mod tests {
use flipperzero_sys as sys;

use super::FuriString;
use super::*;

#[test]
fn invalid_utf8_is_replaced() {
Expand All @@ -881,7 +881,7 @@ mod tests {
// Construct an invalid string using the Flipper Zero SDK.
let s = FuriString::new();
for b in d {
unsafe { sys::furi_string_push_back(s.0.as_ptr(), b as i8) };
unsafe { sys::furi_string_push_back(s.0.as_ptr(), b as c_char) };
}

for (l, r) in s.chars_lossy().zip("f�r".chars()) {
Expand Down

0 comments on commit 0e833a5

Please sign in to comment.