chore: migrate to gitea
Some checks failed
golangci-lint / lint (push) Failing after 1m30s
Test / test (push) Failing after 2m17s

This commit is contained in:
2026-01-27 00:40:46 +01:00
parent 1e05874160
commit f8df24c29d
3169 changed files with 1216434 additions and 1587 deletions

View File

@@ -0,0 +1,20 @@
// +build !noasm,amd64 !appengine,amd64
// Code generated by asm2asm, DO NOT EDIT·
#include "go_asm.h"
#include "funcdata.h"
#include "textflag.h"
TEXT ·MoreStack(SB), NOSPLIT, $0 - 8
NO_LOCAL_POINTERS
_entry:
MOVQ (TLS), R14
MOVQ size+0(FP), R12
NOTQ R12
LEAQ (SP)(R12*1), R12
CMPQ R12, 16(R14)
JBE _stack_grow
RET
_stack_grow:
CALL runtime·morestack_noctxt<>(SB)
JMP _entry

View File

@@ -0,0 +1,10 @@
// +build !noasm,!amd64 !appengine,!amd64
// Code generated by asm2asm, DO NOT EDIT.
#include "go_asm.h"
#include "funcdata.h"
#include "textflag.h"
TEXT ·MoreStack(SB), NOSPLIT, $0 - 8
NO_LOCAL_POINTERS
RET

View File

