Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move evmc_host_interface out of evmc_host_context #427

Merged
merged 6 commits into from
Nov 5, 2019
Merged

Conversation

chfast
Copy link
Member

@chfast chfast commented Sep 20, 2019

On the C API level (and also ABI) the host_interface (think: an object vtable) and host_context (think: pointer to an object's data) are separated. This actually makes creating language bindings easier - no need for workarounds as in https://github.com/ethereum/evmc/blob/master/bindings/go/evmc/evmc.go#L26-L30.

Language bindings can still hide this by providing single OOP interface for Host (both for Client and VM side).

@chfast
Copy link
Member Author

chfast commented Sep 25, 2019

@axic Do you want me to finish Rust part here?

@chfast
Copy link
Member Author

chfast commented Nov 4, 2019

@axic @jakelang can you finish Rust changes here, please?

@axic
Copy link
Member

axic commented Nov 4, 2019

@chfast fixed compilation, but haven't reviewed the changes yet.

@axic axic force-pushed the host_interface branch 4 times, most recently from 7dab19e to 3f865ba Compare November 4, 2019 19:59
@@ -132,7 +132,7 @@ mod tests {
get_block_hash: None,
emit_log: None,
};
let mut host_context = ::evmc_sys::evmc_host_context { _unused: [] };
let mut host_context = ::evmc_sys::evmc_host_context::default();
Copy link
Member Author

Choose a reason for hiding this comment

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

Is it possible to pass a null pointer instead of creating host_context object?

Copy link
Member

@axic axic Nov 4, 2019

Choose a reason for hiding this comment

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

Yeah, that should be an option too. Will make Rust cry though, a mutable nullpointer reference lol.

Copy link
Member

Choose a reason for hiding this comment

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

Just tried it and it feels like to be simple leaving it as is, for now.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried it too, but feels like null pointers is Rust's advanced feature.

@chfast
Copy link
Member Author

chfast commented Nov 4, 2019

Ok, thanks a lot. I will clean up git history and put it for review.

@chfast chfast requested review from jakelang, axic and gumb0 and removed request for jakelang November 4, 2019 20:50
@chfast chfast marked this pull request as ready for review November 4, 2019 20:51
include/evmc/evmc.h Outdated Show resolved Hide resolved
@@ -345,7 +346,7 @@ fn build_execute_fn(names: &VMNameSet) -> proc_macro2::TokenStream {
use evmc_vm::EvmcVm;

// TODO: context is optional in case of the "precompiles" capability
if instance.is_null() || context.is_null() || msg.is_null() || (code.is_null() && code_size != 0) {
if instance.is_null() || host.is_null() || context.is_null() || msg.is_null() || (code.is_null() && code_size != 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Depending on #427 (comment) we may need to remove context.is_null() here.

Copy link
Member Author

Choose a reason for hiding this comment

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

The context may always be null. VM never needs to dereference it.
Now the TODO comment should be applied to the host as in the case of "precompiles" it is not useful and may be null — this can be discussed further in #350.

Copy link
Member

Choose a reason for hiding this comment

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

Fixed the context part. Lets leave host for #350.

@axic
Copy link
Member

axic commented Nov 5, 2019

@chfast simplified it to deal with null pointers. Also allows context to be null now.

@chfast chfast merged commit a15e493 into master Nov 5, 2019
@chfast chfast deleted the host_interface branch November 5, 2019 11:53
@axic axic mentioned this pull request Dec 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants