mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-31 01:11:06 +00:00
Merge pull request #469 from alexcrichton/less-nightly
Remove usage of the `try_reserve` nightly feature
This commit is contained in:
commit
ee1d4ba9ce
27
src/lib.rs
27
src/lib.rs
@ -5,7 +5,7 @@
|
|||||||
//! this crate and this crate also provides JS bindings through the `JsValue`
|
//! this crate and this crate also provides JS bindings through the `JsValue`
|
||||||
//! interface.
|
//! interface.
|
||||||
|
|
||||||
#![feature(use_extern_macros, wasm_import_module, try_reserve, unsize)]
|
#![feature(use_extern_macros, wasm_import_module, unsize)]
|
||||||
#![cfg_attr(feature = "js_globals", feature(proc_macro, wasm_custom_section))]
|
#![cfg_attr(feature = "js_globals", feature(proc_macro, wasm_custom_section))]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
|
||||||
@ -661,24 +661,29 @@ pub mod __rt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if_std! {
|
if_std! {
|
||||||
use std::prelude::v1::*;
|
use std::alloc::{System, GlobalAlloc, Layout};
|
||||||
|
use std::mem;
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern fn __wbindgen_malloc(size: usize) -> *mut u8 {
|
pub extern fn __wbindgen_malloc(size: usize) -> *mut u8 {
|
||||||
use core::mem;
|
let align = mem::align_of::<usize>();
|
||||||
|
if let Ok(layout) = Layout::from_size_align(size, align) {
|
||||||
let mut ret = Vec::new();
|
unsafe {
|
||||||
if ret.try_reserve_exact(size).is_err() {
|
let ptr = System.alloc(layout);
|
||||||
super::throw("invalid malloc request");
|
if !ptr.is_null() {
|
||||||
|
return ptr
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let ptr = ret.as_mut_ptr();
|
|
||||||
mem::forget(ret);
|
super::throw("invalid malloc request");
|
||||||
return ptr
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern fn __wbindgen_free(ptr: *mut u8, size: usize) {
|
pub unsafe extern fn __wbindgen_free(ptr: *mut u8, size: usize) {
|
||||||
drop(Vec::<u8>::from_raw_parts(ptr, 0, size));
|
let align = mem::align_of::<usize>();
|
||||||
|
let layout = Layout::from_size_align_unchecked(size, align);
|
||||||
|
System.dealloc(ptr, layout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user