-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Implement #[alloc_error_handler] #52110
Conversation
This to-be-stable attribute is equivalent to `#[lang = "oom"]`. It is required when using the alloc crate without the std crate. It is called by `handle_alloc_error`, which is in turned called by "infallible" allocations APIs such as `Vec::push`.
(rust_highfive has picked a reviewer for you, use r? to override) |
r? @japaric |
@bors: r+ |
📌 Commit 8101344 has been approved by |
Random thought. If you can't use no_std + alloc without global_allocator and alloc_error_handler, why not put the allocation error handling in the GlobalAlloc trait, like it (kind of) used to be (because that was on the Alloc trait before GlobalAlloc existed). That would even allow a default to exist! |
@glandium the original thinking is that they're separable concerns especially at the libstd layer. Right now this implementation of handling OOM is different from libstd's allocator implementation in that it doesn't provide a fallback automatically if you haven't otherwise provided one. For libstd it makes sense to define how to allocate without defining how to implement OOM, and the same could perhaps one day also be true of |
⌛ Testing commit 8101344 with merge 36adfae3c10ac58714c6a0d93b949ceac314f1d1... |
💔 Test failed - status-appveyor |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
src/libstd/alloc.rs
Outdated
@@ -125,7 +125,8 @@ fn default_alloc_error_hook(layout: Layout) { | |||
|
|||
#[cfg(not(test))] | |||
#[doc(hidden)] | |||
#[lang = "oom"] | |||
#[cfg_attr(stage0, lang = "oom")] | |||
#[cfg_attr(not(stage0), alloc_error_handler)] | |||
#[unstable(feature = "alloc_internals", issue = "0")] | |||
pub extern fn rust_oom(layout: Layout) -> ! { |
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.
What abi is this function supposed to have? Here it's "C"
but elsewhere it seems to be "Rust"
.
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.
Good point, I’ve removed extern
to make it Rust ABI.
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.
Shouldn't the abi be checked as part of the signature check?
…h ABI of the declaration in liballoc
Failure above was @bors r=alexcrichton |
📌 Commit c37a4a0 has been approved by |
Er sorry, was cleaning out branches on the |
This to-be-stable attribute is equivalent to
#[lang = "oom"]
. It is required when using the alloc crate without the std crate. It is called byhandle_alloc_error
, which is in turned called by "infallible" allocations APIs such asVec::push
.Tracking issue: #51540