Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Merge pull request #214 from paritytech/dk-pwasm-alloc-fix
Browse files Browse the repository at this point in the history
Fixes `WasmAllocator` to reflect recent nightly API changes
  • Loading branch information
pepyakin authored Jun 15, 2018
2 parents a123687 + e909d89 commit 4760b35
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion polkadot/parachain/test-chains/basic_add/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ crate-type = ["cdylib"]

[dependencies]
polkadot-parachain = { path = "../../", default-features = false }
wee_alloc = "0.4.0"
wee_alloc = { git = "https://github.com/rustwasm/wee_alloc", rev = "4e9f23fff1f2474962085ca693f8884db666889f" }
tiny-keccak = "1.4"
pwasm-libc = "0.2"

Expand Down
2 changes: 1 addition & 1 deletion polkadot/parachain/test-chains/basic_add/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//! Basic parachain that adds a number as part of its state.
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), feature(alloc, core_intrinsics, global_allocator, lang_items, panic_implementation))]
#![cfg_attr(not(feature = "std"), feature(alloc, core_intrinsics, lang_items, panic_implementation))]

#[cfg(not(feature = "std"))]
extern crate alloc;
Expand Down
12 changes: 4 additions & 8 deletions substrate/pwasm-alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
#![cfg_attr(feature = "strict", deny(warnings))]
#![no_std]
#![crate_type = "rlib"]
#![cfg_attr(feature = "nightly", feature(global_allocator))]
#![cfg_attr(feature = "nightly", feature(alloc))]
#![cfg_attr(feature = "nightly", feature(allocator_api))]

//! Custom allocator crate for wasm
Expand All @@ -17,19 +14,18 @@ static ALLOCATOR: WasmAllocator = WasmAllocator;

#[cfg(feature = "nightly")]
mod __impl {
extern crate alloc;
extern crate pwasm_libc;

use self::alloc::heap::{GlobalAlloc, Layout, Opaque};
use core::alloc::{GlobalAlloc, Layout};

use super::WasmAllocator;

unsafe impl GlobalAlloc for WasmAllocator {
unsafe fn alloc(&self, layout: Layout) -> *mut Opaque {
pwasm_libc::malloc(layout.size()) as *mut Opaque
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
pwasm_libc::malloc(layout.size()) as *mut u8
}

unsafe fn dealloc(&self, ptr: *mut Opaque, _layout: Layout) {
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
pwasm_libc::free(ptr as *mut u8)
}
}
Expand Down

0 comments on commit 4760b35

Please sign in to comment.