Re:Writing a JPEG Decoder in Rust – Part 2: Implementation I
by Manishearth on Friday August 19, 2016 @01:40PM
(#12321838)
Rust has provided ways to not abort on oom for a while now.
[ Parent
| on HN ]
Re:Writing a JPEG Decoder in Rust – Part 2: Implementation I
by wahern on Friday August 19, 2016 @07:47PM
(#12324292)
If by "a while" you mean several months. But, yes, the recent addition of catch_unwind answered one of my biggest gripes with Rust.
https://doc.rust-lang.org/std/panic/fn.catch_unwind.html
Does anybody know if the standard library allocator aborts the process or throws a catchable exception? When they added catch_unwind they officially split panics into two types: abort panics and unwind panics. Code can choose one or the other when panic'ing. Also, programs can be built in such a way that all panics become aborts. That kind of sucks but it's probably one of the compromises needed to assuage those Rust developers who don't believe it's practical to handle OOM conditions.
Re:Writing a JPEG Decoder in Rust – Part 2: Implementation I
by steveklabnik on Friday August 19, 2016 @08:52PM
(#12324500)
To be clear, _every_ panic has to have the same implementation; you can't choose unwind vs abort for some panics vs others.
The default allocator crate always does an abort, both before and after this change.
Re:Writing a JPEG Decoder in Rust – Part 2: Implementation I
by wahern on Friday August 19, 2016 @09:33PM
(#12324624)
When building an app, does changing the default allocator effect all imported libraries? And is that allocator used for boxing, when boxing requires dynamic allocation?
Re:Writing a JPEG Decoder in Rust – Part 2: Implementation I
by steveklabnik on Friday August 19, 2016 @09:38PM
(#12324640)
Currently, "the allocator" is global in Rust. That is, the standard library uses liballoc to do all of its heap allocation, and it's liballoc that aborts on OOM.
You can of course write code that does anything, including use some other mechanism than liballoc.
There's motion on several fronts here:
The first, and currently unstable, is swapping out the implementation of liballoc for a different one. (we ship jemalloc and a pass-through to the system allocator with Rust)
The second, and currently in the "working on an RFC" phase, is per-object allocators.
Both of these are unstable because we're not 100% sure of the interface we want to stabilize yet, it's still a work in progress.
> when boxing requires dynamic allocation?
Boxing always implies dynamic allocation.