mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 16:57:58 +00:00
Correct implementation of memcmp
This commit is contained in:
@@ -59,5 +59,11 @@ error_chain! {
|
||||
description("runtime failure"),
|
||||
display("Runtime error"),
|
||||
}
|
||||
|
||||
/// Runtime failed.
|
||||
InvalidMemoryReference {
|
||||
description("invalid memory reference"),
|
||||
display("Invalid memory reference"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ extern crate byteorder;
|
||||
extern crate rustc_hex;
|
||||
extern crate native_runtime;
|
||||
extern crate runtime_std;
|
||||
extern crate memcmp;
|
||||
extern crate libc;
|
||||
|
||||
#[macro_use]
|
||||
extern crate error_chain;
|
||||
|
||||
@@ -16,10 +16,11 @@
|
||||
|
||||
//! Rust implementation of Polkadot contracts.
|
||||
|
||||
use libc::{memcmp, c_void};
|
||||
use std::sync::Arc;
|
||||
use std::collections::HashMap;
|
||||
use parity_wasm::{deserialize_buffer, ModuleInstanceInterface, ProgramInstance};
|
||||
use parity_wasm::interpreter::{ItemIndex};
|
||||
use parity_wasm::interpreter::{ItemIndex, DummyUserError};
|
||||
use parity_wasm::RuntimeValue::{I32, I64};
|
||||
use primitives::contract::CallData;
|
||||
use state_machine::{Externalities, CodeExecutor};
|
||||
@@ -96,10 +97,13 @@ impl_function_executor!(this: FunctionExecutor<'e, E>,
|
||||
ext_memcmp(s1: *const u8, s2: *const u8, n: usize) -> i32 => {
|
||||
if let (Ok(sl1), Ok(sl2))
|
||||
= (this.memory.get(s1, n as usize), this.memory.get(s2, n as usize)) {
|
||||
use memcmp::Memcmp;
|
||||
(&sl1).memcmp(&sl2) as i32
|
||||
unsafe {
|
||||
memcmp(sl1.as_ptr() as *const u8 as *const c_void,
|
||||
sl2.as_ptr() as *const u8 as *const c_void,
|
||||
n as usize) as i32
|
||||
}
|
||||
} else {
|
||||
0
|
||||
return Err(DummyUserError.into());
|
||||
}
|
||||
},
|
||||
ext_memcpy(dest: *mut u8, src: *const u8, count: usize) -> *mut u8 => {
|
||||
|
||||
Reference in New Issue
Block a user