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

support Errno formatting in no_std #44

Merged
merged 8 commits into from
May 13, 2022
Merged

support Errno formatting in no_std #44

merged 8 commits into from
May 13, 2022

Conversation

A1-Triard
Copy link
Contributor

No description provided.

src/unix.rs Show resolved Hide resolved
src/unix.rs Show resolved Hide resolved
src/wasi.rs Outdated
let mut buf = [0 as c_char; 1024];
unsafe {
let mut buf = [0u8; 1024];
let c_str = unsafe {
if strerror_r(err.0, buf.as_mut_ptr(), buf.len() as libc::size_t) < 0 {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

 error[E0308]: mismatched types
Error:   --> src/wasi.rs:32:30
   |
32 |         if strerror_r(err.0, buf.as_mut_ptr(), buf.len() as libc::size_t) < 0 {
   |            ----------        ^^^^^^^^^^^^^^^^ expected `i8`, found `u8`
   |            |
   |            arguments to this function are incorrect
   |
   = note: expected raw pointer `*mut i8`
              found raw pointer `*mut u8`
note: function defined here
  --> src/wasi.rs:66:8
   |
66 |     fn strerror_r(errnum: c_int, buf: *mut c_char,
   |        ^^^^^^^^^^

src/windows.rs Outdated Show resolved Hide resolved
Cargo.toml Outdated
@@ -14,7 +14,8 @@ categories = ["no-std", "os"]
libc = "0.2"

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["errhandlingapi", "minwindef"] }
widestring = { version = "0.5.1", default-features = false }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

widestring MSRV is 1.58.1.

We can bump up our MSRV as well, but I'm not sure what our users will think about that. For example, caps and rustix guarantee 1.36 and 1.48 respectively.

Is there an easy alternative we can use here?

cc @sunfishcode and @lucab

src/windows.rs Outdated
#[cfg(feature = "std")]
fn from_utf16_lossy<'a>(input: &[u16], output: &'a mut [u8]) -> &'a str {
let mut output_len = 0;
for c in UStr::from_slice(input).chars_lossy().take_while(|&x| x != '\0') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to use core::char::decode_utf16 here? To get lossy behavior, you can run it through .map(|r| r.unwrap_or(core::char::REPLACEMENT_CHARACTER)).

If so, that would eliminated the need for the widestring dependency, which would avoid the MSRV issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Owner

@lambda-fairy lambda-fairy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you @A1-Triard and @sunfishcode!

@lambda-fairy lambda-fairy merged commit 57dbbd7 into lambda-fairy:main May 13, 2022
lambda-fairy added a commit that referenced this pull request May 13, 2022
@lambda-fairy lambda-fairy mentioned this pull request May 13, 2022
lambda-fairy added a commit that referenced this pull request May 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants