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

Remove redundant code and merge rest into rt-std #735

Merged
merged 2 commits into from
Sep 13, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 0 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ exclude = [
"node/runtime/wasm",
"core/executor/wasm",
"pwasm-alloc",
"pwasm-libc",
"core/test-runtime/wasm",
]

Expand Down
28 changes: 0 additions & 28 deletions core/executor/src/wasm_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

//! Rust implementation of Substrate contracts.

use std::cmp::Ordering;
use std::collections::HashMap;

use wasmi::{
Expand Down Expand Up @@ -161,33 +160,6 @@ impl_function_executor!(this: FunctionExecutor<'e, E>,
println!("{}", number);
Ok(())
},
ext_memcmp(s1: *const u8, s2: *const u8, n: usize) -> i32 => {
let sl1 = this.memory.get(s1, n as usize).map_err(|_| UserError("Invalid attempt to read from memory in first arg of ext_memcmp"))?;
let sl2 = this.memory.get(s2, n as usize).map_err(|_| UserError("Invalid attempt to read from memory in second arg of ext_memcmp"))?;
Ok(match sl1.cmp(&sl2) {
Ordering::Greater => 1,
Ordering::Less => -1,
Ordering::Equal => 0,
})
},
ext_memcpy(dest: *mut u8, src: *const u8, count: usize) -> *mut u8 => {
this.memory.copy_nonoverlapping(src as usize, dest as usize, count as usize)
.map_err(|_| UserError("Invalid attempt to copy_nonoverlapping in ext_memcpy"))?;
debug_trace!(target: "sr-io", "memcpy {} from {}, {} bytes", dest, src, count);
Ok(dest)
},
ext_memmove(dest: *mut u8, src: *const u8, count: usize) -> *mut u8 => {
this.memory.copy(src as usize, dest as usize, count as usize)
.map_err(|_| UserError("Invalid attempt to copy in ext_memmove"))?;
debug_trace!(target: "sr-io", "memmove {} from {}, {} bytes", dest, src, count);
Ok(dest)
},
ext_memset(dest: *mut u8, val: u32, count: usize) -> *mut u8 => {
debug_trace!(target: "sr-io", "memset {} with {}, {} bytes", dest, val, count);
this.memory.clear(dest as usize, val as u8, count as usize)
.map_err(|_| UserError("Invalid attempt to clear in ext_memset"))?;
Ok(dest)
},
ext_malloc(size: usize) -> *mut u8 => {
let r = this.heap.allocate(size);
debug_trace!(target: "sr-io", "malloc {} bytes at {}", size, r);
Expand Down
14 changes: 0 additions & 14 deletions core/executor/wasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions core/sr-std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ build = "build.rs"
[build-dependencies]
rustc_version = "0.2"

[dependencies]
pwasm-alloc = { path = "../../pwasm-alloc" }
pwasm-libc = { path = "../../pwasm-libc" }

[features]
default = ["std"]
std = []
Expand Down
1 change: 1 addition & 0 deletions core/sr-std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#![cfg_attr(not(feature = "std"), feature(panic_handler))]
#![cfg_attr(not(feature = "std"), feature(core_intrinsics))]
#![cfg_attr(not(feature = "std"), feature(alloc))]
//#![crate_type = "rlib"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove the commented code


#![cfg_attr(feature = "std", doc = "Polkadot runtime standard library as compiled when linked with Rust's standard library.")]
#![cfg_attr(not(feature = "std"), doc = "Polkadot's runtime standard library as compiled without Rust's standard library.")]
Expand Down
31 changes: 27 additions & 4 deletions core/sr-std/without_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,33 @@

#[cfg(feature = "nightly")]
extern crate alloc;
#[cfg(feature = "nightly")]
extern crate pwasm_libc;
#[cfg(feature = "nightly")]
extern crate pwasm_alloc;

extern "C" {
fn ext_malloc(size: usize) -> *mut u8;
fn ext_free(ptr: *mut u8);
}

/// Wasm allocator
pub struct WasmAllocator;

#[global_allocator]
static ALLOCATOR: WasmAllocator = WasmAllocator;

mod __impl {
use core::alloc::{GlobalAlloc, Layout};

use super::WasmAllocator;

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

unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
super::ext_free(ptr as *mut u8)
}
}
}

pub use alloc::boxed;
pub use alloc::rc;
Expand Down
14 changes: 0 additions & 14 deletions core/test-runtime/wasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions doc/packages/substrate.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ include::../../core/primitives/README.adoc[]

include::../../pwasm-alloc/README.adoc[]

include::../../pwasm-libc/README.adoc[]

include::../../core/rpc/README.adoc[]

include::../../core/rpc-servers/README.adoc[]
Expand Down
14 changes: 0 additions & 14 deletions node/runtime/wasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 0 additions & 23 deletions pwasm-alloc/Cargo.toml

This file was deleted.

25 changes: 0 additions & 25 deletions pwasm-alloc/README.adoc

This file was deleted.

14 changes: 0 additions & 14 deletions pwasm-alloc/build.rs

This file was deleted.

34 changes: 0 additions & 34 deletions pwasm-alloc/src/lib.rs

This file was deleted.

15 changes: 0 additions & 15 deletions pwasm-libc/Cargo.toml

This file was deleted.

24 changes: 0 additions & 24 deletions pwasm-libc/README.adoc

This file was deleted.

Loading