Skip to content

Commit

Permalink
fix: remove some linknames
Browse files Browse the repository at this point in the history
  • Loading branch information
liuq19 committed Jul 8, 2024
1 parent 765ecdb commit f35e631
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 117 deletions.
3 changes: 2 additions & 1 deletion ast/api_compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ import (
`unicode/utf8`

`github.com/bytedance/sonic/internal/native/types`
`github.com/bytedance/sonic/internal/envs`
`github.com/bytedance/sonic/internal/rt`
)

func init() {
println("WARNING:(ast) sonic only supports go1.17~1.22, but your environment is not suitable")
println("WARNING: sonic/decoder only supports", envs.SupportedEnvs, "but your environment is not suitable and fallback to standard library now")

Check failure on line 31 in ast/api_compat.go

View workflow job for this annotation

GitHub Actions / build (1.16.x, arm)

undefined: envs.SupportedEnvs
}

func quote(buf *[]byte, val string) {
Expand Down
105 changes: 99 additions & 6 deletions ast/stubs.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,106 @@ func mem2ptr(s []byte) unsafe.Pointer {
return (*rt.GoSlice)(unsafe.Pointer(&s)).Ptr
}

var (
//go:linkname safeSet encoding/json.safeSet
safeSet [utf8.RuneSelf]bool
var safeSet = [utf8.RuneSelf]bool{
' ': true,
'!': true,
'"': false,
'#': true,
'$': true,
'%': true,
'&': true,
'\'': true,
'(': true,
')': true,
'*': true,
'+': true,
',': true,
'-': true,
'.': true,
'/': true,
'0': true,
'1': true,
'2': true,
'3': true,
'4': true,
'5': true,
'6': true,
'7': true,
'8': true,
'9': true,
':': true,
';': true,
'<': true,
'=': true,
'>': true,
'?': true,
'@': true,
'A': true,
'B': true,
'C': true,
'D': true,
'E': true,
'F': true,
'G': true,
'H': true,
'I': true,
'J': true,
'K': true,
'L': true,
'M': true,
'N': true,
'O': true,
'P': true,
'Q': true,
'R': true,
'S': true,
'T': true,
'U': true,
'V': true,
'W': true,
'X': true,
'Y': true,
'Z': true,
'[': true,
'\\': false,
']': true,
'^': true,
'_': true,
'`': true,
'a': true,
'b': true,
'c': true,
'd': true,
'e': true,
'f': true,
'g': true,
'h': true,
'i': true,
'j': true,
'k': true,
'l': true,
'm': true,
'n': true,
'o': true,
'p': true,
'q': true,
'r': true,
's': true,
't': true,
'u': true,
'v': true,
'w': true,
'x': true,
'y': true,
'z': true,
'{': true,
'|': true,
'}': true,
'~': true,
'\u007f': true,
}

//go:linkname hex encoding/json.hex
hex string
)
var hex = "0123456789abcdef"

//go:linkname unquoteBytes encoding/json.unquoteBytes
func unquoteBytes(s []byte) (t []byte, ok bool)
3 changes: 2 additions & 1 deletion decoder/decoder_compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ import (
`unsafe`

`github.com/bytedance/sonic/internal/native/types`
`github.com/bytedance/sonic/internal/envs`
`github.com/bytedance/sonic/option`
)

func init() {
println("WARNING: sonic/decoder only supports (Go1.17~1.22 && CPU amd64) or (go1.20~1.22 && CPU arm64), but your environment is not suitable")
println("WARNING: sonic/decoder only supports", envs.SupportedEnvs, "but your environment is not suitable and fallback to standard library now")
}

const (
Expand Down
3 changes: 2 additions & 1 deletion encoder/encoder_compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ import (
`reflect`

`github.com/bytedance/sonic/option`
`github.com/bytedance/sonic/internal/envs`
)

func init() {
println("WARNING:(encoder) sonic only supports (Go1.17~1.22 && CPU amd64) or (G01.20~1.22 && CPU arm64) , but your environment is not suitable")
println("WARNING: sonic/decoder only supports", envs.SupportedEnvs, "but your environment is not suitable and fallback to standard library now")
}

// EnableFallback indicates if encoder use fallback
Expand Down
21 changes: 4 additions & 17 deletions internal/decoder/optdec/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -967,11 +967,7 @@ func AsEfaceFast(iter *NodeIter, ctx *Context) interface{} {
val = sp
goto _arr_val;
} else {
ctx.efacePool.ConvTSlice(rt.GoSlice{
Ptr: rt.ZSTPtr,
Len: 0,
Cap: 0,
}, rt.SliceEfaceType, unsafe.Pointer(&root))
ctx.efacePool.ConvTSlice(rt.EmptySlice, rt.SliceEfaceType, unsafe.Pointer(&root))
}
case KStringCommon: ctx.efacePool.ConvTstring(node.StringRef(ctx), unsafe.Pointer(&root))
case KStringEscaped: ctx.efacePool.ConvTstring(node.StringCopyEsc(ctx), unsafe.Pointer(&root))
Expand All @@ -993,9 +989,8 @@ _object_key:
} else {
key = node.StringCopyEsc(ctx)
}
// interface{} slot in map bucket

//println("key is **", key, "** mp is ", mp)
// interface{} slot in map bucket
val = rt.Mapassign_faststr(rt.MapEfaceMapType, mp, key)
vt = &(*rt.GoEface)(val).Type
vp = &(*rt.GoEface)(val).Value
Expand All @@ -1021,11 +1016,7 @@ _object_key:
case KArray:
newSize := node.Array().Len()
if newSize == 0 {
ctx.efacePool.ConvTSlice(rt.GoSlice{
Ptr: rt.ZSTPtr,
Len: 0,
Cap: 0,
}, rt.SliceEfaceType, val)
ctx.efacePool.ConvTSlice(rt.EmptySlice, rt.SliceEfaceType, val)
break;
}

Expand Down Expand Up @@ -1124,11 +1115,7 @@ _arr_val:
case KArray:
newSize := node.Array().Len()
if newSize == 0 {
ctx.efacePool.ConvTSlice(rt.GoSlice{
Ptr: rt.ZSTPtr,
Len: newSize,
Cap: newSize,
}, rt.SliceEfaceType, val)
ctx.efacePool.ConvTSlice(rt.EmptySlice, rt.SliceEfaceType, val)
break;
}

Expand Down
58 changes: 0 additions & 58 deletions internal/decoder/optdec/options.go

This file was deleted.

8 changes: 1 addition & 7 deletions internal/rt/rt_stubs_go116.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,14 @@ import (
"unsafe"
)

//go:linkname roundupsize runtime.roundupsize
func roundupsize(size uintptr) uintptr

//go:linkname makeslice runtime.makeslice
//goland:noinspection GoUnusedParameter
func makeslice(et *GoType, len int, cap int) unsafe.Pointer

func MakeSlice(oldPtr unsafe.Pointer, et *GoType, newLen int) *GoSlice {
if newLen == 0 {
return &GoSlice{
Ptr: ZSTPtr,
Len: 0,
Cap: 0,
}
return &EmptySlice
}

if *(*unsafe.Pointer)(oldPtr) == nil {
Expand Down
9 changes: 1 addition & 8 deletions internal/rt/rt_stubs_go120.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,13 @@ import (
"unsafe"
)

//go:linkname roundupsize runtime.roundupsize
func roundupsize(size uintptr) uintptr

//go:linkname makeslice runtime.makeslice
//goland:noinspection GoUnusedParameter
func makeslice(et *GoType, len int, cap int) unsafe.Pointer

func MakeSlice(oldPtr unsafe.Pointer, et *GoType, newLen int) *GoSlice {
if newLen == 0 {
return &GoSlice{
Ptr: ZSTPtr,
Len: 0,
Cap: 0,
}
return &EmptySlice
}

if *(*unsafe.Pointer)(oldPtr) == nil {
Expand Down
14 changes: 1 addition & 13 deletions internal/rt/rt_stubs_go123.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,13 @@ import (
"unsafe"
)

//go:linkname rt_roundupsize runtime.roundupsize
func rt_roundupsize(size uintptr, noscan bool) uintptr

// a wrapper for fastmap
func roundupsize(size uintptr) uintptr {
return rt_roundupsize(size, MapType(MapEfaceType).Bucket.PtrData == 0)
}

//go:linkname makeslice runtime.makeslice
//goland:noinspection GoUnusedParameter
func makeslice(et *GoType, len int, cap int) unsafe.Pointer

func MakeSlice(oldPtr unsafe.Pointer, et *GoType, newLen int) *GoSlice {
if newLen == 0 {
return &GoSlice{
Ptr: ZSTPtr,
Len: 0,
Cap: 0,
}
return &EmptySlice
}

if *(*unsafe.Pointer)(oldPtr) == nil {
Expand Down
3 changes: 3 additions & 0 deletions internal/rt/stubs.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,6 @@ func GetMap64Assign(vt reflect.Type) Map64Assign {
}
}


var emptyBytes = make([]byte, 0, 0)
var EmptySlice = *(*GoSlice)(unsafe.Pointer(&emptyBytes))

Check failure on line 129 in internal/rt/stubs.go

View workflow job for this annotation

GitHub Actions / build (1.20.x)

syntax error: unexpected var after top level declaration

Check failure on line 129 in internal/rt/stubs.go

View workflow job for this annotation

GitHub Actions / build (1.20.x)

syntax error: unexpected var after top level declaration

Check failure on line 129 in internal/rt/stubs.go

View workflow job for this annotation

GitHub Actions / build (1.20.x)

syntax error: unexpected var after top level declaration
5 changes: 0 additions & 5 deletions internal/rt/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ func AsGoType(t uintptr) *GoType {
return (*GoType)(unsafe.Pointer(t))
}

//go:linkname zerobase runtime.zerobase
var zerobase uintptr

var (
BoolType = UnpackType(reflect.TypeOf(false))
ByteType = UnpackType(reflect.TypeOf(byte(0)))
Expand Down Expand Up @@ -45,6 +42,4 @@ var (
MapStringType = UnpackType(reflect.TypeOf(map[string]string(nil)))

MapEfaceMapType = MapType(UnpackType(reflect.TypeOf(map[string]interface{}(nil))))

ZSTPtr = unsafe.Pointer(&zerobase)
)

0 comments on commit f35e631

Please sign in to comment.