News for hackers. Stuff that matters.
Re:Cross-platform Rust rewrite of the GNU coreutils by steveklabnik on Tuesday March 22, 2016 @01:47PM (#11338391)
The Rust standard library does assume that allocation succeeds. The language itself knows nothing about the heap, and so you can write allocators that do whatever you wish. Side note: on most Linux distros, overcommit is on, and so malloc will basically always succeed; the OOM killer will kill your program before you'd get a failure. I am less knowledgeable about OSX and Windows.

I cannot speak to SQlite in this regard.

Re:Cross-platform Rust rewrite of the GNU coreutils by nickpsecurity on Tuesday March 22, 2016 @02:28PM (#11338730)
Holy crap, I'd never have imagined that... A design that assumes allocation always succeeds flies in the face of decades of safety/security-critical coding wisdom. I strongly recommend the team revisit and change that somehow to account for failures, NULL's, whatever. Actually, same anywhere a failure-prone, esp hardware, resource is acquired. C apps can handle this issue so Rust should as well if it's to replace them.

EDIT: Thanks to replies for clarification that it's just one allocator, aborts, and others are available. Still feel weird about it but that's better.

Re:Cross-platform Rust rewrite of the GNU coreutils by tatterdemalion on Tuesday March 22, 2016 @02:58PM (#11339017)
The standard allocator will abort on oom error. For applications which need to be tolerant to oom errors, you need to use a different allocator.

Most programs can't tolerate oom errors, though, and it would be absolutely unreasonable for every function in the standard library that might perform an allocation to return an error that has to be handled by every programmer all the time.

EDIT: C's solution is to make it very easy to ignore oom errors, so most programmers just don't handle oom errors. Rust's solution is much better.

Re:Cross-platform Rust rewrite of the GNU coreutils by quotemstr on Tuesday March 22, 2016 @11:35PM (#11341969)
Every function in the C++ standard library reliably communicates allocation failure to the application without relying on aborting the whole program. If Rust can do it, C++ can do it too. Rust got itself into this trap by eschewing exceptions.
Re:Cross-platform Rust rewrite of the GNU coreutils by tatterdemalion on Wednesday March 23, 2016 @12:06AM (#11342091)
Maybe avoid using judgmental language like calling a standard allocator that aborts on oom a "trap." The Rust team made conscious design choices in full awareness of the trade-offs. Moreover, Rust actually does have thread unwinding, and even the ability to catch an unwinding thread, so it is not true that the Rust standard library could not have unwound on oom.

Rust's standard library just isn't designed for writing applications that need to survive oom errors. That's fine, its not designed for a number of other applications which Rust the language is well-suited for either (operating systems, for example). Its designed for the majority use case, because life is full of trade offs.

Re:Cross-platform Rust rewrite of the GNU coreutils by quotemstr on Wednesday March 23, 2016 @04:55AM (#11342953)
If Rust isn't suitable for C's niche, Rust's proponents should stop pitching Rust as a replacement for C.

> The Rust team made conscious design choices in full awareness of the trade-offs

I don't think that anyone who isn't already predisposed to avoid exceptions would consider the tradeoff the Rust people made to be the correct one.

Re:Cross-platform Rust rewrite of the GNU coreutils by tatterdemalion on Wednesday March 23, 2016 @01:15PM (#11346368)
This is absurd. Most C applications do not need to persist through OOM errors, and has people have repeatedly reiterated, it is totally possible to write a Rust program that persists through OOM errors.
Re:Cross-platform Rust rewrite of the GNU coreutils by jstimpfle on Tuesday March 22, 2016 @07:07PM (#11340675)
To be fair, not a bug in the language itself. Regarding libc, it's also very easy to abort on error. Just write a function xmalloc().
Re:Cross-platform Rust rewrite of the GNU coreutils by kinghajj on Tuesday March 22, 2016 @02:39PM (#11338828)
Note that Rust, the language, is perfectly capable of handling memory allocation failures, it's just the standard library that makes the assumption. Embedded environments wouldn't use the standard library for numerous reasons anyway, and the "core" library uses no allocation at all. That said, IIRC handling of failure in the standard library will happen eventually, I believe there's just no consensus yet on the best way to do it.
Re:Cross-platform Rust rewrite of the GNU coreutils by all2well on Tuesday March 22, 2016 @03:23PM (#11339236)
At least for the nightly builds, you can specify a closure to run when OOM happens. The only restriction is that it cannot return, but you can "recover" from panics in the nightly standard library as well. The thinking was, I think, that in most cases the default behavior of abort is the correct behavior. Recovering from a failed malloc is really only relevant in large allocations, and there are multiple paths (including directly using __rust_allocate) to recovery in that case.

Furthermore, keep in mind that the _pure language_ Rust has no concept of dynamic allocation (apart from "language elements" like __rust_allocate, which are kind of like a pre-linker).

Re:Cross-platform Rust rewrite of the GNU coreutils by zurn on Tuesday March 22, 2016 @03:13PM (#11339163)
Another robustness and availability-oriented system that will eagerly abort your process on this kind of failure is Erlang.
Re:Cross-platform Rust rewrite of the GNU coreutils by aidenn0 on Tuesday March 22, 2016 @02:01PM (#11338502)
Even with overcommit on, malloc can return NULL on linux.
Re:Cross-platform Rust rewrite of the GNU coreutils by steveklabnik on Tuesday March 22, 2016 @03:05PM (#11339101)
liballoc does check for NULL IIRC.
Re:Cross-platform Rust rewrite of the GNU coreutils by ktRolster on Tuesday March 22, 2016 @02:03PM (#11338533)
Side note: on most Linux distros, overcommit is on, and so malloc will basically always succeed; the OOM killer will kill your program before you'd get a failure

Clarifying note: this is configurable.