-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Revise TARPL's description for allocating 0 bytes #27434
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
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @gankro (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. 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. |
Ah, thanks for the info (I can't even remember where I got that info... possibly just inferred it from existing patterns/comments)! I think I'd still explicitly call out allocating as an annoying detail. In particular if we used uniform allocating code then 0 allocations might give back null and we'd abort with OOM. |
|
@jeehoonkang "general" code checks for the allocator yielding |
Ah, I see! thank you. |
☔ The latest upstream changes (presumably #27444) made this pull request unmergeable. Please resolve the merge conflicts. |
@jeehoonkang we moved everything to src/doc/nomicon -- if you |
@gankro Thank you for noticing me! I agree with your comment "I think I'd still explicitly call out allocating as an annoying detail.", so I revised my PR. But I think I cannot fully grasp what you intended to write in this place. Please review :-) |
@@ -85,8 +85,8 @@ support values. | |||
Safe code need not worry about ZSTs, but *unsafe* code must be careful about the | |||
consequence of types with no size. In particular, pointer offsets are no-ops, | |||
and standard allocators (including jemalloc, the one used by default in Rust) | |||
generally consider passing in `0` for the size of an allocation as Undefined | |||
Behaviour. | |||
generally return `nullptr` when a zero-sized allocation is requested, which is |
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 think I'd replace "generally" with "may" here based on the documentation you linked.
In Section 3.2, TARPL says that "standard allocators (including jemalloc, the one used by default in Rust) generally consider passing in 0 for the size of an allocation as Undefined Behaviour." However, the C standard and jemalloc manual says allocating zero bytes should succeed: - C11 7.22.3 paragraph 1: "If the size of the space requested is zero, the behavior is implementation-defined: either a null pointer is returned, or the behavior is as if the size were some nonzero value, except that the returned pointer shall not be used to access an object." - [jemalloc manual](http://www.freebsd.org/cgi/man.cgi?query=jemalloc&sektion=3): "The malloc and calloc functions return a pointer to the allocated memory if successful; otherwise a NULL pointer is returned and errno is set to ENOMEM." + Note that the description for `allocm` says "Behavior is undefined if size is 0," but it is an experimental API.
Revised :-) |
@bors r+ rollup Thanks! |
📌 Commit 9bfb8d3 has been approved by |
In Section 3.2, TARPL says that "standard allocators (including jemalloc, the one used by default in Rust) generally consider passing in 0 for the size of an allocation as Undefined Behaviour." However, the C standard and jemalloc manual says allocating zero bytes should succeed: - C11 7.22.3 paragraph 1: "If the size of the space requested is zero, the behavior is implementation-defined: either a null pointer is returned, or the behavior is as if the size were some nonzero value, except that the returned pointer shall not be used to access an object." - [jemalloc manual](http://www.freebsd.org/cgi/man.cgi?query=jemalloc&sektion=3): "The malloc and calloc functions return a pointer to the allocated memory if successful; otherwise a NULL pointer is returned and errno is set to ENOMEM." + Note that the description for `allocm` says "Behavior is undefined if size is 0," but it is an experimental API. r? @gankro
In Section 3.2, TARPL says that "standard allocators (including jemalloc, the one used by default in Rust) generally consider passing in 0 for the size of an allocation as Undefined Behaviour."
However, the C standard and jemalloc manual says allocating zero bytes
should succeed:
allocm
says "Behavior is undefined if size is 0," but it is an experimental API.r? @gankro