Skip to content

Commit

Permalink
go: Use evmc_make_result() in Host.Call()
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Aug 6, 2019
1 parent 705a610 commit 229ae73
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
7 changes: 0 additions & 7 deletions bindings/go/evmc/host.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@

#include <stdlib.h>


void evmc_go_free_result_output(const struct evmc_result* result)
{
free((void*)result->output_data);
}


/* Go does not support exporting functions with parameters with const modifiers,
* so we have to cast function pointers to the function types defined in EVMC.
* This disables any type checking of exported Go functions. To mitigate this
Expand Down
17 changes: 5 additions & 12 deletions bindings/go/evmc/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ package evmc
#cgo CFLAGS: -I${SRCDIR}/.. -Wall -Wextra -Wno-unused-parameter
#include <evmc/evmc.h>
#include <evmc/helpers.h>
struct extended_context
{
struct evmc_context context;
int64_t index;
};
void evmc_go_free_result_output(const struct evmc_result* result);
*/
import "C"
import (
Expand Down Expand Up @@ -224,18 +223,12 @@ func call(pCtx unsafe.Pointer, msg *C.struct_evmc_message) C.struct_evmc_result
statusCode = C.enum_evmc_status_code(err.(Error))
}

result := C.struct_evmc_result{}
result.status_code = statusCode
result.gas_left = C.int64_t(gasLeft)
result.create_address = evmcAddress(createAddr)

outputData := (*C.uint8_t)(nil)
if len(output) > 0 {
// TODO: We could pass it directly to the caller without a copy. The caller should release it. Check depth.
cOutput := C.CBytes(output)
result.output_data = (*C.uint8_t)(cOutput)
result.output_size = C.size_t(len(output))
result.release = (C.evmc_release_result_fn)(C.evmc_go_free_result_output)
outputData = (*C.uint8_t)(&output[0])
}

result := C.evmc_make_result(statusCode, C.int64_t(gasLeft), outputData, C.size_t(len(output)))
result.create_address = evmcAddress(createAddr)
return result
}

0 comments on commit 229ae73

Please sign in to comment.