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
d5a6503842
commit
47f0443397
@ -32,21 +32,30 @@ pub unsafe fn allocate(elem_count: usize, elem_ty: usize) -> usize {
|
||||
allocated_mem
|
||||
}
|
||||
|
||||
macro_rules! alloc {
|
||||
($ty:ty, $elem_count:ident) => {{
|
||||
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 layout
|
||||
match elem_ty {
|
||||
0 => Vec::<u8>::with_capacity(elem_count).as_ptr() as usize, // for booleans
|
||||
1 => Vec::<u8>::with_capacity(elem_count).as_ptr() as usize,
|
||||
2 => Vec::<u16>::with_capacity(elem_count).as_ptr() as usize,
|
||||
3 => Vec::<u32>::with_capacity(elem_count).as_ptr() as usize,
|
||||
4 => Vec::<u64>::with_capacity(elem_count).as_ptr() as usize,
|
||||
5 => Vec::<i8>::with_capacity(elem_count).as_ptr() as usize,
|
||||
6 => Vec::<i16>::with_capacity(elem_count).as_ptr() as usize,
|
||||
7 => Vec::<i32>::with_capacity(elem_count).as_ptr() as usize,
|
||||
8 => Vec::<i64>::with_capacity(elem_count).as_ptr() as usize,
|
||||
9 => Vec::<f32>::with_capacity(elem_count).as_ptr() as usize,
|
||||
10 => Vec::<f64>::with_capacity(elem_count).as_ptr() as usize,
|
||||
_ => Vec::<u8>::with_capacity(0).as_ptr() as usize, // it'll allocate 0 bytes
|
||||
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),
|
||||
_ => alloc!(u8, 0), // it'll allocate 0 bytes
|
||||
}
|
||||
}
|
||||
|
@ -122,7 +122,8 @@ pub(crate) fn generate_vector_deserializer(
|
||||
}
|
||||
ParsedType::Utf8Str(_) | ParsedType::Utf8String(_) => {
|
||||
quote! {
|
||||
let mut arg: Vec<u32> = Vec::from_raw_parts(offset as _, (2 * size) as _, (2 * size) as _);
|
||||
let vec_passing_size = 2;
|
||||
let mut arg: Vec<u32> = Vec::from_raw_parts(offset as _, (vec_passing_size * size) as _, (vec_passing_size * size) as _);
|
||||
let mut arg = arg.into_iter();
|
||||
let mut result = Vec::with_capacity(arg.len() / 2);
|
||||
|
||||
@ -145,7 +146,8 @@ pub(crate) fn generate_vector_deserializer(
|
||||
quote! {
|
||||
#inner_vector_deserializer
|
||||
|
||||
let mut arg: Vec<u32> = Vec::from_raw_parts(offset as _, (2 * size) as _, (2 * size) as _);
|
||||
let vec_passing_size = 2;
|
||||
let mut arg: Vec<u32> = Vec::from_raw_parts(offset as _, (vec_passing_size * size) as _, (vec_passing_size * size) as _);
|
||||
let mut result = Vec::with_capacity(arg.len());
|
||||
|
||||
let mut arg = arg.into_iter();
|
||||
|
@ -257,7 +257,7 @@ impl FieldValuesBuilder {
|
||||
};
|
||||
};
|
||||
|
||||
self.value_id += 2 * 4;
|
||||
self.value_id += 2 * std::mem::size_of::<u32>();
|
||||
|
||||
result
|
||||
}
|
||||
@ -292,7 +292,7 @@ impl FieldValuesBuilder {
|
||||
let #field = unsafe { #generated_der_ident(offset as _, size as _) };
|
||||
};
|
||||
|
||||
self.value_id += 2 * 4;
|
||||
self.value_id += 2 * std::mem::size_of::<u32>();
|
||||
|
||||
result
|
||||
}
|
||||
|
@ -22,8 +22,9 @@ pub unsafe fn __fce_generated_wrapper_func_inner_arrays_1(arg_0: u32, arg_1: u32
|
||||
) -> Vec<u8> {
|
||||
Vec::from_raw_parts(offset as _, size as _, size as _)
|
||||
}
|
||||
let vec_passing_size = 2;
|
||||
let mut arg: Vec<u32> =
|
||||
Vec::from_raw_parts(offset as _, (2 * size) as _, (2 * size) as _);
|
||||
Vec::from_raw_parts(offset as _, (vec_passing_size * size) as _, (vec_passing_size * size) as _);
|
||||
let mut result = Vec::with_capacity(arg.len());
|
||||
let mut arg = arg.into_iter();
|
||||
while let Some(offset) = arg.next() {
|
||||
@ -36,8 +37,9 @@ pub unsafe fn __fce_generated_wrapper_func_inner_arrays_1(arg_0: u32, arg_1: u32
|
||||
}
|
||||
result
|
||||
}
|
||||
let vec_passing_size = 2;
|
||||
let mut arg: Vec<u32> =
|
||||
Vec::from_raw_parts(offset as _, (2 * size) as _, (2 * size) as _);
|
||||
Vec::from_raw_parts(offset as _, (vec_passing_size * size) as _, (vec_passing_size * size) as _);
|
||||
let mut result = Vec::with_capacity(arg.len());
|
||||
let mut arg = arg.into_iter();
|
||||
while let Some(offset) = arg.next() {
|
||||
@ -48,7 +50,8 @@ pub unsafe fn __fce_generated_wrapper_func_inner_arrays_1(arg_0: u32, arg_1: u32
|
||||
}
|
||||
result
|
||||
}
|
||||
let mut arg: Vec<u32> = Vec::from_raw_parts(offset as _, (2 * size) as _, (2 * size) as _);
|
||||
let vec_passing_size = 2;
|
||||
let mut arg: Vec<u32> = Vec::from_raw_parts(offset as _, (vec_passing_size * size) as _, (vec_passing_size * size) as _);
|
||||
let mut result = Vec::with_capacity(arg.len());
|
||||
let mut arg = arg.into_iter();
|
||||
while let Some(offset) = arg.next() {
|
||||
|
@ -9,8 +9,9 @@ pub fn test_array_refs(arg: &Vec<Vec<String>>) -> &Vec<Vec<Vec<Vec<String>>>> {
|
||||
pub unsafe fn __fce_generated_wrapper_func_test_array_refs(arg_0: u32, arg_1: u32) {
|
||||
unsafe fn __fce_generated_vec_deserializer_0(offset: u32, size: u32) -> Vec<Vec<String>> {
|
||||
unsafe fn __fce_generated_vec_deserializer_0_String(offset: u32, size: u32) -> Vec<String> {
|
||||
let vec_passing_size = 2;
|
||||
let mut arg: Vec<u32> =
|
||||
Vec::from_raw_parts(offset as _, (2 * size) as _, (2 * size) as _);
|
||||
Vec::from_raw_parts(offset as _, (vec_passing_size * size) as _, (vec_passing_size * size) as _);
|
||||
let mut arg = arg.into_iter();
|
||||
let mut result = Vec::with_capacity(arg.len() / 2);
|
||||
while let Some(offset) = arg.next() {
|
||||
@ -20,7 +21,8 @@ pub unsafe fn __fce_generated_wrapper_func_test_array_refs(arg_0: u32, arg_1: u3
|
||||
}
|
||||
result
|
||||
}
|
||||
let mut arg: Vec<u32> = Vec::from_raw_parts(offset as _, (2 * size) as _, (2 * size) as _);
|
||||
let vec_passing_size = 2;
|
||||
let mut arg: Vec<u32> = Vec::from_raw_parts(offset as _, (vec_passing_size * size) as _, (vec_passing_size * size) as _);
|
||||
let mut result = Vec::with_capacity(arg.len());
|
||||
let mut arg = arg.into_iter();
|
||||
while let Some(offset) = arg.next() {
|
||||
|
@ -161,8 +161,9 @@ impl CallParameters {
|
||||
}
|
||||
result
|
||||
}
|
||||
let vec_passing_size = 2;
|
||||
let mut arg: Vec<u32> =
|
||||
Vec::from_raw_parts(offset as _, (2 * size) as _, (2 * size) as _);
|
||||
Vec::from_raw_parts(offset as _, (vec_passing_size * size) as _, (vec_passing_size * size) as _);
|
||||
let mut result = Vec::with_capacity(arg.len());
|
||||
let mut arg = arg.into_iter();
|
||||
while let Some(offset) = arg.next() {
|
||||
|
@ -31,8 +31,9 @@ pub unsafe fn __fce_generated_wrapper_func_inner_arrays_2(arg_0: u32, arg_1: u32
|
||||
}
|
||||
result
|
||||
}
|
||||
let vec_passing_size = 2;
|
||||
let mut arg: Vec<u32> =
|
||||
Vec::from_raw_parts(offset as _, (2 * size) as _, (2 * size) as _);
|
||||
Vec::from_raw_parts(offset as _, (vec_passing_size * size) as _, (vec_passing_size * size) as _);
|
||||
let mut result = Vec::with_capacity(arg.len());
|
||||
let mut arg = arg.into_iter();
|
||||
while let Some(offset) = arg.next() {
|
||||
@ -42,8 +43,9 @@ pub unsafe fn __fce_generated_wrapper_func_inner_arrays_2(arg_0: u32, arg_1: u32
|
||||
}
|
||||
result
|
||||
}
|
||||
let vec_passing_size = 2;
|
||||
let mut arg: Vec<u32> =
|
||||
Vec::from_raw_parts(offset as _, (2 * size) as _, (2 * size) as _);
|
||||
Vec::from_raw_parts(offset as _, (vec_passing_size * size) as _, (vec_passing_size * size) as _);
|
||||
let mut result = Vec::with_capacity(arg.len());
|
||||
let mut arg = arg.into_iter();
|
||||
while let Some(offset) = arg.next() {
|
||||
@ -56,7 +58,8 @@ pub unsafe fn __fce_generated_wrapper_func_inner_arrays_2(arg_0: u32, arg_1: u32
|
||||
}
|
||||
result
|
||||
}
|
||||
let mut arg: Vec<u32> = Vec::from_raw_parts(offset as _, (2 * size) as _, (2 * size) as _);
|
||||
let vec_passing_size = 2;
|
||||
let mut arg: Vec<u32> = Vec::from_raw_parts(offset as _, (vec_passing_size * size) as _, (vec_passing_size * size) as _);
|
||||
let mut result = Vec::with_capacity(arg.len());
|
||||
let mut arg = arg.into_iter();
|
||||
while let Some(offset) = arg.next() {
|
||||
|
Loading…
Reference in New Issue
Block a user