Skip to content
This repository was archived by the owner on Apr 8, 2026. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion bindings/rust/evmc-declare/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,15 @@ fn build_execute_fn(names: &VMNameSet) -> proc_macro2::TokenStream {
::evmc_vm::EvmcContainer::<#type_name_ident>::from_ffi_pointer(instance)
};

let result = container.execute(code_ref, &execution_context);
let result = ::std::panic::catch_unwind(|| {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not recommended to use this function for a general try/catch mechanism. The Result type is more appropriate to use for functions that can fail on a regular basis. Additionally, this function is not guaranteed to catch all panics, see the "Notes" section below.

https://doc.rust-lang.org/std/panic/fn.catch_unwind.html

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main reason for this change is exactly listed in your link:

It is currently undefined behavior to unwind from Rust code into foreign code, so this function is particularly useful when Rust is called from another language (normally C). This can run arbitrary Rust code, capturing a panic and allowing a graceful handling of the error.

container.execute(code_ref, &execution_context)
});

let result = if result.is_err() {
::evmc_vm::ExecutionResult::new(::evmc_vm::ffi::evmc_status_code::EVMC_INTERNAL_ERROR, 0, None)
} else {
result.unwrap()
};

unsafe {
::evmc_vm::EvmcContainer::into_ffi_pointer(container);
Expand Down