Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually need feature(alloc) here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it successfully compiled without alloc and allocator_api.


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