@@ -0,0 +1,42 @@
// +build go1.17
/*
* Copyright 2021 ByteDance Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package rt
import (
_ `unsafe`
)
func AssertI2I(t *GoType, i GoIface) (r GoIface) {
inter := IfaceType(t)
tab := i.Itab
if tab == nil {
return
}
if (*GoInterfaceType)(tab.it) != inter {
tab = GetItab(inter, tab.Vt, true)
if tab == nil {
return
}
}
r.Itab = tab
r.Value = i.Value
return
}

View File

@@ -0,0 +1,44 @@
// +build amd64,go1.17,!go1.27
package rt
import (
_ "unsafe"
"github.com/cloudwego/base64x"
)
func DecodeBase64(raw []byte) ([]byte, error) {
ret := make([]byte, base64x.StdEncoding.DecodedLen(len(raw)))
n, err := base64x.StdEncoding.Decode(ret, raw)
if err != nil {
return nil, err
}
return ret[:n], nil
}
func EncodeBase64ToString(src []byte) string {
return base64x.StdEncoding.EncodeToString(src)
}
func EncodeBase64(buf []byte, src []byte) []byte {
if len(src) == 0 {
return append(buf, '"', '"')
}
buf = append(buf, '"')
need := base64x.StdEncoding.EncodedLen(len(src))
if cap(buf) - len(buf) < need {
tmp := make([]byte, len(buf), len(buf) + need*2)
copy(tmp, buf)
buf = tmp
}
base64x.StdEncoding.Encode(buf[len(buf):cap(buf)], src)
buf = buf[:len(buf) + need]
buf = append(buf, '"')
return buf
}
//go:linkname SubrB64Decode github.com/cloudwego/base64x._subr__b64decode
var SubrB64Decode uintptr
//go:linkname SubrB64Encode github.com/cloudwego/base64x._subr__b64encode
var SubrB64Encode uintptr

View File

@@ -0,0 +1,37 @@
// +build !amd64 !go1.17 go1.27
package rt
import (
"encoding/base64"
)
func DecodeBase64(raw []byte) ([]byte, error) {
ret := make([]byte, base64.StdEncoding.DecodedLen(len(raw)))
n, err := base64.StdEncoding.Decode(ret, raw)
if err != nil {
return nil, err
}
return ret[:n], nil
}
func EncodeBase64ToString(src []byte) string {
return base64.StdEncoding.EncodeToString(src)
}
func EncodeBase64(buf []byte, src []byte) []byte {
if len(src) == 0 {
return append(buf, '"', '"')
}
buf = append(buf, '"')
need := base64.StdEncoding.EncodedLen(len(src))
if cap(buf) - len(buf) < need {
tmp := make([]byte, len(buf), len(buf) + need*2)
copy(tmp, buf)
buf = tmp
}
base64.StdEncoding.Encode(buf[len(buf):cap(buf)], src)
buf = buf[:len(buf) + need]
buf = append(buf, '"')
return buf
}

View File

@@ -0,0 +1,175 @@
package rt
import (
"unsafe"
"encoding/json"
)
// Copied from Golang
var staticuint64s = [...]uint64{
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
}
const maxZero = 1024 // must match value in reflect/value.go:maxZero cmd/compile/internal/gc/walk.go:zeroValSize
var zeroVal [maxZero]byte
type TslicePool struct {
pool []GoSlice
index int
}
func NewTslicePool (hint int) TslicePool {
return TslicePool{
pool: make([]GoSlice, hint, hint),
index: 0,
}
}
func (self *TslicePool) Conv(val GoSlice, typ *GoType, ep *interface{}) {
var vp unsafe.Pointer
if ((*GoSlice)(unsafe.Pointer(&val))).Ptr == nil {
vp = unsafe.Pointer(&zeroVal[0])
} else if self.index < len(self.pool) {
dst := &(self.pool)[self.index]
*dst = val
self.index++
vp = unsafe.Pointer(dst)
} else {
vp = Mallocgc(unsafe.Sizeof(val), BytesType, true)
}
*((*GoEface)(unsafe.Pointer(ep))) = GoEface{Type: typ, Value: vp}
}
func (self *TslicePool) Free() {
self.pool = nil
}
type TstringPool struct {
pool []string
index int
}
func NewTstringPool (hint int) TstringPool {
return TstringPool{
pool: make([]string, hint),
index: 0,
}
}
func (self *TstringPool) Conv(val string, ep *interface{}) {
var vp unsafe.Pointer
if val == "" {
vp = unsafe.Pointer(&zeroVal[0])
} else if self.index < len(self.pool) {
dst := &(self.pool)[self.index]
*dst = val
self.index++
vp = unsafe.Pointer(dst)
} else {
vp = Mallocgc(unsafe.Sizeof(val), StringType, true)
}
// convert into interface{}
*((*GoEface)(unsafe.Pointer(ep))) = GoEface{Type: StringType, Value: vp}
}
func (self *TstringPool) ConvNum(val json.Number, ep *interface{}) {
var vp unsafe.Pointer
if val == "" {
vp = unsafe.Pointer(&zeroVal[0])
} else if self.index < len(self.pool) {
dst := &(self.pool)[self.index]
*dst = string(val)
self.index++
vp = unsafe.Pointer(dst)
} else {
vp = Mallocgc(unsafe.Sizeof(val), StringType, true)
}
// convert into interface{}
*((*GoEface)(unsafe.Pointer(ep))) = GoEface{Type: JsonNumberType, Value: vp}
}
func (self *TstringPool) Free() {
self.pool = nil
}
type T64Pool struct {
pool []uint64
index int
}
func NewT64Pool (hint int) T64Pool {
return T64Pool{
pool: make([]uint64, hint, hint),
index: 0,
}
}
func (self *T64Pool) Conv(val uint64, typ *GoType, ep *interface{}) {
var vp unsafe.Pointer
if val < uint64(len(staticuint64s)) {
vp = unsafe.Pointer(&staticuint64s[val])
} else if self.index < len(self.pool) {
dst := &(self.pool)[self.index]
*dst = val
self.index++
vp = unsafe.Pointer(dst)
} else {
vp = Mallocgc(8, Uint64Type, false)
}
// convert into interface{}
*((*GoEface)(unsafe.Pointer(ep))) = GoEface{Type: typ, Value: vp}
}
func (self *T64Pool) Free() {
self.pool = nil
}
func ConvTBool(val bool, ep *interface{}) {
var vp unsafe.Pointer
if val {
vp = unsafe.Pointer(&staticuint64s[1])
} else {
vp = unsafe.Pointer(&staticuint64s[0])
}
*((*GoEface)(unsafe.Pointer(ep))) = GoEface{Type: BoolType, Value: vp}
}

View File

@@ -0,0 +1,155 @@
/*
* Copyright 2021 ByteDance Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package rt
import (
"reflect"
"unsafe"
"github.com/bytedance/sonic/option"
)
//go:nosplit
func Get16(v []byte) int16 {
return *(*int16)((*GoSlice)(unsafe.Pointer(&v)).Ptr)
}
//go:nosplit
func Get32(v []byte) int32 {
return *(*int32)((*GoSlice)(unsafe.Pointer(&v)).Ptr)
}
//go:nosplit
func Get64(v []byte) int64 {
return *(*int64)((*GoSlice)(unsafe.Pointer(&v)).Ptr)
}
//go:nosplit
func Mem2Str(v []byte) (s string) {
(*GoString)(unsafe.Pointer(&s)).Len = (*GoSlice)(unsafe.Pointer(&v)).Len
(*GoString)(unsafe.Pointer(&s)).Ptr = (*GoSlice)(unsafe.Pointer(&v)).Ptr
return
}
//go:nosplit
func Str2Mem(s string) (v []byte) {
(*GoSlice)(unsafe.Pointer(&v)).Cap = (*GoString)(unsafe.Pointer(&s)).Len
(*GoSlice)(unsafe.Pointer(&v)).Len = (*GoString)(unsafe.Pointer(&s)).Len
(*GoSlice)(unsafe.Pointer(&v)).Ptr = (*GoString)(unsafe.Pointer(&s)).Ptr
return
}
func BytesFrom(p unsafe.Pointer, n int, c int) (r []byte) {
(*GoSlice)(unsafe.Pointer(&r)).Ptr = p
(*GoSlice)(unsafe.Pointer(&r)).Len = n
(*GoSlice)(unsafe.Pointer(&r)).Cap = c
return
}
func FuncAddr(f interface{}) unsafe.Pointer {
if vv := UnpackEface(f); vv.Type.Kind() != reflect.Func {
panic("f is not a function")
} else {
return *(*unsafe.Pointer)(vv.Value)
}
}
//go:nocheckptr
func IndexChar(src string, index int) unsafe.Pointer {
return unsafe.Pointer(uintptr((*GoString)(unsafe.Pointer(&src)).Ptr) + uintptr(index))
}
//go:nocheckptr
func IndexByte(ptr []byte, index int) unsafe.Pointer {
return unsafe.Pointer(uintptr((*GoSlice)(unsafe.Pointer(&ptr)).Ptr) + uintptr(index))
}
func GuardSlice(buf *[]byte, n int) {
c := cap(*buf)
l := len(*buf)
if c-l < n {
c = c>>1 + n + l
if c < 32 {
c = 32
}
tmp := make([]byte, l, c)
copy(tmp, *buf)
*buf = tmp
}
}
func GuardSlice2(buf []byte, n int) []byte {
c := cap(buf)
l := len(buf)
if c-l < n {
c = c>>1 + n + l
if c < 32 {
c = 32
}
tmp := make([]byte, l, c)
copy(tmp, buf)
buf = tmp
}
return buf
}
//go:nosplit
func Ptr2SlicePtr(s unsafe.Pointer, l int, c int) unsafe.Pointer {
slice := &GoSlice{
Ptr: s,
Len: l,
Cap: c,
}
return unsafe.Pointer(slice)
}
//go:nosplit
func StrPtr(s string) unsafe.Pointer {
return (*GoString)(unsafe.Pointer(&s)).Ptr
}
//go:nosplit
func StrFrom(p unsafe.Pointer, n int64) (s string) {
(*GoString)(unsafe.Pointer(&s)).Ptr = p
(*GoString)(unsafe.Pointer(&s)).Len = int(n)
return
}
// NoEscape hides a pointer from escape analysis. NoEscape is
// the identity function but escape analysis doesn't think the
// output depends on the input. NoEscape is inlined and currently
// compiles down to zero instructions.
// USE CAREFULLY!
//go:nosplit
//goland:noinspection GoVetUnsafePointer
func NoEscape(p unsafe.Pointer) unsafe.Pointer {
x := uintptr(p)
return unsafe.Pointer(x ^ 0)
}
//go:nosplit
func MoreStack(size uintptr)
//go:nosplit
func Add(ptr unsafe.Pointer, off uintptr) unsafe.Pointer {
return unsafe.Pointer(uintptr(ptr) + off)
}
// CanSizeResue
func CanSizeResue(cap int) bool {
return cap <= int(option.LimitBufferSize)
}

View File

@@ -0,0 +1,227 @@
/*
* Copyright 2021 ByteDance Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package rt
import (
"reflect"
"unsafe"
)
var (
reflectRtypeItab = findReflectRtypeItab()
)
// GoType.KindFlags const
const (
F_direct = 1 << 5
F_kind_mask = (1 << 5) - 1
)
// GoType.Flags const
const (
tflagUncommon uint8 = 1 << 0
tflagExtraStar uint8 = 1 << 1
tflagNamed uint8 = 1 << 2
tflagRegularMemory uint8 = 1 << 3
)
type GoType struct {
Size uintptr
PtrData uintptr
Hash uint32
Flags uint8
Align uint8
FieldAlign uint8
KindFlags uint8
Traits unsafe.Pointer
GCData *byte
Str int32
PtrToSelf int32
}
func (self *GoType) IsNamed() bool {
return (self.Flags & tflagNamed) != 0
}
func (self *GoType) Kind() reflect.Kind {
return reflect.Kind(self.KindFlags & F_kind_mask)
}
func (self *GoType) Pack() (t reflect.Type) {
(*GoIface)(unsafe.Pointer(&t)).Itab = reflectRtypeItab
(*GoIface)(unsafe.Pointer(&t)).Value = unsafe.Pointer(self)
return
}
func (self *GoType) String() string {
return self.Pack().String()
}
type GoItab struct {
it unsafe.Pointer
Vt *GoType
hv uint32
_ [4]byte
fn [1]uintptr
}
type GoIface struct {
Itab *GoItab
Value unsafe.Pointer
}
type GoEface struct {
Type *GoType
Value unsafe.Pointer
}
func (self GoEface) Pack() (v interface{}) {
*(*GoEface)(unsafe.Pointer(&v)) = self
return
}
type GoPtrType struct {
GoType
Elem *GoType
}
type GoMapType struct {
GoType
Key *GoType
Elem *GoType
Bucket *GoType
Hasher func(unsafe.Pointer, uintptr) uintptr
KeySize uint8
ElemSize uint8
BucketSize uint16
Flags uint32
}
func (self *GoMapType) IndirectElem() bool {
return self.Flags&2 != 0
}
type GoStructType struct {
GoType
Pkg *byte
Fields []GoStructField
}
type GoStructField struct {
Name *byte
Type *GoType
OffEmbed uintptr
}
type GoInterfaceType struct {
GoType
PkgPath *byte
Methods []GoInterfaceMethod
}
type GoInterfaceMethod struct {
Name int32
Type int32
}
type GoSlice struct {
Ptr unsafe.Pointer
Len int
Cap int
}
type GoString struct {
Ptr unsafe.Pointer
Len int
}
func PtrElem(t *GoType) *GoType {
return (*GoPtrType)(unsafe.Pointer(t)).Elem
}
func MapType(t *GoType) *GoMapType {
return (*GoMapType)(unsafe.Pointer(t))
}
func IfaceType(t *GoType) *GoInterfaceType {
return (*GoInterfaceType)(unsafe.Pointer(t))
}
func UnpackType(t reflect.Type) *GoType {
return (*GoType)((*GoIface)(unsafe.Pointer(&t)).Value)
}
func UnpackEface(v interface{}) GoEface {
return *(*GoEface)(unsafe.Pointer(&v))
}
func UnpackIface(v interface{}) GoIface {
return *(*GoIface)(unsafe.Pointer(&v))
}
func findReflectRtypeItab() *GoItab {
v := reflect.TypeOf(struct{}{})
return (*GoIface)(unsafe.Pointer(&v)).Itab
}
func AssertI2I2(t *GoType, i GoIface) (r GoIface) {
inter := IfaceType(t)
tab := i.Itab
if tab == nil {
return
}
if (*GoInterfaceType)(tab.it) != inter {
tab = GetItab(inter, tab.Vt, true)
if tab == nil {
return
}
}
r.Itab = tab
r.Value = i.Value
return
}
func (t *GoType) IsInt64() bool {
return t.Kind() == reflect.Int64 || (t.Kind() == reflect.Int && t.Size == 8)
}
func (t *GoType) IsInt32() bool {
return t.Kind() == reflect.Int32 || (t.Kind() == reflect.Int && t.Size == 4)
}
//go:nosplit
func (t *GoType) IsUint64() bool {
isUint := t.Kind() == reflect.Uint || t.Kind() == reflect.Uintptr
return t.Kind() == reflect.Uint64 || (isUint && t.Size == 8)
}
//go:nosplit
func (t *GoType) IsUint32() bool {
isUint := t.Kind() == reflect.Uint || t.Kind() == reflect.Uintptr
return t.Kind() == reflect.Uint32 || (isUint && t.Size == 4)
}
//go:nosplit
func PtrAdd(ptr unsafe.Pointer, offset uintptr) unsafe.Pointer {
return unsafe.Pointer(uintptr(ptr) + offset)
}
//go:noescape
//go:linkname GetItab runtime.getitab
func GetItab(inter *GoInterfaceType, typ *GoType, canfail bool) *GoItab

85
vendor/github.com/bytedance/sonic/internal/rt/gcwb.go generated vendored Normal file
View File

@@ -0,0 +1,85 @@
// +build go1.21,!go1.27
/*
* Copyright 2021 ByteDance Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package rt
import (
`sync/atomic`
`unsafe`
`golang.org/x/arch/x86/x86asm`
)
//go:linkname GcWriteBarrier2 runtime.gcWriteBarrier2
func GcWriteBarrier2()
//go:linkname RuntimeWriteBarrier runtime.writeBarrier
var RuntimeWriteBarrier uintptr
const (
_MaxInstr = 15
)
func isvar(arg x86asm.Arg) bool {
v, ok := arg.(x86asm.Mem)
return ok && v.Base == x86asm.RIP
}
func iszero(arg x86asm.Arg) bool {
v, ok := arg.(x86asm.Imm)
return ok && v == 0
}
func GcwbAddr() uintptr {
var err error
var off uintptr
var ins x86asm.Inst
/* get the function address */
pc := uintptr(0)
fp := FuncAddr(atomic.StorePointer)
/* search within the first 16 instructions */
for i := 0; i < 16; i++ {
mem := unsafe.Pointer(uintptr(fp) + pc)
buf := BytesFrom(mem, _MaxInstr, _MaxInstr)
/* disassemble the instruction */
if ins, err = x86asm.Decode(buf, 64); err != nil {
panic("gcwbaddr: " + err.Error())
}
/* check for a byte comparison with zero */
if ins.Op == x86asm.CMP && ins.MemBytes == 1 && isvar(ins.Args[0]) && iszero(ins.Args[1]) {
off = pc + uintptr(ins.Len) + uintptr(ins.Args[0].(x86asm.Mem).Disp)
break
}
/* move to next instruction */
nb := ins.Len
pc += uintptr(nb)
}
/* check for address */
if off == 0 {
panic("gcwbaddr: could not locate the variable `writeBarrier`")
} else {
return uintptr(fp) + off
}
}

