-
Notifications
You must be signed in to change notification settings - Fork 54
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
Use portable c_char instead of i8 #33
Conversation
Signed-off-by: Alexander Rodin <[email protected]>
src/database/error.rs
Outdated
@@ -21,7 +21,7 @@ impl Error { | |||
/// | |||
/// This method is `unsafe` because the pointer must be valid and point to heap. | |||
/// The pointer will be passed to `free`! | |||
pub unsafe fn new_from_i8(message: *const i8) -> Error { | |||
pub unsafe fn new_from_char(message: *const c_char) -> Error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we're here already, we could also modernise the codebase cough and make this function be pub(crate)
. Also, this is one of the rare cases where I would be okay with accepting a patch that uses from_utf8_unchecked
, as I trust the leveldb maintainers to have their error messages be valid utf8 in all cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I trust the leveldb maintainers to have their error messages be valid utf8 in all cases
I would not trust them in this, as they are using an ordinary C++ std::string
which is not UTF-8 aware. In particular, I was able to generate non-UTF-8 error message with this code on Linux:
use leveldb::{database::Database, options::Options};
use std::{ffi::OsStr, os::unix::ffi::OsStrExt, path::Path};
fn main() {
let _ = Database::<i32>::open(Path::new(OsStr::from_bytes(b"/\xc3\x28")), Options::new())
.map_err(|e| println!("{:?}", e));
}
where the path is not valid UTF-8. I've created a separate PR #34 on top of this one that handles non-unicode strings explicitly.
That is correct. Thanks for the patch! I left one comment. |
Signed-off-by: Alexander Rodin <[email protected]>
Signed-off-by: Alexander Rodin <[email protected]>
I believe this could be closed as #36 achieved the same goal. |
Closing as suggested. Thanks for the patch nevertheless, @michaelsproul! |
Some architectures, such as ARM, use unsigned 8-bit integers to represent C
char
type.In order to make the code work on architectures with both signed and unsigned chars, this PR replaces
i8
byc_char
in places where it corresponds to Cchar
type.