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

GlobalAlloc docs example crashes #81847

Closed
ijackson opened this issue Feb 7, 2021 · 3 comments · Fixed by #81864
Closed

GlobalAlloc docs example crashes #81847

ijackson opened this issue Feb 7, 2021 · 3 comments · Fixed by #81864
Assignees
Labels
C-bug Category: This is a bug. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@ijackson
Copy link
Contributor

ijackson commented Feb 7, 2021

I cut and pasted the example for GlobalAlloc from the stdlib docs into the playground. Contrary to the implications in the documentation, the program does not run to completion. Instead, it prints

memory allocation of 4 bytes failed
timeout: the monitored command dumped core
/playground/tools/entrypoint.sh: line 11:     8 Aborted                 timeout --signal=KILL ${timeout} "$@"

I think this is fine behaviour. The example is wrong and should be fixed somehow.

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=54f5b4b24c19b64962d35ec4031ee4a5

I was doing this because I am trying to write a test case for the stdlib which involves a stunt allocator. So far my #[global_alloc] annotation in a file in library/std/tests/ does not seem to be effective. I suspect that whatever is getting in my way might also get in the way of adding a test case specifically for #[global_alloc]. Looks like src/test/ui/ is the right place and I should read the dev docs...

The example from std::alloc::System works correctly.

@ijackson ijackson added the C-bug Category: This is a bug. label Feb 7, 2021
@ijackson
Copy link
Contributor Author

ijackson commented Feb 7, 2021

@rustbot modify labels +T-libs

@rustbot rustbot added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Feb 7, 2021
@ijackson
Copy link
Contributor Author

ijackson commented Feb 7, 2021

@rustbot claim

@vitalyd
Copy link

vitalyd commented Feb 8, 2021

My $.02 is that #81864 is a bit too involved for an example.

The existing example can be fixed by delegating to the System allocator up until main() runs, at which point the sample allocator can take effect. Something like this.

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Jul 21, 2021
…nieu

docs: GlobalAlloc: completely replace example with one that works

Since this is an example, this could really do with some review from someone familiar with unsafe stuff!

I made the example no longer `no_run` since it works for me.

Fixes rust-lang#81847
ehuss added a commit to ehuss/rust that referenced this issue Jul 21, 2021
…nieu

docs: GlobalAlloc: completely replace example with one that works

Since this is an example, this could really do with some review from someone familiar with unsafe stuff!

I made the example no longer `no_run` since it works for me.

Fixes rust-lang#81847
@bors bors closed this as completed in 07e11e8 Jul 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants