cargo fmt all the things

This commit is contained in:
vms 2020-06-02 01:02:22 +03:00
parent 541a19ff29
commit 880bb6f87e
11 changed files with 45 additions and 55 deletions

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#![allow(clippy::missing_safety_doc)]
mod mem;
mod result;

View File

@ -14,7 +14,6 @@
* limitations under the License.
*/
use std::alloc::{alloc as global_alloc, dealloc as global_dealloc, Layout};
use std::ptr::NonNull;

View File

@ -14,7 +14,6 @@
* limitations under the License.
*/
use std::sync::atomic::AtomicUsize;
pub static mut RESULT_PTR: AtomicUsize = AtomicUsize::new(0);

View File

@ -14,6 +14,8 @@
* limitations under the License.
*/
#![allow(clippy::missing_safety_doc)]
mod mem;
mod result;
@ -21,17 +23,14 @@ use crate::result::{RESULT_PTR, RESULT_SIZE};
#[no_mangle]
pub unsafe fn put(file_content_ptr: *mut u8, file_content_size: usize) {
let file_content = String::from_raw_parts(
file_content_ptr,
file_content_size,
file_content_size
);
let file_content =
String::from_raw_parts(file_content_ptr, file_content_size, file_content_size);
let msg = format!("from Wasm node: file content is {}\n", file_content);
log_utf8_string(msg.as_ptr() as _, msg.len() as _);
let cmd = format!("put {}", file_content);
ipfs(file_content.as_ptr() as _, file_content.len() as _);
ipfs(cmd.as_ptr() as _, cmd.len() as _);
let result = "Hello from IPFS node, take your hash".to_string();
@ -42,11 +41,7 @@ pub unsafe fn put(file_content_ptr: *mut u8, file_content_size: usize) {
#[no_mangle]
pub unsafe fn get(hash_ptr: *mut u8, hash_size: usize) {
let hash = String::from_raw_parts(
hash_ptr,
hash_size,
hash_size
);
let hash = String::from_raw_parts(hash_ptr, hash_size, hash_size);
let msg = format!("from Wasm node: file content is {}\n", hash);
log_utf8_string(msg.as_ptr() as _, msg.len() as _);

View File

@ -14,9 +14,8 @@
* limitations under the License.
*/
use std::alloc::{alloc as global_alloc, dealloc as global_dealloc, Layout};
use crate::log_utf8_string;
use std::alloc::{alloc as global_alloc, dealloc as global_dealloc, Layout};
use std::ptr::NonNull;
/// Allocates memory area of specified size and returns its address.

View File

@ -14,16 +14,15 @@
* limitations under the License.
*/
use std::sync::atomic::AtomicUsize;
use crate::log_utf8_string;
use std::sync::atomic::AtomicUsize;
pub static mut RESULT_PTR: AtomicUsize = AtomicUsize::new(0);
pub static mut RESULT_SIZE: AtomicUsize = AtomicUsize::new(0);
#[no_mangle]
pub unsafe fn get_result_ptr() -> usize {
let msg = format!("wasm_node: calling get_result_ptr\n");
let msg = "wasm_node: calling get_result_ptr\n";
log_utf8_string(msg.as_ptr() as _, msg.len() as _);
*RESULT_PTR.get_mut()
@ -31,7 +30,7 @@ pub unsafe fn get_result_ptr() -> usize {
#[no_mangle]
pub unsafe fn get_result_size() -> usize {
let msg = format!("wasm_node: calling get_result_size\n");
let msg = "wasm_node: calling get_result_size\n";
log_utf8_string(msg.as_ptr() as _, msg.len() as _);
*RESULT_SIZE.get_mut()

View File

@ -13,19 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#![allow(clippy::missing_safety_doc)]
mod mem;
mod result;
use crate::result::{RESULT_PTR, RESULT_SIZE};
// use crate::result::{RESULT_PTR, RESULT_SIZE};
#[no_mangle]
pub unsafe fn invoke(file_content_ptr: *mut u8, file_content_size: usize) {
let file_content = String::from_raw_parts(
file_content_ptr,
file_content_size,
file_content_size,
);
let file_content =
String::from_raw_parts(file_content_ptr, file_content_size, file_content_size);
let msg = format!("from Wasm rpc: file_content is {}\n", file_content);
log_utf8_string(msg.as_ptr() as _, msg.len() as _);
@ -54,6 +52,7 @@ extern "C" {
/// Put a file to ipfs, returns ipfs hash of the file.
fn put(ptr: i32, size: i32);
#[allow(unused)]
/// Get file from ipfs by hash.
fn get(ptr: i32, size: i32);
}

View File

@ -14,9 +14,8 @@
* limitations under the License.
*/
use std::alloc::{alloc as global_alloc, dealloc as global_dealloc, Layout};
use crate::log_utf8_string;
use std::alloc::{alloc as global_alloc, dealloc as global_dealloc, Layout};
use std::ptr::NonNull;
/// Allocates memory area of specified size and returns its address.

View File

@ -14,16 +14,15 @@
* limitations under the License.
*/
use std::sync::atomic::AtomicUsize;
use crate::log_utf8_string;
use std::sync::atomic::AtomicUsize;
pub static mut RESULT_PTR: AtomicUsize = AtomicUsize::new(0);
pub static mut RESULT_SIZE: AtomicUsize = AtomicUsize::new(0);
#[no_mangle]
pub unsafe fn get_result_ptr() -> usize {
let msg = format!("wasm_rpc: calling get_result_ptr\n");
let msg = "wasm_rpc: calling get_result_ptr\n";
log_utf8_string(msg.as_ptr() as _, msg.len() as _);
*RESULT_PTR.get_mut()
@ -31,7 +30,7 @@ pub unsafe fn get_result_ptr() -> usize {
#[no_mangle]
pub unsafe fn get_result_size() -> usize {
let msg = format!("wasm_rpc: calling get_result_size\n");
let msg = "wasm_rpc: calling get_result_size\n";
log_utf8_string(msg.as_ptr() as _, msg.len() as _);
*RESULT_SIZE.get_mut()

View File

@ -30,6 +30,7 @@ enum WITFunctionInner {
outputs: Vec<InterfaceType>,
},
Import {
// TODO: use WITInstance here instead of WITModule
wit_module: Arc<WITModule>,
func_name: String,
inputs: Vec<InterfaceType>,

View File

@ -39,12 +39,13 @@ use wasmer_runtime_core::import::Namespace;
const WIT_SECTION_NAME: &str = "interface-types";
type WITInterpreter =
Interpreter<WITInstance, WITExport, WITFunction, WITMemory, WITMemoryView<'static>>;
type WITModuleFunc = (WITInterpreter, Vec<InterfaceType>, Vec<InterfaceType>);
pub struct WITModule {
#[allow(unused)]
instance: WasmerInstance,
wit_instance: Arc<WITInstance>,
funcs: HashMap<String, (WITInterpreter, Vec<InterfaceType>, Vec<InterfaceType>)>,
funcs: HashMap<String, WITModuleFunc>,
}
impl WITModule {
@ -128,10 +129,7 @@ impl WITModule {
fn extract_wit_exports(
interfaces: &Interfaces,
) -> Result<
HashMap<String, (WITInterpreter, Vec<InterfaceType>, Vec<InterfaceType>)>,
WITFCEError,
> {
) -> Result<HashMap<String, WITModuleFunc>, WITFCEError> {
let exports_type_to_names = interfaces
.exports
.iter()
@ -254,29 +252,31 @@ impl WITModule {
let interpreter: WITInterpreter = instructions.try_into().unwrap();
let wit_instance = wit_instance.clone();
let inner_import = Box::new(move |_: &mut Ctx, inputs: &[Value]| -> Vec<Value> {
// copy here to because otherwise wit_instance will be consumed by the closure
let wit_instance_callable = wit_instance.clone();
let converted_inputs = inputs.iter().map(wval_to_ival).collect::<Vec<_>>();
unsafe {
// error here will be propagated by the special error instruction
let _ = interpreter.run(
&converted_inputs,
Arc::make_mut(&mut wit_instance_callable.assume_init()),
);
}
let wit_inner_import =
Box::new(move |_: &mut Ctx, inputs: &[Value]| -> Vec<Value> {
// copy here to because otherwise wit_instance will be consumed by the closure
let wit_instance_callable = wit_instance.clone();
let converted_inputs = inputs.iter().map(wval_to_ival).collect::<Vec<_>>();
unsafe {
// error here will be propagated by the special error instruction
let _ = interpreter.run(
&converted_inputs,
Arc::make_mut(&mut wit_instance_callable.assume_init()),
);
}
// wit import functions should only change the stack state -
// the result will be returned by an export function
vec![]
});
// wit import functions should only change the stack state -
// the result will be returned by an export function
vec![]
});
let linking_import = dyn_func_from_imports(inputs.clone(), inner_import);
let wit_import = dyn_func_from_imports(inputs.clone(), wit_inner_import);
let mut n = Namespace::new();
n.insert(func_name.clone(), linking_import);
// TODO: refactor this
let mut module_namespace = Namespace::new();
module_namespace.insert(func_name.clone(), wit_import);
import_namespaces.insert(namespace, n);
import_namespaces.insert(namespace, module_namespace);
} else {
// TODO: change error type
return Err(WITFCEError::WasmerResolveError(format!(