Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signedness mismatch between core::ffi::c_char and libc::c_char #249

Closed
jothan opened this issue Dec 21, 2024 · 3 comments
Closed

Signedness mismatch between core::ffi::c_char and libc::c_char #249

jothan opened this issue Dec 21, 2024 · 3 comments

Comments

@jothan
Copy link

jothan commented Dec 21, 2024

I tried this code:

unsafe { libc::printf(c"%s".as_ptr(), line.as_ptr()) };

I expected to be able to compile the above code, but the compiler had a different opinion:

error[E0308]: mismatched types
  --> src/logging.rs:90:27
   |
90 |     unsafe { libc::printf(c"%s".as_ptr(), line.as_ptr()) };
   |              ------------ ^^^^^^^^^^^^^^ expected `*const u8`, found `*const i8`
   |              |
   |              arguments to this function are incorrect
   |
   = note: expected raw pointer `*const u8`
              found raw pointer `*const i8`
note: function defined here
  --> index.crates.io-6f17d22bba15001f/libc-0.2.169/src/unix/mod.rs:694:12

It would seem that the latest libc 0.2.169 flipped its signedness of c_char from signed to unsigned for ESP-IDF:
rust-lang/libc@c66faeb

rustc should probably match this signedness change on ESP-IDF and update the definition somewhere around here: https://doc.rust-lang.org/beta/src/core/ffi/mod.rs.html#52

Doing a bit of searching around, I am about 80% sure that char is unsigned on the C side on ESP-IDF.

Meta

rustc --version --verbose:

rustc 1.83.0-nightly (103cde010 2024-11-26) (1.83.0.0)
binary: rustc
commit-hash: 103cde01096863220765fd2e54519d011a5740ac
commit-date: 2024-11-26
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 18.1.2
@MabezDev
Copy link
Member

Sorry, this got lost in my notifications over the holidays. We fixed this in rust-lang/libc#4195 and I believe libc has had a release since then, so this should be fixed. Please re open if that's not the case.

@github-project-automation github-project-automation bot moved this from Todo to Done in esp-rs Jan 24, 2025
@jothan
Copy link
Author

jothan commented Jan 24, 2025

Sorry, this got lost in my notifications over the holidays. We fixed this in rust-lang/libc#4195 and I believe libc has had a release since then, so this should be fixed. Please re open if that's not the case.

Ok, looks like the rustc side will match once 1.85 is out. I'm going to test it then.

rustc PR: https://github.com/rust-lang/rust/pull/132975/files

@jothan
Copy link
Author

jothan commented Jan 24, 2025

Big thanks 🙏🏼👍🏼❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

2 participants