-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Replace str::sbuf with *ctypes::c_char #1715
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
Comments
See also #1672 |
C
|
Needless to say, I think this is such utter nonsense that it has no place re-infecting our type system, and I'm happy to encapsulate the madness in the |
graydon, I can't tell where you fall on getting rid of sbuf. I now think we have two use cases - treating a string as a byte buffer, and interop with C. So I think we should get rid of str::sbuf, make str::as_buf use a *u8 buffer, and add a new str::as_cstr that does the exact same thing, but typed as a *ctypes::c_char buffer. Also str::from_cstr/from_cstr_len take *c_char and we get two new str::from_buf/from_buf_len functions for *u8. |
Can someone show me any (sane) code where it is important for the signedness of characters in Rust aligns with that of C? It seems that just being able to assume unsignedness (on the Rust side) makes thing easier. You don't want to conditionalize all code that works with >127 char values on some obscure flag. |
I'm in favor of defining c_char as u8. |
This is what i intend to do:
|
Also, modifying str::from_cstr, etc. to use *c_char and adding companion from_buf methods |
Done. |
sbuf is mostly used for C interop. Interestingly, we define sbuf as
*u8
and usually talk about strings as arrays ofu8
, but C char is a signed value. It probably doesn't make any difference.The text was updated successfully, but these errors were encountered: