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
-14
View File
@@ -1845,18 +1845,6 @@ dependencies = [
"getopts 0.2.17 (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 = "pwasm-utils"
version = "0.3.1"
@@ -2351,8 +2339,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)",
]
-1
View File
@@ -57,7 +57,6 @@ exclude = [
"node/runtime/wasm",
"core/executor/wasm",
"pwasm-alloc",
"pwasm-libc",
"core/test-runtime/wasm",
]
@@ -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)",
]
-2
View File
@@ -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[]
-14
View File
@@ -404,18 +404,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 = "pwasm-utils"
version = "0.3.1"
@@ -611,8 +599,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)",
]
-23
View File
@@ -1,23 +0,0 @@
[package]
name = "pwasm-alloc"
version = "0.1.0"
authors = ["Nikolay Volf <nikvolf@gmail.com>"]
license = "MIT/Apache-2.0"
readme = "README.md"
repository = "https://github.com/paritytech/pwasm-std"
homepage = "https://github.com/paritytech/pwasm-std"
documentation = "https://paritytech.github.io/pwasm-std/pwasm_std/"
description = "Parity WebAssembly standard library internal allocator"
keywords = ["wasm", "parity", "webassembly", "blockchain"]
categories = ["no-std", "embedded"]
build = "build.rs"
[dependencies]
pwasm-libc = { path = "../pwasm-libc", version = "0.1" }
[build-dependencies]
rustc_version = "0.2"
[features]
strict = []
nightly = []
-25
View File
@@ -1,25 +0,0 @@
= Pwasm-alloc
Parity WASM contracts standard library libc bindings.
See https://paritytech.github.io/pwasm-std/pwasm_alloc/ for the documentation.
== License
`pwasm_alloc` is primarily distributed under the terms of both the MIT
license and the Apache License (Version 2.0), at your choice.
See LICENSE-APACHE, and LICENSE-MIT for details.
.Summary
[source, toml]
----
include::Cargo.toml[lines=2..5]
----
.Description
----
include::src/lib.rs[tag=description]
----
-14
View File
@@ -1,14 +0,0 @@
//! Set a nightly feature
extern crate rustc_version;
use rustc_version::{version, version_meta, Channel};
fn main() {
// Assert we haven't travelled back in time
assert!(version().unwrap().major >= 1);
// Set cfg flags depending on release channel
if let Channel::Nightly = version_meta().unwrap().channel {
println!("cargo:rustc-cfg=feature=\"nightly\"");
}
}
-34
View File
@@ -1,34 +0,0 @@
#![warn(missing_docs)]
#![cfg_attr(feature = "strict", deny(warnings))]
#![no_std]
#![crate_type = "rlib"]
// tag::description[]
//! Custom allocator crate for wasm
// end::description[]
/// Wasm allocator
pub struct WasmAllocator;
#[cfg(feature = "nightly")]
#[global_allocator]
static ALLOCATOR: WasmAllocator = WasmAllocator;
#[cfg(feature = "nightly")]
mod __impl {
extern crate pwasm_libc;
use core::alloc::{GlobalAlloc, Layout};
use super::WasmAllocator;
unsafe impl GlobalAlloc for WasmAllocator {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
pwasm_libc::malloc(layout.size()) as *mut u8
}
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
pwasm_libc::free(ptr as *mut u8)
}
}
}
-15
View File
@@ -1,15 +0,0 @@
[package]
name = "pwasm-libc"
version = "0.1.0"
authors = ["Sergey Pepyakin <s.pepyakin@gmail.com>"]
license = "MIT/Apache-2.0"
readme = "README.md"
repository = "https://github.com/paritytech/pwasm-std"
homepage = "https://github.com/paritytech/pwasm-std"
documentation = "https://paritytech.github.io/pwasm-std/pwasm_std/"
description = "Parity WebAssembly standard library libc bindings"
keywords = ["wasm", "parity", "webassembly", "blockchain"]
categories = ["no-std", "embedded"]
[features]
strict = []
-24
View File
@@ -1,24 +0,0 @@
= Pwasm-libc
Parity WASM contracts standard library libc bindings
https://paritytech.github.io/pwasm-std/pwasm_libc/[Documentation]
== License
`pwasm-libc` is primarily distributed under the terms of both the MIT
license and the Apache License (Version 2.0), at your choice.
See LICENSE-APACHE, and LICENSE-MIT for details.
.Summary
[source, toml]
----
include::Cargo.toml[lines=2..5]
----
.Description
----
include::src/lib.rs[tag=description]
----
-55
View File
@@ -1,55 +0,0 @@
#![warn(missing_docs)]
#![cfg_attr(feature = "strict", deny(warnings))]
#![no_std]
// tag::description[]
//! libc externs crate
// end::description[]
extern "C" {
fn ext_memcpy(dest: *mut u8, src: *const u8, n: usize) -> *mut u8;
fn ext_memmove(dest: *mut u8, src: *const u8, n: usize) -> *mut u8;
fn ext_memset(dest: *mut u8, c: i32, n: usize) -> *mut u8;
fn ext_memcmp(s1: *const u8, s2: *const u8, n: usize) -> i32;
fn ext_malloc(size: usize) -> *mut u8;
fn ext_free(ptr: *mut u8);
}
// Declaring these function here prevents Emscripten from including it's own verisons
// into final binary.
/// memcpy extern
#[no_mangle]
pub unsafe extern "C" fn memcpy(dest: *mut u8, src: *const u8, n: usize) -> *mut u8 {
ext_memcpy(dest, src, n)
}
/// memcmp extern
#[no_mangle]
pub unsafe extern "C" fn memcmp(s1: *const u8, s2: *const u8, n: usize) -> i32 {
ext_memcmp(s1, s2, n)
}
/// memmove extern
#[no_mangle]
pub unsafe extern "C" fn memmove(dest: *mut u8, src: *const u8, n: usize) -> *mut u8 {
ext_memmove(dest, src, n)
}
/// memset extern
#[no_mangle]
pub unsafe extern "C" fn memset(dest: *mut u8, c: i32, n: usize) -> *mut u8 {
ext_memset(dest, c, n)
}
/// malloc extern
#[no_mangle]
pub unsafe extern "C" fn malloc(size: usize) -> *mut u8 {
ext_malloc(size)
}
/// free extern
#[no_mangle]
pub unsafe extern "C" fn free(ptr: *mut u8) {
ext_free(ptr);
}