mirror of
https://github.com/fluencelabs/marine-rs-sdk-test
synced 2024-12-04 15:20:18 +00:00
pr fixes
This commit is contained in:
parent
766da0bf0f
commit
17115b696a
@ -14,9 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#[cfg(feature = "debug")]
|
||||
use super::log;
|
||||
|
||||
/// Allocates memory area of specified size and type and returns its address.
|
||||
/// The allocated memory region is intended to be use as a Vec.
|
||||
#[no_mangle]
|
||||
@ -27,8 +24,7 @@ pub unsafe fn allocate(elem_count: usize, elem_ty: usize) -> usize {
|
||||
}
|
||||
|
||||
let allocated_mem = allocate_impl(elem_count, elem_ty);
|
||||
#[cfg(feature = "debug")]
|
||||
log(format!(
|
||||
crate::debug_log!(format!(
|
||||
"sdk.allocate: {} {} -> {}\n",
|
||||
elem_count, elem_ty, allocated_mem
|
||||
));
|
||||
@ -36,30 +32,29 @@ pub unsafe fn allocate(elem_count: usize, elem_ty: usize) -> usize {
|
||||
allocated_mem
|
||||
}
|
||||
|
||||
macro_rules! alloc {
|
||||
($ty:ty, $elem_count:expr) => {{
|
||||
let vec = Vec::<$ty>::with_capacity($elem_count);
|
||||
let offset = vec.as_ptr() as usize;
|
||||
std::mem::forget(vec);
|
||||
offset
|
||||
}};
|
||||
}
|
||||
|
||||
fn allocate_impl(elem_count: usize, elem_ty: usize) -> usize {
|
||||
// TODO: handle OOM
|
||||
// Such allocation scheme is needed to deal with Vec layout
|
||||
match elem_ty {
|
||||
0 => alloc!(u8, elem_count), // for booleans
|
||||
1 => alloc!(u8, elem_count),
|
||||
2 => alloc!(u16, elem_count),
|
||||
3 => alloc!(u32, elem_count),
|
||||
4 => alloc!(u64, elem_count),
|
||||
5 => alloc!(i8, elem_count),
|
||||
6 => alloc!(i16, elem_count),
|
||||
7 => alloc!(i32, elem_count),
|
||||
8 => alloc!(i64, elem_count),
|
||||
9 => alloc!(f32, elem_count),
|
||||
10 => alloc!(f64, elem_count),
|
||||
0 => allocate_vec::<u8>(elem_count), // for booleans
|
||||
1 => allocate_vec::<u8>(elem_count),
|
||||
2 => allocate_vec::<u16>(elem_count),
|
||||
3 => allocate_vec::<u32>(elem_count),
|
||||
4 => allocate_vec::<u64>(elem_count),
|
||||
5 => allocate_vec::<i8>(elem_count),
|
||||
6 => allocate_vec::<i16>(elem_count),
|
||||
7 => allocate_vec::<i32>(elem_count),
|
||||
8 => allocate_vec::<i64>(elem_count),
|
||||
9 => allocate_vec::<f32>(elem_count),
|
||||
10 => allocate_vec::<f64>(elem_count),
|
||||
_ => 0,
|
||||
}
|
||||
}
|
||||
|
||||
fn allocate_vec<T>(count: usize) -> usize {
|
||||
// TODO: handle OOM
|
||||
// This allocation scheme with vectors is needed to deal with internal Vec layout
|
||||
let vec = Vec::<T>::with_capacity(count);
|
||||
let offset = vec.as_ptr() as usize;
|
||||
std::mem::forget(vec);
|
||||
|
||||
offset
|
||||
}
|
||||
|
@ -57,12 +57,16 @@ pub use result::add_object_to_release;
|
||||
pub use module_manifest::MANIFEST_SECTION_NAME;
|
||||
pub use sdk_version_embedder::VERSION_SECTION_NAME;
|
||||
|
||||
// logs will be printed only if debug feature is enabled
|
||||
#[cfg(feature = "debug")]
|
||||
#[allow(unused_variables)]
|
||||
pub(crate) fn log<S: AsRef<str>>(msg: S) {
|
||||
let level = log::Level::Info as i32;
|
||||
let target = 0i32;
|
||||
let msg = msg.as_ref();
|
||||
logger::log_utf8_string(level, target, msg.as_ptr() as i32, msg.len() as i32);
|
||||
// these logs will be printed only if debug feature is enabled
|
||||
#[macro_export]
|
||||
macro_rules! debug_log {
|
||||
($msg_generator:expr) => {
|
||||
#[cfg(feature = "debug")]
|
||||
{
|
||||
let level = log::Level::Info as i32;
|
||||
let target = 0i32;
|
||||
let msg = $msg_generator;
|
||||
logger::log_utf8_string(level, target, msg.as_ptr() as i32, msg.len() as i32);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -18,9 +18,6 @@
|
||||
//! by two global variables that contain pointer and size. Will be refactored after multi-value
|
||||
//! support in Wasmer.
|
||||
|
||||
#[cfg(feature = "debug")]
|
||||
use super::log;
|
||||
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use std::cell::RefCell;
|
||||
use std::any::Any;
|
||||
@ -32,8 +29,7 @@ thread_local!(static OBJECTS_TO_RELEASE: RefCell<Vec<Box<dyn Any>>> = RefCell::n
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe fn get_result_ptr() -> usize {
|
||||
#[cfg(feature = "debug")]
|
||||
log(format!(
|
||||
crate::debug_log!(format!(
|
||||
"sdk.get_result_ptr, returns {}\n",
|
||||
*RESULT_PTR.get_mut()
|
||||
));
|
||||
@ -43,8 +39,7 @@ pub unsafe fn get_result_ptr() -> usize {
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe fn get_result_size() -> usize {
|
||||
#[cfg(feature = "debug")]
|
||||
log(format!(
|
||||
crate::debug_log!(format!(
|
||||
"sdk.get_result_size, returns {}\n",
|
||||
*RESULT_SIZE.get_mut()
|
||||
));
|
||||
@ -54,16 +49,14 @@ pub unsafe fn get_result_size() -> usize {
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe fn set_result_ptr(ptr: usize) {
|
||||
#[cfg(feature = "debug")]
|
||||
log(format!("sdk.set_result_ptr: {}\n", ptr));
|
||||
crate::debug_log!(format!("sdk.set_result_ptr: {}\n", ptr));
|
||||
|
||||
*RESULT_PTR.get_mut() = ptr;
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe fn set_result_size(size: usize) {
|
||||
#[cfg(feature = "debug")]
|
||||
log(format!("sdk.set_result_size: {}\n", size));
|
||||
crate::debug_log!(format!("sdk.set_result_size: {}\n", size));
|
||||
|
||||
*RESULT_SIZE.get_mut() = size;
|
||||
}
|
||||
|
@ -27,8 +27,8 @@ pub(crate) struct AstFnSignature {
|
||||
pub visibility: syn::Visibility,
|
||||
pub name: String,
|
||||
pub arguments: Vec<AstFnArgument>,
|
||||
// fce supports only one return value now,
|
||||
// waiting for adding multi-value support in Wasmer.
|
||||
// only one or zero return values are supported now,
|
||||
// waiting for adding multi-value support in Wasmer
|
||||
pub output_type: Option<ParsedType>,
|
||||
}
|
||||
|
||||
@ -39,19 +39,22 @@ pub(crate) struct AstRecordItem {
|
||||
pub original: syn::ItemStruct,
|
||||
}
|
||||
|
||||
#[allow(dead_code)] // at the moment tuple and unit structs aren't supported
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub(crate) enum AstRecordFields {
|
||||
Named(Vec<AstRecordField>),
|
||||
|
||||
// named and unnamed variants have the same inner field types because of it's easy to handle it,
|
||||
// for additional info look at https://github.com/dtolnay/syn/issues/698
|
||||
#[allow(dead_code)] // at the moment tuple and unit structs aren't supported
|
||||
Unnamed(Vec<AstRecordField>),
|
||||
|
||||
#[allow(dead_code)] // at the moment tuple and unit structs aren't supported
|
||||
Unit,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub(crate) struct AstRecordField {
|
||||
// fields of tuple structs haven't got name
|
||||
/// Name of the field. Can be `None` for tuples.
|
||||
pub name: Option<String>,
|
||||
pub ty: ParsedType,
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ pub(crate) fn generate_vector_ser(
|
||||
fluence::internal::add_object_to_release(Box::new(converted_bool_vector));
|
||||
(converted_bool_vector.as_ptr() as _, converted_bool_vector.len() as _)
|
||||
}
|
||||
},
|
||||
}
|
||||
ParsedType::I8(_)
|
||||
| ParsedType::U8(_)
|
||||
| ParsedType::I16(_)
|
||||
|
Loading…
Reference in New Issue
Block a user