Skip to content

remove CStr8 and replace by libcore::ffi::CStr #496

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

Closed
wants to merge 1 commit into from

Conversation

phip1611
Copy link
Member

This is a cleanup PR. It removes everything related to CStr8. I replaced it with core::ffi::CStr which is available since Rust 1.62.0.

Copy link
Member

@nicholasbishop nicholasbishop left a comment

Choose a reason for hiding this comment

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

One concern I have here is encoding. The CHAR8 type in the UEFI spec (section 2.3.1 Data Types) says: "1-byte character. Unless otherwise specified, all 1-byte or ASCII characters and strings are stored in 8-bit ASCII encoding format, using the ISO-Latin-1 character set."

As far as I can see though, CStr doesn't specify any particular encoding; it's just a null-terminated C string.

I'm not sure that the current code is correctly enforcing the latin-1 encoding (are all 255 non-null bit patterns actually valid as Char8::try_from implies?), and I've never actually used any of the APIs in UEFI that use latin-1 instead of UCS2, but I think there is still good reason to have a latin-1 type in uefi-rs.

@phip1611
Copy link
Member Author

phip1611 commented Sep 6, 2022

Couldn't we easily verify this by using the one-liner let _ = str::from_raw_parts(cstr.as_ptr(), cstr.len()).map_err(...)??

Ahh, there might be mismatches because UTF-8 would be allowed by that line but UEFI doesn't understand it..From that string slice, we could check if the length equals the number of chars, thus, there are no two-byte or four-byte characters in it 😅 then we have what we want

I analyzed the code lines where CStr8 is used. We are exposing the "PXE Base Code protocol" (struct BaseCode) which indeed has this type in its public API.

I do not insist on this change, but I always like code cleanups.

Hm.. the more I think about it: yeah, probably core::ffi::CStr is not what we want here in the public interface

@phip1611
Copy link
Member Author

phip1611 commented Sep 6, 2022

Closing this in favor of #506

@phip1611 phip1611 closed this Sep 6, 2022
@phip1611 phip1611 deleted the cstr8-refactoring branch April 2, 2023 13:47
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.

None yet

2 participants