mirror of https://github.com/status-im/evmc.git
rust: pass ExecutionContext mutable so it can actually be used with host functions
Co-authored-by: Jake Lang <jak3lang@gmail.com>
This commit is contained in:
parent
892474a259
commit
a17fd0ed6e
|
@ -22,7 +22,7 @@ impl EvmcVm for FooVM {
|
|||
_revision: evmc_sys::evmc_revision,
|
||||
_code: &[u8],
|
||||
_message: &ExecutionMessage,
|
||||
_context: &ExecutionContext,
|
||||
_context: &mut ExecutionContext,
|
||||
) -> ExecutionResult {
|
||||
ExecutionResult::success(1337, None)
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
//! ExampleVM {}
|
||||
//! }
|
||||
//!
|
||||
//! fn execute(&self, revision: evmc_vm::ffi::evmc_revision, code: &[u8], message: &evmc_vm::ExecutionMessage, context: &evmc_vm::ExecutionContext) -> evmc_vm::ExecutionResult {
|
||||
//! fn execute(&self, revision: evmc_vm::ffi::evmc_revision, code: &[u8], message: &evmc_vm::ExecutionMessage, context: &mut evmc_vm::ExecutionContext) -> evmc_vm::ExecutionResult {
|
||||
//! evmc_vm::ExecutionResult::success(1337, None)
|
||||
//! }
|
||||
//! }
|
||||
|
@ -346,10 +346,6 @@ fn build_execute_fn(names: &VMNameSet) -> proc_macro2::TokenStream {
|
|||
msg.as_ref().expect("EVMC message is null").into()
|
||||
};
|
||||
|
||||
let execution_context = unsafe {
|
||||
::evmc_vm::ExecutionContext::new(context.as_mut().expect("EVMC context is null"))
|
||||
};
|
||||
|
||||
let empty_code = [0u8;0];
|
||||
let code_ref: &[u8] = if code.is_null() {
|
||||
assert_eq!(code_size, 0);
|
||||
|
@ -365,7 +361,10 @@ fn build_execute_fn(names: &VMNameSet) -> proc_macro2::TokenStream {
|
|||
};
|
||||
|
||||
let result = ::std::panic::catch_unwind(|| {
|
||||
container.execute(revision, code_ref, &execution_message, &execution_context)
|
||||
let mut execution_context = unsafe {
|
||||
::evmc_vm::ExecutionContext::new(context.as_mut().expect("EVMC context is null"))
|
||||
};
|
||||
container.execute(revision, code_ref, &execution_message, &mut execution_context)
|
||||
});
|
||||
|
||||
let result = if result.is_err() {
|
||||
|
|
|
@ -62,7 +62,7 @@ mod tests {
|
|||
_revision: evmc_sys::evmc_revision,
|
||||
_code: &[u8],
|
||||
_message: &ExecutionMessage,
|
||||
_context: &ExecutionContext,
|
||||
_context: &mut ExecutionContext,
|
||||
) -> ExecutionResult {
|
||||
ExecutionResult::failure()
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ mod tests {
|
|||
emit_log: None,
|
||||
};
|
||||
let mut backing_context = ::evmc_sys::evmc_context { host: &host };
|
||||
let context = ExecutionContext::new(&mut backing_context);
|
||||
let mut context = ExecutionContext::new(&mut backing_context);
|
||||
|
||||
let container = EvmcContainer::<TestVm>::new(instance);
|
||||
assert_eq!(
|
||||
|
@ -135,7 +135,7 @@ mod tests {
|
|||
evmc_sys::evmc_revision::EVMC_PETERSBURG,
|
||||
&code,
|
||||
&message,
|
||||
&context
|
||||
&mut context
|
||||
)
|
||||
.get_status_code(),
|
||||
::evmc_sys::evmc_status_code::EVMC_FAILURE
|
||||
|
@ -150,7 +150,7 @@ mod tests {
|
|||
evmc_sys::evmc_revision::EVMC_PETERSBURG,
|
||||
&code,
|
||||
&message,
|
||||
&context
|
||||
&mut context
|
||||
)
|
||||
.get_status_code(),
|
||||
::evmc_sys::evmc_status_code::EVMC_FAILURE
|
||||
|
|
|
@ -23,7 +23,7 @@ pub trait EvmcVm {
|
|||
revision: ffi::evmc_revision,
|
||||
code: &[u8],
|
||||
message: &ExecutionMessage,
|
||||
context: &ExecutionContext,
|
||||
context: &mut ExecutionContext,
|
||||
) -> ExecutionResult;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ impl EvmcVm for ExampleRustVM {
|
|||
_revision: evmc_sys::evmc_revision,
|
||||
_code: &[u8],
|
||||
message: &ExecutionMessage,
|
||||
_context: &ExecutionContext,
|
||||
_context: &mut ExecutionContext,
|
||||
) -> ExecutionResult {
|
||||
let is_create = message.kind() == evmc_sys::evmc_call_kind::EVMC_CREATE;
|
||||
|
||||
|
|
Loading…
Reference in New Issue