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 * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#![allow(clippy::missing_safety_doc)]
mod mem; mod mem;
mod result; mod result;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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