Skip to content
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

Vec and Box documentation do not state maximum allocation size guarantee #68593

Closed
aticu opened this issue Jan 28, 2020 · 3 comments
Closed

Vec and Box documentation do not state maximum allocation size guarantee #68593

aticu opened this issue Jan 28, 2020 · 3 comments
Labels
A-collections Area: `std::collection` A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools C-enhancement Category: An issue proposing an enhancement or a PR with one. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@aticu
Copy link
Contributor

aticu commented Jan 28, 2020

In the documentation for pointer::add, it is mentioned that

Vec and Box ensure they never allocate more than isize::MAX bytes

however, this is not stated in documentation of Vec, the module documentation of vec, the documentation of Box or the module documentation of boxed.

This can cause doubt, whether this statement actually holds true, since the places where one would expect such guarantees to be made (especially the "Guarantees" section of the Vec documentation) does not mention these guarantees.

@jonas-schievink jonas-schievink added A-collections Area: `std::collection` C-enhancement Category: An issue proposing an enhancement or a PR with one. A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Jan 28, 2020
@cuviper
Copy link
Member

cuviper commented Jan 28, 2020

Along these lines, I want to point out that this a real system limit now, beyond just what Rust wants to do, at least if you're using the system allocator. This is mentioned in the glibc 2.30 release notes:

* Memory allocation functions malloc, calloc, realloc, reallocarray, valloc,
  pvalloc, memalign, and posix_memalign fail now with total object size
  larger than PTRDIFF_MAX.  This is to avoid potential undefined behavior with
  pointer subtraction within the allocated object, where results might
  overflow the ptrdiff_t type.

C and C++ ptrdiff_t is essentially the same as Rust's isize, so PTRDIFF_MAX == isize::MAX.

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Feb 1, 2020
Added upper bound of what vecs and boxes can allocate

Fixed issue rust-lang#68593
I added a line of documentation to these two files to reflect that vectors and boxes ensure that they never allocate more than `isize::MAX` bytes.
r? @steveklabnik
JohnTitor added a commit to JohnTitor/rust that referenced this issue Feb 1, 2020
Added upper bound of what vecs and boxes can allocate

Fixed issue rust-lang#68593
I added a line of documentation to these two files to reflect that vectors and boxes ensure that they never allocate more than `isize::MAX` bytes.
r? @steveklabnik
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Feb 3, 2020
Added upper bound of what vecs and boxes can allocate

Fixed issue rust-lang#68593
I added a line of documentation to these two files to reflect that vectors and boxes ensure that they never allocate more than `isize::MAX` bytes.
r? @steveklabnik
@aticu
Copy link
Contributor Author

aticu commented Feb 4, 2020

I want to point out that this a real system limit now, beyond just what Rust wants to do, at least if you're using the system allocator.

If that's the case, it might make sense to document that constraint on every allocation based API in the standard library, since it should apply to all of them.

@poliorcetics
Copy link
Contributor

This has been fixed by #68711 and could be closed

@sfackler sfackler closed this as completed Jun 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-collections Area: `std::collection` A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools C-enhancement Category: An issue proposing an enhancement or a PR with one. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants