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

Fixes WasmAllocator to reflect recent nightly API changes #214

Merged
merged 5 commits into from
Jun 15, 2018
Merged
Changes from 2 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
10 changes: 4 additions & 6 deletions substrate/pwasm-alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +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))]

Expand All @@ -17,19 +16,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 Author

Choose a reason for hiding this comment

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

This line needs attention. Note, that I removed the leading self. Don't sure, how WASM and no-std stuff is linked, so it may be an issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

probably the extern crate alloc and corresponding feature is no longer necessary since this stuff is in libcore now

Copy link
Contributor

@pepyakin pepyakin Jun 13, 2018

Choose a reason for hiding this comment

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

also the feature global_allocator is also no longer needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, forgot to push the second commit.

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