mirror of https://github.com/status-im/evmc.git
Merge pull request #401 from ethereum/rust-container
rust: change ownership api in container
This commit is contained in:
commit
d8c2aa2c89
|
@ -301,8 +301,11 @@ fn build_create_fn(names: &VMNameSet) -> proc_macro2::TokenStream {
|
|||
version: unsafe { ::std::ffi::CStr::from_bytes_with_nul_unchecked(#static_version_ident.as_bytes()).as_ptr() as *const i8 },
|
||||
};
|
||||
|
||||
let container = ::evmc_vm::EvmcContainer::<#type_ident>::new(new_instance);
|
||||
|
||||
unsafe {
|
||||
::evmc_vm::EvmcContainer::into_ffi_pointer(Box::new(::evmc_vm::EvmcContainer::<#type_ident>::new(new_instance)))
|
||||
// Release ownership to EVMC.
|
||||
::evmc_vm::EvmcContainer::into_ffi_pointer(container)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -319,6 +322,7 @@ fn build_destroy_fn(names: &VMNameSet) -> proc_macro2::TokenStream {
|
|||
std::process::abort();
|
||||
}
|
||||
unsafe {
|
||||
// Acquire ownership from EVMC. This will deallocate it also at the end of the scope.
|
||||
::evmc_vm::EvmcContainer::<#type_ident>::from_ffi_pointer(instance);
|
||||
}
|
||||
}
|
||||
|
@ -367,6 +371,7 @@ fn build_execute_fn(names: &VMNameSet) -> proc_macro2::TokenStream {
|
|||
};
|
||||
|
||||
let container = unsafe {
|
||||
// Acquire ownership from EVMC.
|
||||
::evmc_vm::EvmcContainer::<#type_name_ident>::from_ffi_pointer(instance)
|
||||
};
|
||||
|
||||
|
@ -385,6 +390,7 @@ fn build_execute_fn(names: &VMNameSet) -> proc_macro2::TokenStream {
|
|||
};
|
||||
|
||||
unsafe {
|
||||
// Release ownership to EVMC.
|
||||
::evmc_vm::EvmcContainer::into_ffi_pointer(container);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,11 +22,11 @@ where
|
|||
T: EvmcVm + Sized,
|
||||
{
|
||||
/// Basic constructor.
|
||||
pub fn new(_instance: ::evmc_sys::evmc_instance) -> Self {
|
||||
Self {
|
||||
pub fn new(_instance: ::evmc_sys::evmc_instance) -> Box<Self> {
|
||||
Box::new(Self {
|
||||
instance: _instance,
|
||||
vm: T::init(),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Take ownership of the given pointer and return a box.
|
||||
|
@ -147,7 +147,7 @@ mod tests {
|
|||
::evmc_sys::evmc_status_code::EVMC_FAILURE
|
||||
);
|
||||
|
||||
let ptr = unsafe { EvmcContainer::into_ffi_pointer(Box::new(container)) };
|
||||
let ptr = unsafe { EvmcContainer::into_ffi_pointer(container) };
|
||||
|
||||
let mut context = ExecutionContext::new(&mut backing_context);
|
||||
let container = unsafe { EvmcContainer::<TestVm>::from_ffi_pointer(ptr) };
|
||||
|
|
Loading…
Reference in New Issue