Skip to content

Commit

Permalink
skip registering large uint64
Browse files Browse the repository at this point in the history
  • Loading branch information
xhd2015 committed Jun 3, 2024
1 parent 4d63b2e commit c35e746
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 20 deletions.
4 changes: 2 additions & 2 deletions cmd/xgo/runtime_gen/core/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
)

const VERSION = "1.0.39"
const REVISION = "55af407f826d020bcd28c51663d0879f8d1ca76e+1"
const NUMBER = 258
const REVISION = "4d63b2ed7ce161f17d1c311a9b536e82a01769f0+1"
const NUMBER = 259

// these fields will be filled by compiler
const XGO_VERSION = ""
Expand Down
4 changes: 2 additions & 2 deletions cmd/xgo/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package main
import "fmt"

const VERSION = "1.0.39"
const REVISION = "55af407f826d020bcd28c51663d0879f8d1ca76e+1"
const NUMBER = 258
const REVISION = "4d63b2ed7ce161f17d1c311a9b536e82a01769f0+1"
const NUMBER = 259

func getRevision() string {
revSuffix := ""
Expand Down
6 changes: 4 additions & 2 deletions patch/info/decl_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ func (c DeclKind) String() string {
}

type DeclInfo struct {
FuncDecl *syntax.FuncDecl
VarDecl *syntax.VarDecl
FuncDecl *syntax.FuncDecl
VarDecl *syntax.VarDecl

// when kind == CONST
ConstDecl *syntax.ConstDecl

// is this var decl follow a const __xgo_trap_xxx = 1?
Expand Down
12 changes: 12 additions & 0 deletions patch/syntax/syntax.go
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,18 @@ func generateFuncRegBody(pos syntax.Pos, funcDecls []*DeclInfo, xgoRegFunc strin
// there are function with name "_"
continue
}
// type unknown constant expr, will not be registered,
// see bug https://github.com/xhd2015/xgo/issues/53
// why not filter them earlier?
// because the node still needs to be marked, but effectively skipped
if funcDecl.Kind == info.Kind_Const && funcDecl.ConstDecl.Type == nil {
untypedConstType := getConstDeclValueType(funcDecl.ConstDecl.Values)
if untypedConstType == "" || untypedConstType == UNKNOWN_CONST_TYPE {
// exclude
continue
}
}

var fnRefName syntax.Expr
var varRefName syntax.Expr
if funcDecl.Kind.IsFunc() {
Expand Down
4 changes: 2 additions & 2 deletions runtime/core/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
)

const VERSION = "1.0.39"
const REVISION = "55af407f826d020bcd28c51663d0879f8d1ca76e+1"
const NUMBER = 258
const REVISION = "4d63b2ed7ce161f17d1c311a9b536e82a01769f0+1"
const NUMBER = 259

// these fields will be filled by compiler
const XGO_VERSION = ""
Expand Down
17 changes: 8 additions & 9 deletions runtime/test/debug/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@ import (
"testing"
)

const userNsLength = (1 << 16)
const (
pod1 = "pod1"
minimumMappingUID = userNsLength
mappingLen = userNsLength * 2000
)

type Pod struct {
Name string
}

func TestConstNameCollision(t *testing.T) {
var pod1 *Pod
// see bug https://github.com/xhd2015/xgo/issues/176
func TestUntypedUnknownConstShouldCompile(t *testing.T) {
var allocated uint32

if pod1 != nil && pod1.Name != "" {
t.Fatalf("pod1 should be empty")
if allocated > minimumMappingUID+mappingLen-userNsLength {
t.Fatalf("allocated is greater?")
}
}
22 changes: 19 additions & 3 deletions runtime/test/patch_const/patch_const_op_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package patch_const

import (
"fmt"
"testing"
"time"

Expand All @@ -10,9 +11,24 @@ import (
const A = 20 * time.Second

func TestPatchConstOp(t *testing.T) {
mock.PatchByName("github.com/xhd2015/xgo/runtime/test/patch_const", "A", func() time.Duration {
return 10 * time.Second
})
// patch should fail because registering were filtered
var errMsg string
func() {
defer func() {
if e := recover(); e != nil {
errMsg = fmt.Sprint(e)
}
}()
mock.PatchByName("github.com/xhd2015/xgo/runtime/test/patch_const", "A", func() time.Duration {
return 10 * time.Second
})
}()

expectErr := "failed to setup mock for: github.com/xhd2015/xgo/runtime/test/patch_const.A"
if errMsg != expectErr {
t.Fatalf("expect errMsg to be: %q, actual: %q", expectErr, errMsg)
}

a := A
if a != 20*time.Second {
t.Fatalf("expect patch A failed because current xgo does not resolve operation type, actual: a=%v, want: %v", a, 20*time.Second)
Expand Down
22 changes: 22 additions & 0 deletions runtime/test/trap/trap_math_max_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package trap

import (
"math"
"testing"
)

// these should compile
// see bug https://github.com/xhd2015/xgo/issues/53

const SET_EMPTY_STRING = "<empty>"
const SET_ZERO = math.MaxInt64 - 1
const SET_ZERO_UINT = math.MaxUint64 - 1
const SET_ZERO_INT32 = math.MaxInt32 - 1
const SET_ZERO_UINT32 = math.MaxUint32 - 1

func TestMathMaxShouldCompile(t *testing.T) {
zero := uint64(SET_ZERO_UINT)
if zero != math.MaxUint64-1 {
t.Fatalf("zero: %v", zero)
}
}

0 comments on commit c35e746

Please sign in to comment.