Skip to content

Commit

Permalink
Rollup merge of rust-lang#49050 - snf:fix_oom_asmjs, r=alexcrichton
Browse files Browse the repository at this point in the history
setting ABORTING_MALLOC=0 for asmjs backend

This changes the behaviour of the allocator for asmjs backend.
It will return NULL on OOM instead of aborting and let Rust choose the behaviour.
Fixes rust-lang#48968 and enables try_reserve (fallible allocation) in asmjs.
  • Loading branch information
kennytm committed Mar 15, 2018
2 parents 55a0075 + 9e64946 commit 90230ce
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 23 deletions.
5 changes: 0 additions & 5 deletions src/liballoc/tests/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@
// except according to those terms.

use std::borrow::Cow;
#[cfg(not(target_arch = "asmjs"))]
use std::collections::CollectionAllocErr::*;
#[cfg(not(target_arch = "asmjs"))]
use std::mem::size_of;
#[cfg(not(target_arch = "asmjs"))]
use std::{usize, isize};

pub trait IntoCow<'a, B: ?Sized> where B: ToOwned {
Expand Down Expand Up @@ -535,7 +532,6 @@ fn test_reserve_exact() {
assert!(s.capacity() >= 33)
}

#[cfg(not(target_arch = "asmjs"))]
#[test]
fn test_try_reserve() {

Expand Down Expand Up @@ -613,7 +609,6 @@ fn test_try_reserve() {

}

#[cfg(not(target_arch = "asmjs"))]
#[test]
fn test_try_reserve_exact() {

Expand Down
7 changes: 1 addition & 6 deletions src/liballoc/tests/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@

use std::borrow::Cow;
use std::mem::size_of;
use std::{usize, panic};
#[cfg(not(target_arch = "asmjs"))]
use std::isize;
use std::{usize, isize, panic};
use std::vec::{Drain, IntoIter};
#[cfg(not(target_arch = "asmjs"))]
use std::collections::CollectionAllocErr::*;

struct DropCounter<'a> {
Expand Down Expand Up @@ -994,7 +991,6 @@ fn test_reserve_exact() {
assert!(v.capacity() >= 33)
}

#[cfg(not(target_arch = "asmjs"))]
#[test]
fn test_try_reserve() {

Expand Down Expand Up @@ -1097,7 +1093,6 @@ fn test_try_reserve() {

}

#[cfg(not(target_arch = "asmjs"))]
#[test]
fn test_try_reserve_exact() {

Expand Down
8 changes: 1 addition & 7 deletions src/liballoc/tests/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@
use std::collections::VecDeque;
use std::fmt::Debug;
use std::collections::vec_deque::{Drain};
#[cfg(not(target_arch = "asmjs"))]
use std::collections::CollectionAllocErr::*;
#[cfg(not(target_arch = "asmjs"))]
use std::mem::size_of;
use std::isize;
#[cfg(not(target_arch = "asmjs"))]
use std::usize;
use std::{usize, isize};

use self::Taggy::*;
use self::Taggypar::*;
Expand Down Expand Up @@ -1053,7 +1049,6 @@ fn test_reserve_exact_2() {
assert!(v.capacity() >= 48)
}

#[cfg(not(target_arch = "asmjs"))]
#[test]
fn test_try_reserve() {

Expand Down Expand Up @@ -1155,7 +1150,6 @@ fn test_try_reserve() {

}

#[cfg(not(target_arch = "asmjs"))]
#[test]
fn test_try_reserve_exact() {

Expand Down
4 changes: 3 additions & 1 deletion src/librustc_back/target/asmjs_unknown_emscripten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ pub fn target() -> Result<Target, String> {
let mut args = LinkArgs::new();
args.insert(LinkerFlavor::Em,
vec!["-s".to_string(),
"ERROR_ON_UNDEFINED_SYMBOLS=1".to_string()]);
"ERROR_ON_UNDEFINED_SYMBOLS=1".to_string(),
"-s".to_string(),
"ABORTING_MALLOC=0".to_string()]);

let opts = TargetOptions {
dynamic_linking: false,
Expand Down
4 changes: 0 additions & 4 deletions src/libstd/collections/hash/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2755,11 +2755,8 @@ mod test_map {
use cell::RefCell;
use rand::{thread_rng, Rng};
use panic;
#[cfg(not(target_arch = "asmjs"))]
use realstd::collections::CollectionAllocErr::*;
#[cfg(not(target_arch = "asmjs"))]
use realstd::mem::size_of;
#[cfg(not(target_arch = "asmjs"))]
use realstd::usize;

#[test]
Expand Down Expand Up @@ -3696,7 +3693,6 @@ mod test_map {
assert_eq!(hm.len(), 0);
}

#[cfg(not(target_arch = "asmjs"))]
#[test]
fn test_try_reserve() {

Expand Down

0 comments on commit 90230ce

Please sign in to comment.