mirror of
https://github.com/fluencelabs/marine-rs-sdk-test
synced 2024-12-04 23:30:18 +00:00
some minor improvements
This commit is contained in:
parent
55cfb1e844
commit
ea5baec462
@ -17,7 +17,6 @@
|
||||
use super::log;
|
||||
|
||||
use std::alloc::alloc as global_alloc;
|
||||
use std::alloc::dealloc as global_dealloc;
|
||||
use std::alloc::Layout;
|
||||
|
||||
/// Allocates memory area of specified size and returns its address.
|
||||
@ -35,19 +34,3 @@ pub unsafe fn allocate(size: usize) -> usize {
|
||||
|
||||
global_alloc(layout) as _
|
||||
}
|
||||
|
||||
/// Deallocates memory area for provided memory pointer and size.
|
||||
/// Does nothing if supplied size is too long.
|
||||
#[no_mangle]
|
||||
pub unsafe fn deallocate(ptr: *mut u8, size: usize) {
|
||||
let layout = match Layout::from_size_align(size, std::mem::align_of::<u8>()) {
|
||||
Ok(layout) => layout,
|
||||
// in this case a err may occur only in a case of too long allocated size,
|
||||
// so just done nothing
|
||||
Err(_) => return,
|
||||
};
|
||||
|
||||
log(format!("sdk.deallocate: {:?} {}\n", ptr, size));
|
||||
|
||||
global_dealloc(ptr, layout);
|
||||
}
|
||||
|
@ -39,7 +39,6 @@ mod result;
|
||||
mod sdk_version_embedder;
|
||||
|
||||
pub use export_allocator::allocate;
|
||||
pub use export_allocator::deallocate;
|
||||
|
||||
#[cfg(feature = "logger")]
|
||||
pub use logger::WasmLoggerBuilder;
|
||||
|
@ -88,8 +88,8 @@ pub use fluence_sdk_main::WasmLoggerBuilder;
|
||||
#[cfg(feature = "logger")]
|
||||
pub use fluence_sdk_main::TargetMap;
|
||||
|
||||
pub use mounted_binary::Result as MountedBinaryResult;
|
||||
pub use mounted_binary::StringResult as MountedBinaryStringResult;
|
||||
pub use mounted_binary::MountedBinaryResult;
|
||||
pub use mounted_binary::MountedBinaryStringResult;
|
||||
pub use mounted_binary::SUCCESS_CODE as BINARY_SUCCESS_CODE;
|
||||
|
||||
pub use fluence_sdk_main::module_manifest;
|
||||
|
@ -24,7 +24,7 @@ pub const SUCCESS_CODE: i32 = 0;
|
||||
/// Describes result of calling a CLI service.
|
||||
#[fce]
|
||||
#[derive(Clone, PartialEq, Default, Eq, Debug, Serialize, Deserialize)]
|
||||
pub struct Result {
|
||||
pub struct MountedBinaryResult {
|
||||
/// Return process exit code or host execution error code, where SUCCESS_CODE means success.
|
||||
pub ret_code: i32,
|
||||
|
||||
@ -38,10 +38,10 @@ pub struct Result {
|
||||
pub stderr: Vec<u8>,
|
||||
}
|
||||
|
||||
/// The same as the Result, but stdout and stderr are utf8 strings.
|
||||
/// The same as the MountedBinaryResult, but stdout and stderr are utf8 strings.
|
||||
#[fce]
|
||||
#[derive(Clone, PartialEq, Default, Eq, Debug, Serialize, Deserialize)]
|
||||
pub struct StringResult {
|
||||
pub struct MountedBinaryStringResult {
|
||||
/// Return process exit code or host execution error code, where SUCCESS_CODE means success.
|
||||
pub ret_code: i32,
|
||||
|
||||
@ -55,7 +55,7 @@ pub struct StringResult {
|
||||
pub stderr: String,
|
||||
}
|
||||
|
||||
impl Result {
|
||||
impl MountedBinaryResult {
|
||||
/// Create a new failure MountedBinaryResult from the provided ret_code.
|
||||
pub fn from_error(ret_code: i32, error: impl Into<String>) -> Self {
|
||||
Self {
|
||||
@ -99,11 +99,11 @@ impl Result {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn stringify(&self) -> Option<StringResult> {
|
||||
pub fn stringify(&self) -> Option<MountedBinaryStringResult> {
|
||||
let stdout = String::from_utf8(self.stdout.clone()).ok()?;
|
||||
let stderr = String::from_utf8(self.stderr.clone()).ok()?;
|
||||
|
||||
let string_result = StringResult {
|
||||
let string_result = MountedBinaryStringResult {
|
||||
ret_code: self.ret_code,
|
||||
error: self.error.clone(),
|
||||
stdout,
|
||||
|
Loading…
Reference in New Issue
Block a user