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

* Remove redundant code and merge rest into rt-std

* Update lib.rs
This commit is contained in:
Gav Wood
2018-09-13 14:54:24 +02:00
committed by GitHub
parent 0ed48c89ab
commit a7f8f0f1bd
16 changed files with 27 additions and 285 deletions
@@ -16,7 +16,6 @@
//! Rust implementation of Substrate contracts.
use std::cmp::Ordering;
use std::collections::HashMap;
use wasmi::{
@@ -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);
-14
View File
@@ -63,18 +63,6 @@ dependencies = [
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "pwasm-alloc"
version = "0.1.0"
dependencies = [
"pwasm-libc 0.1.0",
"rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "pwasm-libc"
version = "0.1.0"
[[package]]
name = "quote"
version = "0.6.5"
@@ -149,8 +137,6 @@ dependencies = [
name = "sr-std"
version = "0.1.0"
dependencies = [
"pwasm-alloc 0.1.0",
"pwasm-libc 0.1.0",
"rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
-4
View File
@@ -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 = []
+27 -4
View File
@@ -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;
-14
View File
@@ -363,18 +363,6 @@ dependencies = [
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "pwasm-alloc"
version = "0.1.0"
dependencies = [
"pwasm-libc 0.1.0",
"rustc_version 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "pwasm-libc"
version = "0.1.0"
[[package]]
name = "quote"
version = "0.6.3"
@@ -540,8 +528,6 @@ dependencies = [
name = "sr-std"
version = "0.1.0"
dependencies = [
"pwasm-alloc 0.1.0",
"pwasm-libc 0.1.0",
"rustc_version 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
]