Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
build: fix version comparison for go1.10 and beyond (ethereum#15781)
Browse files Browse the repository at this point in the history
  • Loading branch information
karalabe authored and dm4 committed May 4, 2018
1 parent 7154181 commit 3a0c88d
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 6 deletions.
21 changes: 15 additions & 6 deletions build/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,17 @@ func doInstall(cmdline []string) {

// Check Go version. People regularly open issues about compilation
// failure with outdated Go. This should save them the trouble.
if runtime.Version() < "go1.7" && !strings.Contains(runtime.Version(), "devel") {
log.Println("You have Go version", runtime.Version())
log.Println("go-ethereum requires at least Go version 1.7 and cannot")
log.Println("be compiled with an earlier version. Please upgrade your Go installation.")
os.Exit(1)
if !strings.Contains(runtime.Version(), "devel") {
// Figure out the minor version number since we can't textually compare (1.10 < 1.7)
var minor int
fmt.Sscanf(strings.TrimPrefix(runtime.Version(), "go1."), "%d", &minor)

if minor < 7 {
log.Println("You have Go version", runtime.Version())
log.Println("go-ethereum requires at least Go version 1.7 and cannot")
log.Println("be compiled with an earlier version. Please upgrade your Go installation.")
os.Exit(1)
}
}
// Compile packages given as arguments, or everything if there are no arguments.
packages := []string{"./..."}
Expand Down Expand Up @@ -256,7 +262,10 @@ func goToolArch(arch string, subcmd string, args ...string) *exec.Cmd {
if subcmd == "build" || subcmd == "install" || subcmd == "test" {
// Go CGO has a Windows linker error prior to 1.8 (https://github.com/golang/go/issues/8756).
// Work around issue by allowing multiple definitions for <1.8 builds.
if runtime.GOOS == "windows" && runtime.Version() < "go1.8" {
var minor int
fmt.Sscanf(strings.TrimPrefix(runtime.Version(), "go1."), "%d", &minor)

if runtime.GOOS == "windows" && minor < 8 {
cmd.Args = append(cmd.Args, []string{"-ldflags", "-extldflags -Wl,--allow-multiple-definition"}...)
}
}
Expand Down
54 changes: 54 additions & 0 deletions core/vm/eni/arg_parser/arg_parser_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package arg_parser
import "testing"
import "bytes"
import "fmt"

// single positive integer (big endian)
func ExampleA(){
var arg_parser arg_parser_t
var f, d []byte
var buf bytes.Buffer;

f = make([]byte, 1, 1)
d = make([]byte, 70, 70)
f[0] = INT
for i:=0; i<70; i++ { d[i] = uint8(0) }
d[31] = uint8(72) // 32-byte big endian
arg_parser.parse_entry_point(f, d, &buf)
fmt.Println(buf.String())
// Output: [72]
}

// single positive integer (big endian)
func TestB(t *testing.T){
var arg_parser arg_parser_t
var f, d []byte
var buf bytes.Buffer;

f = make([]byte, 1, 1)
d = make([]byte, 70, 70)
f[0] = INT
for i:=0; i<70; i++ { d[i] = uint8(0) }
a:= -72
d[31] = byte(a) // 32-byte big endian
arg_parser.parse_entry_point(f, d, &buf)
}

// a int and a bool
func ExampleC(){
var arg_parser arg_parser_t
var f, d []byte
var buf bytes.Buffer;

f = make([]byte, 2, 2)
d = make([]byte, 70, 70)
f[0] = INT
f[1] = BOOL
for i:=0; i<70; i++ { d[i] = uint8(0) }
d[31] = uint8(72) // 32-byte big endian
arg_parser.parse_entry_point(f, d, &buf)
fmt.Println(buf.String())

// Output: [72,false]
}

23 changes: 23 additions & 0 deletions core/vm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ package vm
import (
"fmt"
"math/big"
"strings"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm/eni/arg_parser"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params"
)
Expand Down Expand Up @@ -656,6 +658,27 @@ func opDelegateCall(pc *uint64, evm *EVM, contract *Contract, memory *Memory, st
return ret, nil
}

func opENI(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
// get arguments
funcName := string(stack.pop().Bytes()).Trim(string(funcName), "\x00")
typeOffset, dataOffset := stack.pop().Int64(), stack.pop().Int64()
typeLength := new(big.Int).SetBytes(memory.Get(typeOffset, 32)).Int64()
dataLength := new(big.Int).SetBytes(memory.Get(dataOffset, 32)).Int64()

typeSection := memory.Get(typeOffset+32, typeLength)
dataSection := memory.Get(dataOffset+32, dataLength)

argsText := arg_parser.Parse(typeSection, dataSection)

retText := evm.eni.ExecuteENI(funcName, argsText)

// TODO: parse return value
retAddr := uint64(7112)
memory.Resize(retAddr + uint64(len(retText)))
memory.Set(retAddr, 32, []byte(retText))
return nil, nil
}

func opReturn(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
offset, size := stack.pop(), stack.pop()
ret := memory.GetPtr(offset.Int64(), size.Int64())
Expand Down

0 comments on commit 3a0c88d

Please sign in to comment.