mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-16 02:00:51 +00:00
Fix wasm sizes on nightly
Looks like the recent changes to `Vec::with_capacity` meant that our previous codegen to avoid panics no longer avoids panics. Let's pick up the `try_reserve` unstable feature for now and hopefully it'll be stabilized before the other pieces in the future.
This commit is contained in:
parent
5638126598
commit
91295f4d16
14
src/lib.rs
14
src/lib.rs
@ -5,7 +5,7 @@
|
||||
//! this crate and this crate also provides JS bindings through the `JsValue`
|
||||
//! interface.
|
||||
|
||||
#![feature(use_extern_macros)]
|
||||
#![feature(use_extern_macros, try_reserve)]
|
||||
|
||||
extern crate wasm_bindgen_macro;
|
||||
|
||||
@ -399,18 +399,10 @@ pub mod __rt {
|
||||
|
||||
#[no_mangle]
|
||||
pub extern fn __wbindgen_malloc(size: usize) -> *mut u8 {
|
||||
// Any malloc request this big is bogus anyway. If this actually
|
||||
// goes down to `Vec` we trigger a whole bunch of panicking
|
||||
// machinery to get pulled in from libstd anyway as it'll verify
|
||||
// the size passed in below.
|
||||
//
|
||||
// Head this all off by just aborting on too-big sizes. This
|
||||
// avoids panicking (code bloat) and gives a better error
|
||||
// message too hopefully.
|
||||
if size >= usize::max_value() / 2 {
|
||||
let mut ret = Vec::new();
|
||||
if ret.try_reserve_exact(size).is_err() {
|
||||
super::throw("invalid malloc request");
|
||||
}
|
||||
let mut ret = Vec::with_capacity(size);
|
||||
let ptr = ret.as_mut_ptr();
|
||||
mem::forget(ret);
|
||||
return ptr
|
||||
|
Loading…
x
Reference in New Issue
Block a user