View File

@@ -0,0 +1,29 @@
// +build go1.17,!go1.21
/*
* Copyright 2021 ByteDance Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package rt
import (
_ `unsafe`
)
//go:linkname GcWriteBarrierAX runtime.gcWriteBarrier
func GcWriteBarrierAX()
//go:linkname RuntimeWriteBarrier runtime.writeBarrier
var RuntimeWriteBarrier uintptr

View File

@@ -0,0 +1,25 @@
//go:build go1.26
// +build go1.26
/*
* Copyright 2021 ByteDance Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package rt
// In Go 1.26+, TFlagDirectIface is in the TFlag (Flags) field, not Kind_.
func (self *GoType) Indirect() bool {
return self.Flags&F_direct == 0
}

View File

@@ -0,0 +1,25 @@
//go:build !go1.26
// +build !go1.26
/*
* Copyright 2021 ByteDance Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package rt
// In Go < 1.26, KindDirectIface is in the Kind_ (KindFlags) field.
func (self *GoType) Indirect() bool {
return self.KindFlags&F_direct == 0
}

View File

@@ -0,0 +1,36 @@
// +build go1.20
/*
* Copyright 2021 ByteDance Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package rt
import "unsafe"
// Growslice to newCap, not append length
// Note: the [old, newCap) will not be zeroed if et does not have any ptr data.
func GrowSlice(et *GoType, old GoSlice, newCap int) GoSlice {
if newCap < old.Len {
panic("growslice's newCap is smaller than old length")
}
s := growslice(old.Ptr, newCap, old.Cap, newCap - old.Len, et)
s.Len = old.Len
return s
}
//go:linkname growslice runtime.growslice
//goland:noinspection GoUnusedParameter
func growslice(oldPtr unsafe.Pointer, newLen, oldCap, num int, et *GoType) GoSlice

View File

@@ -0,0 +1,27 @@
// +build go1.16,!go1.20
/*
* Copyright 2021 ByteDance Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package rt
import (
_ `unsafe`
)
//go:linkname GrowSlice runtime.growslice
//goland:noinspection GoUnusedParameter
func GrowSlice(et *GoType, old GoSlice, cap int) GoSlice

36
vendor/github.com/bytedance/sonic/internal/rt/int48.go generated vendored Normal file
View File

@@ -0,0 +1,36 @@
/*
* Copyright 2021 ByteDance Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package rt
const (
MinInt48 int64 = -(1 << 47)
MaxInt48 int64 = +(1 << 47) - 1
)
func PackInt(v int) uint64 {
if u := uint64(v); int64(v) < MinInt48 || int64(v) > MaxInt48 {
panic("int48 out of range")
} else {
return ((u >> 63) << 47) | (u & 0x00007fffffffffff)
}
}
func UnpackInt(v uint64) int {
v &= 0x0000ffffffffffff
v |= (v >> 47) * (0xffff << 48)
return int(v)
}

View File

@@ -0,0 +1,28 @@
//go:build go1.24 && !go1.26 && !goexperiment.swissmap
// +build go1.24,!go1.26,!goexperiment.swissmap
package rt
import (
"unsafe"
)
type GoMapIterator struct {
K unsafe.Pointer
V unsafe.Pointer
T *GoMapType
H unsafe.Pointer
Buckets unsafe.Pointer
Bptr *unsafe.Pointer
Overflow *[]unsafe.Pointer
OldOverflow *[]unsafe.Pointer
StartBucket uintptr
Offset uint8
Wrapped bool
B uint8
I uint8
Bucket uintptr
CheckBucket uintptr
// different from go1.23
ClearSeq uint64
}

View File

@@ -0,0 +1,15 @@
//go:build go1.26 || goexperiment.swissmap
// +build go1.26 goexperiment.swissmap
package rt
import (
"unsafe"
)
type GoMapIterator struct {
K unsafe.Pointer
V unsafe.Pointer
T *GoMapType
It unsafe.Pointer
}

View File

@@ -0,0 +1,25 @@
// +build !go1.24
package rt
import (
"unsafe"
)
type GoMapIterator struct {
K unsafe.Pointer
V unsafe.Pointer
T *GoMapType
H unsafe.Pointer
Buckets unsafe.Pointer
Bptr *unsafe.Pointer
Overflow *[]unsafe.Pointer
OldOverflow *[]unsafe.Pointer
StartBucket uintptr
Offset uint8
Wrapped bool
B uint8
I uint8
Bucket uintptr
CheckBucket uintptr
}

31
vendor/github.com/bytedance/sonic/internal/rt/pool.go generated vendored Normal file
View File

@@ -0,0 +1,31 @@
package rt
import (
"unsafe"
)
type SlicePool struct {
pool unsafe.Pointer
len int
index int
typ uintptr
}
func NewPool(typ *GoType, size int) SlicePool {
return SlicePool{pool: newarray(typ, size), len: size, typ: uintptr(unsafe.Pointer(typ))}
}
func (self *SlicePool) GetSlice(size int) unsafe.Pointer {
// pool is full, fallback to normal alloc
if size > self.Remain() {
return newarray(AsGoType(self.typ), size)
}
ptr := PtrAdd(self.pool, uintptr(self.index)* AsGoType(self.typ).Size)
self.index += size
return ptr
}
func (self *SlicePool) Remain() int {
return self.len - self.index
}

197
vendor/github.com/bytedance/sonic/internal/rt/stubs.go generated vendored Normal file
View File

@@ -0,0 +1,197 @@
/*
* Copyright 2021 ByteDance Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package rt
import (
"reflect"
"unsafe"
)
//go:noescape
//go:linkname Memmove runtime.memmove
func Memmove(to unsafe.Pointer, from unsafe.Pointer, n uintptr)
//go:noescape
//go:linkname MemEqual runtime.memequal
//goland:noinspection GoUnusedParameter
func MemEqual(a unsafe.Pointer, b unsafe.Pointer, size uintptr) bool
//go:linkname Mapiternext runtime.mapiternext
func Mapiternext(it *GoMapIterator)
//go:linkname Mapiterinit runtime.mapiterinit
func Mapiterinit(t *GoMapType, m unsafe.Pointer, it *GoMapIterator)
//go:linkname Maplen reflect.maplen
func Maplen(h unsafe.Pointer) int
//go:nosplit
//go:linkname MemclrHasPointers runtime.memclrHasPointers
//goland:noinspection GoUnusedParameter
func MemclrHasPointers(ptr unsafe.Pointer, n uintptr)
//go:linkname MemclrNoHeapPointers runtime.memclrNoHeapPointers
//goland:noinspection GoUnusedParameter
func MemclrNoHeapPointers(ptr unsafe.Pointer, n uintptr)
//go:linkname newarray runtime.newarray
func newarray(typ *GoType, n int) unsafe.Pointer
func add(p unsafe.Pointer, x uintptr) unsafe.Pointer {
return unsafe.Pointer(uintptr(p) + x)
}
func ClearMemory(et *GoType, ptr unsafe.Pointer, size uintptr) {
if et.PtrData == 0 {
MemclrNoHeapPointers(ptr, size)
} else {
MemclrHasPointers(ptr, size)
}
}
// runtime.maxElementSize
const _max_map_element_size uintptr = 128
func IsMapfast(vt reflect.Type) bool {
return vt.Elem().Size() <= _max_map_element_size
}
//go:linkname Mallocgc runtime.mallocgc
//goland:noinspection GoUnusedParameter
func Mallocgc(size uintptr, typ *GoType, needzero bool) unsafe.Pointer
//go:linkname Makemap reflect.makemap
func Makemap(*GoType, int) unsafe.Pointer
//go:linkname MakemapSmall runtime.makemap_small
func MakemapSmall() unsafe.Pointer
//go:linkname Mapassign runtime.mapassign
//goland:noinspection GoUnusedParameter
func Mapassign(t *GoMapType, h unsafe.Pointer, k unsafe.Pointer) unsafe.Pointer
//go:linkname Mapassign_fast32 runtime.mapassign_fast32
//goland:noinspection GoUnusedParameter
func Mapassign_fast32(t *GoMapType, h unsafe.Pointer, k uint32) unsafe.Pointer
//go:linkname Mapassign_fast64 runtime.mapassign_fast64
//goland:noinspection GoUnusedParameter
func Mapassign_fast64(t *GoMapType, h unsafe.Pointer, k uint64) unsafe.Pointer
//go:linkname Mapassign_faststr runtime.mapassign_faststr
//goland:noinspection GoUnusedParameter
func Mapassign_faststr(t *GoMapType, h unsafe.Pointer, s string) unsafe.Pointer
type MapStrAssign func (t *GoMapType, h unsafe.Pointer, s string) unsafe.Pointer
func GetMapStrAssign(vt reflect.Type) MapStrAssign {
if IsMapfast(vt) {
return Mapassign_faststr
} else {
return func (t *GoMapType, h unsafe.Pointer, s string) unsafe.Pointer {
return Mapassign(t, h, unsafe.Pointer(&s))
}
}
}
type Map32Assign func(t *GoMapType, h unsafe.Pointer, k uint32) unsafe.Pointer
func GetMap32Assign(vt reflect.Type) Map32Assign {
if IsMapfast(vt) {
return Mapassign_fast32
} else {
return func (t *GoMapType, h unsafe.Pointer, s uint32) unsafe.Pointer {
return Mapassign(t, h, unsafe.Pointer(&s))
}
}
}
type Map64Assign func(t *GoMapType, h unsafe.Pointer, k uint64) unsafe.Pointer
func GetMap64Assign(vt reflect.Type) Map64Assign {
if IsMapfast(vt) {
return Mapassign_fast64
} else {
return func (t *GoMapType, h unsafe.Pointer, s uint64) unsafe.Pointer {
return Mapassign(t, h, unsafe.Pointer(&s))
}
}
}
var emptyBytes = make([]byte, 0, 0)
var EmptySlice = *(*GoSlice)(unsafe.Pointer(&emptyBytes))
//go:linkname MakeSliceStd runtime.makeslice
//goland:noinspection GoUnusedParameter
func MakeSliceStd(et *GoType, len int, cap int) unsafe.Pointer
func MakeSlice(oldPtr unsafe.Pointer, et *GoType, newLen int) *GoSlice {
if newLen == 0 {
return &EmptySlice
}
if *(*unsafe.Pointer)(oldPtr) == nil {
return &GoSlice{
Ptr: MakeSliceStd(et, newLen, newLen),
Len: newLen,
Cap: newLen,
}
}
old := (*GoSlice)(oldPtr)
if old.Cap >= newLen {
old.Len = newLen
return old
}
new := GrowSlice(et, *old, newLen)
// we should clear the memory from [oldLen:newLen]
if et.PtrData == 0 {
oldlenmem := uintptr(old.Len) * et.Size
newlenmem := uintptr(newLen) * et.Size
MemclrNoHeapPointers(add(new.Ptr, oldlenmem), newlenmem-oldlenmem)
}
new.Len = newLen
return &new
}
//go:nosplit
//go:linkname Throw runtime.throw
//goland:noinspection GoUnusedParameter
func Throw(s string)
//go:linkname ConvT64 runtime.convT64
//goland:noinspection GoUnusedParameter
func ConvT64(v uint64) unsafe.Pointer
//go:linkname ConvTslice runtime.convTslice
//goland:noinspection GoUnusedParameter
func ConvTslice(v []byte) unsafe.Pointer
//go:linkname ConvTstring runtime.convTstring
//goland:noinspection GoUnusedParameter
func ConvTstring(v string) unsafe.Pointer
//go:linkname Mapassign_fast64ptr runtime.mapassign_fast64ptr
//goland:noinspection GoUnusedParameter
func Mapassign_fast64ptr(t *GoMapType, h unsafe.Pointer, k unsafe.Pointer) unsafe.Pointer
//go:noescape
//go:linkname Strhash runtime.strhash
func Strhash(_ unsafe.Pointer, _ uintptr) uintptr

118
vendor/github.com/bytedance/sonic/internal/rt/table.go generated vendored Normal file
View File

@@ -0,0 +1,118 @@
// Copyright 2024 CloudWeGo Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package rt
import "unicode/utf8"
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,
}
var Hex = "0123456789abcdef"

45
vendor/github.com/bytedance/sonic/internal/rt/types.go generated vendored Normal file
View File

@@ -0,0 +1,45 @@
package rt
import (
"reflect"
"unsafe"
"encoding/json"
)
func AsGoType(t uintptr) *GoType {
return (*GoType)(unsafe.Pointer(t))
}
var (
BoolType = UnpackType(reflect.TypeOf(false))
ByteType = UnpackType(reflect.TypeOf(byte(0)))
IncntType = UnpackType(reflect.TypeOf(int(0)))
Int8Type = UnpackType(reflect.TypeOf(int8(0)))
Int16Type = UnpackType(reflect.TypeOf(int16(0)))
Int32Type = UnpackType(reflect.TypeOf(int32(0)))
Int64Type = UnpackType(reflect.TypeOf(int64(0)))
UintType = UnpackType(reflect.TypeOf(uint(0)))
Uint8Type = UnpackType(reflect.TypeOf(uint8(0)))
Uint16Type = UnpackType(reflect.TypeOf(uint16(0)))
Uint32Type = UnpackType(reflect.TypeOf(uint32(0)))
Uint64Type = UnpackType(reflect.TypeOf(uint64(0)))
Float32Type = UnpackType(reflect.TypeOf(float32(0)))
Float64Type = UnpackType(reflect.TypeOf(float64(0)))
StringType = UnpackType(reflect.TypeOf(""))
BytesType = UnpackType(reflect.TypeOf([]byte(nil)))
JsonNumberType = UnpackType(reflect.TypeOf(json.Number("")))
SliceEfaceType = UnpackType(reflect.TypeOf([]interface{}(nil)))
SliceStringType = UnpackType(reflect.TypeOf([]string(nil)))
SliceI32Type = UnpackType(reflect.TypeOf([]int32(nil)))
SliceI64Type = UnpackType(reflect.TypeOf([]int64(nil)))
SliceU32Type = UnpackType(reflect.TypeOf([]uint32(nil)))
SliceU64Type = UnpackType(reflect.TypeOf([]uint64(nil)))
AnyType = UnpackType(reflect.TypeOf((*interface{})(nil)).Elem())
MapEfaceType = UnpackType(reflect.TypeOf(map[string]interface{}(nil)))
MapStringType = UnpackType(reflect.TypeOf(map[string]string(nil)))
MapEfaceMapType = MapType(UnpackType(reflect.TypeOf(map[string]interface{}(nil))))
)