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

Commit 36893c7

Browse files
authored
Remove redundant code and merge rest into rt-std (#735)
* Remove redundant code and merge rest into rt-std * Update lib.rs
1 parent 00e5f23 commit 36893c7

File tree

16 files changed

+27
-285
lines changed

16 files changed

+27
-285
lines changed

Cargo.lock

Lines changed: 0 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ exclude = [
5757
"node/runtime/wasm",
5858
"core/executor/wasm",
5959
"pwasm-alloc",
60-
"pwasm-libc",
6160
"core/test-runtime/wasm",
6261
]
6362

core/executor/src/wasm_executor.rs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
//! Rust implementation of Substrate contracts.
1818
19-
use std::cmp::Ordering;
2019
use std::collections::HashMap;
2120

2221
use wasmi::{
@@ -161,33 +160,6 @@ impl_function_executor!(this: FunctionExecutor<'e, E>,
161160
println!("{}", number);
162161
Ok(())
163162
},
164-
ext_memcmp(s1: *const u8, s2: *const u8, n: usize) -> i32 => {
165-
let sl1 = this.memory.get(s1, n as usize).map_err(|_| UserError("Invalid attempt to read from memory in first arg of ext_memcmp"))?;
166-
let sl2 = this.memory.get(s2, n as usize).map_err(|_| UserError("Invalid attempt to read from memory in second arg of ext_memcmp"))?;
167-
Ok(match sl1.cmp(&sl2) {
168-
Ordering::Greater => 1,
169-
Ordering::Less => -1,
170-
Ordering::Equal => 0,
171-
})
172-
},
173-
ext_memcpy(dest: *mut u8, src: *const u8, count: usize) -> *mut u8 => {
174-
this.memory.copy_nonoverlapping(src as usize, dest as usize, count as usize)
175-
.map_err(|_| UserError("Invalid attempt to copy_nonoverlapping in ext_memcpy"))?;
176-
debug_trace!(target: "sr-io", "memcpy {} from {}, {} bytes", dest, src, count);
177-
Ok(dest)
178-
},
179-
ext_memmove(dest: *mut u8, src: *const u8, count: usize) -> *mut u8 => {
180-
this.memory.copy(src as usize, dest as usize, count as usize)
181-
.map_err(|_| UserError("Invalid attempt to copy in ext_memmove"))?;
182-
debug_trace!(target: "sr-io", "memmove {} from {}, {} bytes", dest, src, count);
183-
Ok(dest)
184-
},
185-
ext_memset(dest: *mut u8, val: u32, count: usize) -> *mut u8 => {
186-
debug_trace!(target: "sr-io", "memset {} with {}, {} bytes", dest, val, count);
187-
this.memory.clear(dest as usize, val as u8, count as usize)
188-
.map_err(|_| UserError("Invalid attempt to clear in ext_memset"))?;
189-
Ok(dest)
190-
},
191163
ext_malloc(size: usize) -> *mut u8 => {
192164
let r = this.heap.allocate(size);
193165
debug_trace!(target: "sr-io", "malloc {} bytes at {}", size, r);

core/executor/wasm/Cargo.lock

Lines changed: 0 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/sr-std/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ build = "build.rs"
77
[build-dependencies]
88
rustc_version = "0.2"
99

10-
[dependencies]
11-
pwasm-alloc = { path = "../../pwasm-alloc" }
12-
pwasm-libc = { path = "../../pwasm-libc" }
13-
1410
[features]
1511
default = ["std"]
1612
std = []

core/sr-std/without_std.rs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,33 @@
1616

1717
#[cfg(feature = "nightly")]
1818
extern crate alloc;
19-
#[cfg(feature = "nightly")]
20-
extern crate pwasm_libc;
21-
#[cfg(feature = "nightly")]
22-
extern crate pwasm_alloc;
19+
20+
extern "C" {
21+
fn ext_malloc(size: usize) -> *mut u8;
22+
fn ext_free(ptr: *mut u8);
23+
}
24+
25+
/// Wasm allocator
26+
pub struct WasmAllocator;
27+
28+
#[global_allocator]
29+
static ALLOCATOR: WasmAllocator = WasmAllocator;
30+
31+
mod __impl {
32+
use core::alloc::{GlobalAlloc, Layout};
33+
34+
use super::WasmAllocator;
35+
36+
unsafe impl GlobalAlloc for WasmAllocator {
37+
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
38+
super::ext_malloc(layout.size()) as *mut u8
39+
}
40+
41+
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
42+
super::ext_free(ptr as *mut u8)
43+
}
44+
}
45+
}
2346

2447
pub use alloc::boxed;
2548
pub use alloc::rc;

core/test-runtime/wasm/Cargo.lock

Lines changed: 0 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/packages/substrate.adoc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ include::../../core/primitives/README.adoc[]
3131

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

34-
include::../../pwasm-libc/README.adoc[]
35-
3634
include::../../core/rpc/README.adoc[]
3735

3836
include::../../core/rpc-servers/README.adoc[]

node/runtime/wasm/Cargo.lock

Lines changed: 0 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pwasm-alloc/Cargo.toml

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)