-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
[std] clarify ffi C string nul term & length discussion #56140
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @TimNN (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
I don't agree with the change to measured. My intuition (as a non-native English speaker) is that "measure" implies measuring something physical (e.g. distance, time). The dictionary seems to confirm that intuition.
I don't think describing how |
7f66e03
to
b8da5ef
Compare
I've rewritten it again, hopefully you'll like v2 better. Sorry for the delay, I've got very irregular internet access currently.
Ok, I wasn't 100% happy with it either, but it was better. I've used "counting" instead in v2.
I think the discussion necessitates brief mention that it involves counting. I hope you like the revised text more. |
☔ The latest upstream changes (presumably #56578) made this pull request unmergeable. Please resolve the merge conflicts. |
b8da5ef
to
85c6548
Compare
re-written the paragraph, including: - Changed use of "calculated" to "count". "calculated" just sounds wrong, giving a false impression of what strlen() does. - Changed "C code must manually call a function". Firstly, "manually"? Secondly, a function is called in Rust also... the difference is in what the function does - counting v.s. reading an attribute...
ping from triage @TimNN awaiting your review on this |
I'm not quite sure about this PR. Some parts are certainly improved, I think, but I'm not sure about other parts of the docs here. cc @rust-lang/docs: I would appreciated your input here. |
I preferred the original version. :-/ |
cc @rust-lang/docs |
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.
While we're in this section, i kind of want to either capitalize the use of NUL or write it as the word "null" - otherwise, to me it just looks like someone kept misspelling "null".
//! length is stored); in C it is an O(length) operation because the | ||
//! length needs to be computed by scanning the string for the nul | ||
//! terminator. | ||
//! end. The length of the string is not stored, but has to be determined |
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 feel like "calculated" is still a better word here? "Determined" feels like it implies that there's some kind of conceptual decision-making going on, but "calculated" feels more like it's a rote procedure that needs to be run through to figure out the length. I could be reading way too far into this, though. >_>
//! nul that marks its end, counting as it goes. The value returned by | ||
//! common functions that perform this, is effectively the index position | ||
//! of the nul, and thus the string length (in terms of buffer size) is | ||
//! actually len+1. Rust strings don't have a nul terminator, their |
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.
Part of me wants to add some types to single out what "Rust strings" actually means. Something like:
Rust strings (like
&str
andString
) don't have a nul terminator...
On the other hand, there are many more "string" types in Rust, and e.g. OsString
also stores its length separately instead of having a null byte to mark the end. Would it be too confusing to single out these types and leave out the others?
I'm going to close this PR as it's been idle for quite a while. If you have some time to address the review comments then we'd be happy to either reopen this PR or see a new PR from you in the future. Thanks! |
re-written the paragraph, including:
wrong, giving a false impression of what strlen() does.
Secondly, a function is called in Rust also... the difference is in
what the function does - measurement v.s. reading an attribute...
"buffer" here was bound to confuse.