[chore]: Bump github.com/gin-contrib/gzip from 1.2.2 to 1.2.3

Bumps [github.com/gin-contrib/gzip](https://github.com/gin-contrib/gzip) from 1.2.2 to 1.2.3.
- [Release notes](https://github.com/gin-contrib/gzip/releases)
- [Changelog](https://github.com/gin-contrib/gzip/blob/master/.goreleaser.yaml)
- [Commits](https://github.com/gin-contrib/gzip/compare/v1.2.2...v1.2.3)

---
updated-dependencies:
- dependency-name: github.com/gin-contrib/gzip
  dependency-version: 1.2.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
dependabot[bot] 2025-04-14 06:15:04 +00:00 committed by GitHub
commit 41a5f6e513
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
220 changed files with 127887 additions and 125516 deletions

View file

@ -35,6 +35,7 @@ const (
_F_use_int64 = consts.F_use_int64
_F_use_number = consts.F_use_number
_F_validate_string = consts.F_validate_string
_F_case_sensitive = consts.F_case_sensitive
_MaxStack = consts.MaxStack
@ -45,6 +46,7 @@ const (
OptionCopyString = consts.OptionCopyString
OptionValidateString = consts.OptionValidateString
OptionNoValidateJSON = consts.OptionNoValidateJSON
OptionCaseSensitive = consts.OptionCaseSensitive
)
type (

View file

@ -1,5 +1,5 @@
//go:build go1.17 && !go1.24
// +build go1.17,!go1.24
//go:build go1.17 && !go1.25
// +build go1.17,!go1.25
/*
* Copyright 2021 ByteDance Inc.

View file

@ -1,4 +1,4 @@
// +build go1.17,!go1.24
// +build go1.17,!go1.25
/*
* Copyright 2021 ByteDance Inc.

View file

@ -12,11 +12,11 @@ const (
F_disable_unknown = 3
F_copy_string = 4
F_use_number = types.B_USE_NUMBER
F_validate_string = types.B_VALIDATE_STRING
F_allow_control = types.B_ALLOW_CONTROL
F_no_validate_json = types.B_NO_VALIDATE_JSON
F_case_sensitive = 7
)
type Options uint64
@ -29,6 +29,7 @@ const (
OptionCopyString Options = 1 << F_copy_string
OptionValidateString Options = 1 << F_validate_string
OptionNoValidateJSON Options = 1 << F_no_validate_json
OptionCaseSensitive Options = 1 << F_case_sensitive
)
const (

View file

@ -20,21 +20,16 @@ import (
`strconv`
`unsafe`
`github.com/bytedance/sonic/internal/rt`
`github.com/bytedance/sonic/internal/jit`
`github.com/twitchyliquid64/golang-asm/obj`
`github.com/twitchyliquid64/golang-asm/obj/x86`
)
//go:linkname _runtime_writeBarrier runtime.writeBarrier
var _runtime_writeBarrier uintptr
//go:linkname gcWriteBarrierAX runtime.gcWriteBarrier
func gcWriteBarrierAX()
var (
_V_writeBarrier = jit.Imm(int64(uintptr(unsafe.Pointer(&_runtime_writeBarrier))))
_V_writeBarrier = jit.Imm(int64(uintptr(unsafe.Pointer(&rt.RuntimeWriteBarrier))))
_F_gcWriteBarrierAX = jit.Func(gcWriteBarrierAX)
_F_gcWriteBarrierAX = jit.Func(rt.GcWriteBarrierAX)
)
func (self *_Assembler) WritePtrAX(i int, rec obj.Addr, saveDI bool) {

View file

@ -1,4 +1,4 @@
// +build go1.21,!go1.24
// +build go1.21,!go1.25
// Copyright 2023 CloudWeGo Authors
//
@ -20,25 +20,19 @@ import (
`strconv`
`unsafe`
`github.com/bytedance/sonic/internal/rt`
`github.com/bytedance/sonic/internal/jit`
`github.com/twitchyliquid64/golang-asm/obj`
`github.com/twitchyliquid64/golang-asm/obj/x86`
)
//go:linkname _runtime_writeBarrier runtime.writeBarrier
var _runtime_writeBarrier uintptr
//go:nosplit
//go:linkname gcWriteBarrier2 runtime.gcWriteBarrier2
func gcWriteBarrier2()
// Notice: gcWriteBarrier must use R11 register!!
var _R11 = _IC
var (
_V_writeBarrier = jit.Imm(int64(uintptr(unsafe.Pointer(&_runtime_writeBarrier))))
_V_writeBarrier = jit.Imm(int64(uintptr(unsafe.Pointer(&rt.RuntimeWriteBarrier))))
_F_gcWriteBarrier2 = jit.Func(gcWriteBarrier2)
_F_gcWriteBarrier2 = jit.Func(rt.GcWriteBarrier2)
)
func (self *_Assembler) WritePtrAX(i int, rec obj.Addr, saveDI bool) {

View file

@ -1,5 +1,5 @@
//go:build go1.17 && !go1.24
// +build go1.17,!go1.24
//go:build go1.17 && !go1.25
// +build go1.17,!go1.25
/*
* Copyright 2021 ByteDance Inc.
@ -271,6 +271,7 @@ var _OpFuncTab = [256]func(*_Assembler, *_Instr) {
_OP_nil_1 : (*_Assembler)._asm_OP_nil_1,
_OP_nil_2 : (*_Assembler)._asm_OP_nil_2,
_OP_nil_3 : (*_Assembler)._asm_OP_nil_3,
_OP_empty_bytes : (*_Assembler)._asm_OP_empty_bytes,
_OP_deref : (*_Assembler)._asm_OP_deref,
_OP_index : (*_Assembler)._asm_OP_index,
_OP_is_null : (*_Assembler)._asm_OP_is_null,
@ -313,9 +314,10 @@ var _OpFuncTab = [256]func(*_Assembler, *_Instr) {
_OP_check_char_0 : (*_Assembler)._asm_OP_check_char_0,
_OP_dismatch_err : (*_Assembler)._asm_OP_dismatch_err,
_OP_go_skip : (*_Assembler)._asm_OP_go_skip,
_OP_skip_emtpy : (*_Assembler)._asm_OP_skip_empty,
_OP_skip_emtpy : (*_Assembler)._asm_OP_skip_empty,
_OP_add : (*_Assembler)._asm_OP_add,
_OP_check_empty : (*_Assembler)._asm_OP_check_empty,
_OP_unsupported : (*_Assembler)._asm_OP_unsupported,
_OP_debug : (*_Assembler)._asm_OP_debug,
}
@ -456,7 +458,7 @@ func (self *_Assembler) call_vf(fn obj.Addr) {
/** Assembler Error Handlers **/
var (
_F_convT64 = jit.Func(convT64)
_F_convT64 = jit.Func(rt.ConvT64)
_F_error_wrap = jit.Func(error_wrap)
_F_error_type = jit.Func(error_type)
_F_error_field = jit.Func(error_field)
@ -598,7 +600,6 @@ func (self *_Assembler) _asm_OP_dismatch_err(p *_Instr) {
func (self *_Assembler) _asm_OP_go_skip(p *_Instr) {
self.Byte(0x4c, 0x8d, 0x0d) // LEAQ (PC), R9
self.Xref(p.vi(), 4)
// self.Byte(0xcc)
self.Emit("MOVQ", _R9, _VAR_pc)
self.Sjmp("JMP" , _LB_skip_one) // JMP _skip_one
}
@ -606,9 +607,7 @@ func (self *_Assembler) _asm_OP_go_skip(p *_Instr) {
var _F_IndexByte = jit.Func(strings.IndexByte)
func (self *_Assembler) _asm_OP_skip_empty(p *_Instr) {
// self.Byte(0xcc)
self.call_sf(_F_skip_one) // CALL_SF skip_one
// self.Byte(0xcc)
self.Emit("TESTQ", _AX, _AX) // TESTQ AX, AX
self.Sjmp("JS" , _LB_parsing_error_v) // JS _parse_error_v
self.Emit("BTQ", jit.Imm(_F_disable_unknown), _ARG_fv)
@ -619,7 +618,6 @@ func (self *_Assembler) _asm_OP_skip_empty(p *_Instr) {
self.Emit("MOVQ", _AX, _ARG_sv_p)
self.Emit("MOVQ", jit.Imm(':'), _CX)
self.call_go(_F_IndexByte)
// self.Byte(0xcc)
self.Emit("TESTQ", _AX, _AX)
// disallow unknown field
self.Sjmp("JNS", _LB_field_error)
@ -662,7 +660,7 @@ func (self *_Assembler) skip_key_value() {
var (
_T_byte = jit.Type(byteType)
_F_mallocgc = jit.Func(mallocgc)
_F_mallocgc = jit.Func(rt.Mallocgc)
)
func (self *_Assembler) malloc_AX(nb obj.Addr, ret obj.Addr) {
@ -964,8 +962,8 @@ func (self *_Assembler) unquote_twice(p obj.Addr, n obj.Addr, stack bool) {
/** Memory Clearing Routines **/
var (
_F_memclrHasPointers = jit.Func(memclrHasPointers)
_F_memclrNoHeapPointers = jit.Func(memclrNoHeapPointers)
_F_memclrHasPointers = jit.Func(rt.MemclrHasPointers)
_F_memclrNoHeapPointers = jit.Func(rt.MemclrNoHeapPointers)
)
func (self *_Assembler) mem_clear_fn(ptrfree bool) {
@ -989,10 +987,10 @@ func (self *_Assembler) mem_clear_rem(size int64, ptrfree bool) {
/** Map Assigning Routines **/
var (
_F_mapassign = jit.Func(mapassign)
_F_mapassign_fast32 = jit.Func(mapassign_fast32)
_F_mapassign_faststr = jit.Func(mapassign_faststr)
_F_mapassign_fast64ptr = jit.Func(mapassign_fast64ptr)
_F_mapassign = jit.Func(rt.Mapassign)
_F_mapassign_fast32 = jit.Func(rt.Mapassign_fast32)
_F_mapassign_faststr = jit.Func(rt.Mapassign_faststr)
_F_mapassign_fast64ptr = jit.Func(rt.Mapassign_fast64ptr)
)
var (
@ -1183,12 +1181,12 @@ func (self *_Assembler) decode_dynamic(vt obj.Addr, vp obj.Addr) {
/** OpCode Assembler Functions **/
var (
_F_memequal = jit.Func(memequal)
_F_memmove = jit.Func(memmove)
_F_memequal = jit.Func(rt.MemEqual)
_F_memmove = jit.Func(rt.Memmove)
_F_growslice = jit.Func(rt.GrowSlice)
_F_makeslice = jit.Func(makeslice)
_F_makemap_small = jit.Func(makemap_small)
_F_mapassign_fast64 = jit.Func(mapassign_fast64)
_F_makeslice = jit.Func(rt.MakeSliceStd)
_F_makemap_small = jit.Func(rt.MakemapSmall)
_F_mapassign_fast64 = jit.Func(rt.Mapassign_fast64)
)
var (
@ -1197,7 +1195,7 @@ var (
)
var (
_F_b64decode = jit.Imm(int64(_subr__b64decode))
_F_b64decode = jit.Imm(int64(rt.SubrB64Decode))
_F_decodeValue = jit.Imm(int64(_subr_decode_value))
)
@ -1253,18 +1251,42 @@ func (self *_Assembler) _asm_OP_any(_ *_Instr) {
func (self *_Assembler) _asm_OP_dyn(p *_Instr) {
self.Emit("MOVQ" , jit.Type(p.vt()), _ET) // MOVQ ${p.vt()}, ET
self.Emit("CMPQ" , jit.Ptr(_VP, 8), jit.Imm(0)) // CMPQ 8(VP), $0
self.Sjmp("JE" , _LB_type_error) // JE _type_error
self.Sjmp("JNE" , "_decode_dyn_non_nil_{n}") // JE _type_error
/* if nil iface, call skip one */
self.Emit("MOVQ", _IC, _VAR_ic)
self.Emit("MOVQ", _ET, _VAR_et)
self.Byte(0x4c, 0x8d, 0x0d)
self.Sref("_decode_end_{n}", 4)
self.Emit("MOVQ", _R9, _VAR_pc)
self.Sjmp("JMP" , _LB_skip_one)
self.Link("_decode_dyn_non_nil_{n}") // _decode_dyn_non_nil_{n}:
self.Emit("MOVQ" , jit.Ptr(_VP, 0), _CX) // MOVQ (VP), CX
self.Emit("MOVQ" , jit.Ptr(_CX, 8), _CX) // MOVQ 8(CX), CX
self.Emit("MOVBLZX", jit.Ptr(_CX, _Gt_KindFlags), _DX) // MOVBLZX _Gt_KindFlags(CX), DX
self.Emit("ANDL" , jit.Imm(rt.F_kind_mask), _DX) // ANDL ${F_kind_mask}, DX
self.Emit("CMPL" , _DX, jit.Imm(_Vk_Ptr)) // CMPL DX, ${reflect.Ptr}
self.Sjmp("JNE" , _LB_type_error) // JNE _type_error
self.Sjmp("JE" , "_decode_dyn_ptr_{n}") // JNE _type_error
self.Emit("MOVQ", _IC, _VAR_ic)
self.Emit("MOVQ", _ET, _VAR_et)
self.Byte(0x4c, 0x8d, 0x0d)
self.Sref("_decode_end_{n}", 4)
self.Emit("MOVQ", _R9, _VAR_pc)
self.Sjmp("JMP" , _LB_skip_one)
self.Link("_decode_dyn_ptr_{n}") // _decode_dyn_ptr_{n}:
self.Emit("LEAQ" , jit.Ptr(_VP, 8), _DI) // LEAQ 8(VP), DI
self.decode_dynamic(_CX, _DI) // DECODE CX, DI
self.Link("_decode_end_{n}") // _decode_end_{n}:
}
func (self *_Assembler) _asm_OP_unsupported(p *_Instr) {
self.Emit("MOVQ", jit.Type(p.vt()), _ET) // MOVQ ${p.vt()}, ET
self.Sjmp("JMP" , _LB_type_error) // JMP _LB_type_error
}
func (self *_Assembler) _asm_OP_str(_ *_Instr) {
self.parse_string() // PARSE STRING
self.unquote_once(jit.Ptr(_VP, 0), jit.Ptr(_VP, 8), false, true) // UNQUOTE once, (VP), 8(VP)
@ -1488,6 +1510,19 @@ func (self *_Assembler) _asm_OP_nil_3(_ *_Instr) {
self.Emit("MOVQ" , _AX, jit.Ptr(_VP, 16)) // MOVOU AX, 16(VP)
}
var (
bytes []byte = make([]byte, 0)
zerobytes = (*rt.GoSlice)(unsafe.Pointer(&bytes)).Ptr
_ZERO_PTR = jit.Imm(int64(uintptr(zerobytes)))
)
func (self *_Assembler) _asm_OP_empty_bytes(_ *_Instr) {
self.Emit("MOVQ", _ZERO_PTR, _AX)
self.Emit("PXOR" , _X0, _X0)
self.Emit("MOVQ", _AX, jit.Ptr(_VP, 0))
self.Emit("MOVOU", _X0, jit.Ptr(_VP, 8))
}
func (self *_Assembler) _asm_OP_deref(p *_Instr) {
self.vfollow(p.vt())
}
@ -1547,7 +1582,7 @@ func (self *_Assembler) _asm_OP_map_key_i32(p *_Instr) {
self.parse_signed(int32Type, "", p.vi()) // PARSE int32
self.range_signed_CX(_I_int32, _T_int32, math.MinInt32, math.MaxInt32) // RANGE int32
self.match_char('"')
if vt := p.vt(); !mapfast(vt) {
if vt := p.vt(); !rt.IsMapfast(vt) {
self.mapassign_std(vt, _VAR_st_Iv) // MAPASSIGN int32, mapassign, st.Iv
} else {
self.Emit("MOVQ", _CX, _AX) // MOVQ CX, AX
@ -1558,7 +1593,7 @@ func (self *_Assembler) _asm_OP_map_key_i32(p *_Instr) {
func (self *_Assembler) _asm_OP_map_key_i64(p *_Instr) {
self.parse_signed(int64Type, "", p.vi()) // PARSE int64
self.match_char('"')
if vt := p.vt(); !mapfast(vt) {
if vt := p.vt(); !rt.IsMapfast(vt) {
self.mapassign_std(vt, _VAR_st_Iv) // MAPASSIGN int64, mapassign, st.Iv
} else {
self.Emit("MOVQ", _VAR_st_Iv, _AX) // MOVQ st.Iv, AX
@ -1584,7 +1619,7 @@ func (self *_Assembler) _asm_OP_map_key_u32(p *_Instr) {
self.parse_unsigned(uint32Type, "", p.vi()) // PARSE uint32
self.range_unsigned_CX(_I_uint32, _T_uint32, math.MaxUint32) // RANGE uint32
self.match_char('"')
if vt := p.vt(); !mapfast(vt) {
if vt := p.vt(); !rt.IsMapfast(vt) {
self.mapassign_std(vt, _VAR_st_Iv) // MAPASSIGN uint32, vt.Iv
} else {
self.Emit("MOVQ", _CX, _AX) // MOVQ CX, AX
@ -1595,7 +1630,7 @@ func (self *_Assembler) _asm_OP_map_key_u32(p *_Instr) {
func (self *_Assembler) _asm_OP_map_key_u64(p *_Instr) {
self.parse_unsigned(uint64Type, "", p.vi()) // PARSE uint64
self.match_char('"')
if vt := p.vt(); !mapfast(vt) {
if vt := p.vt(); !rt.IsMapfast(vt) {
self.mapassign_std(vt, _VAR_st_Iv) // MAPASSIGN uint64, vt.Iv
} else {
self.Emit("MOVQ", _VAR_st_Iv, _AX) // MOVQ st.Iv, AX
@ -1620,7 +1655,7 @@ func (self *_Assembler) _asm_OP_map_key_f64(p *_Instr) {
func (self *_Assembler) _asm_OP_map_key_str(p *_Instr) {
self.parse_string() // PARSE STRING
self.unquote_once(_ARG_sv_p, _ARG_sv_n, true, true) // UNQUOTE once, sv.p, sv.n
if vt := p.vt(); !mapfast(vt) {
if vt := p.vt(); !rt.IsMapfast(vt) {
self.valloc(vt.Key(), _DI)
self.Emit("MOVOU", _ARG_sv, _X0)
self.Emit("MOVOU", _X0, jit.Ptr(_DI, 0))
@ -1794,6 +1829,8 @@ func (self *_Assembler) _asm_OP_struct_field(p *_Instr) {
self.Emit("MOVQ" , _R8, _VAR_sr) // MOVQ R8, sr
self.Sjmp("JMP" , "_end_{n}") // JMP _end_{n}
self.Link("_try_lowercase_{n}") // _try_lowercase_{n}:
self.Emit("BTQ" , jit.Imm(_F_case_sensitive), _ARG_fv) // check if enable option CaseSensitive
self.Sjmp("JC" , "_unknown_{n}")
self.Emit("MOVQ" , jit.Imm(referenceFields(p.vf())), _AX) // MOVQ ${p.vf()}, AX
self.Emit("MOVQ", _ARG_sv_p, _BX) // MOVQ sv, BX
self.Emit("MOVQ", _ARG_sv_n, _CX) // MOVQ sv, CX
@ -1801,6 +1838,10 @@ func (self *_Assembler) _asm_OP_struct_field(p *_Instr) {
self.Emit("MOVQ" , _AX, _VAR_sr) // MOVQ AX, _VAR_sr
self.Emit("TESTQ", _AX, _AX) // TESTQ AX, AX
self.Sjmp("JNS" , "_end_{n}") // JNS _end_{n}
self.Link("_unknown_{n}")
// HACK: because `_VAR_sr` maybe used in `F_vstring`, so we should clear here again for `_OP_switch`.
self.Emit("MOVQ" , jit.Imm(-1), _AX) // MOVQ $-1, AX
self.Emit("MOVQ" , _AX, _VAR_sr) // MOVQ AX, sr
self.Emit("BTQ" , jit.Imm(_F_disable_unknown), _ARG_fv) // BTQ ${_F_disable_unknown}, fv
self.Sjmp("JC" , _LB_field_error) // JC _field_error
self.Link("_end_{n}") // _end_{n}:

View file

@ -54,6 +54,7 @@ const (
_OP_nil_1
_OP_nil_2
_OP_nil_3
_OP_empty_bytes
_OP_deref
_OP_index
_OP_is_null
@ -99,6 +100,7 @@ const (
_OP_skip_emtpy
_OP_add
_OP_check_empty
_OP_unsupported
_OP_debug
)
@ -134,6 +136,7 @@ var _OpNames = [256]string {
_OP_nil_1 : "nil_1",
_OP_nil_2 : "nil_2",
_OP_nil_3 : "nil_3",
_OP_empty_bytes : "empty bytes",
_OP_deref : "deref",
_OP_index : "index",
_OP_is_null : "is_null",
@ -176,6 +179,7 @@ var _OpNames = [256]string {
_OP_add : "add",
_OP_go_skip : "go_skip",
_OP_check_empty : "check_empty",
_OP_unsupported : "unsupported type",
_OP_debug : "debug",
}
@ -630,10 +634,17 @@ func (self *_Compiler) compileOps(p *_Program, sp int, vt reflect.Type) {
case reflect.Ptr : self.compilePtr (p, sp, vt)
case reflect.Slice : self.compileSlice (p, sp, vt)
case reflect.Struct : self.compileStruct (p, sp, vt)
default : panic (&json.UnmarshalTypeError{Type: vt})
default : self.compileUnsupportedType (p, vt)
}
}
func (self *_Compiler) compileUnsupportedType(p *_Program, vt reflect.Type) {
i := p.pc()
p.add(_OP_is_null)
p.rtt(_OP_unsupported, vt)
p.pin(i)
}
func (self *_Compiler) compileMap(p *_Program, sp int, vt reflect.Type) {
if reflect.PtrTo(vt.Key()).Implements(encodingTextUnmarshalerType) {
self.compileMapOp(p, sp, vt, _OP_map_key_utext_p)
@ -819,12 +830,19 @@ func (self *_Compiler) compileSliceBin(p *_Program, sp int, vt reflect.Type) {
self.compileSliceBody(p, sp, vt.Elem())
y := p.pc()
p.add(_OP_goto)
// unmarshal `null` and `"` is different
p.pin(i)
p.pin(k)
p.add(_OP_nil_3)
y2 := p.pc()
p.add(_OP_goto)
p.pin(k)
p.add(_OP_empty_bytes)
p.pin(x)
p.pin(skip)
p.pin(y)
p.pin(y2)
}
func (self *_Compiler) compileSliceList(p *_Program, sp int, vt reflect.Type) {
@ -1135,13 +1153,11 @@ func (self *_Compiler) compileInterface(p *_Program, vt reflect.Type) {
p.pin(j)
}
func (self *_Compiler) compilePrimitive(vt reflect.Type, p *_Program, op _Op) {
func (self *_Compiler) compilePrimitive(_ reflect.Type, p *_Program, op _Op) {
i := p.pc()
p.add(_OP_is_null)
// skip := self.checkPrimitive(p, vt)
p.add(op)
p.pin(i)
// p.pin(skip)
}
func (self *_Compiler) compileUnmarshalEnd(p *_Program, vt reflect.Type, i int) {

View file

@ -27,6 +27,7 @@ const (
_F_use_number = consts.F_use_number
_F_no_validate_json = consts.F_no_validate_json
_F_validate_string = consts.F_validate_string
_F_case_sensitive = consts.F_case_sensitive
)
var (

View file

@ -1,4 +1,4 @@
// +build go1.17,!go1.24
// +build go1.17,!go1.25
/*
* Copyright 2021 ByteDance Inc.
@ -27,6 +27,7 @@ import (
`github.com/bytedance/sonic/internal/native`
`github.com/bytedance/sonic/internal/native/types`
`github.com/twitchyliquid64/golang-asm/obj`
`github.com/bytedance/sonic/internal/rt`
)
/** Crucial Registers:
@ -173,8 +174,8 @@ var (
)
var (
_F_convTslice = jit.Func(convTslice)
_F_convTstring = jit.Func(convTstring)
_F_convTslice = jit.Func(rt.ConvTslice)
_F_convTstring = jit.Func(rt.ConvTstring)
_F_invalid_vtype = jit.Func(invalid_vtype)
)
@ -725,5 +726,5 @@ var (
//go:nosplit
func invalid_vtype(vt types.ValueType) {
throw(fmt.Sprintf("invalid value type: %d", vt))
rt.Throw(fmt.Sprintf("invalid value type: %d", vt))
}

View file

@ -1,4 +1,4 @@
// +build go1.17,!go1.24
// +build go1.17,!go1.25
//
// Copyright 2021 ByteDance Inc.

View file

@ -102,7 +102,7 @@ func newStack() *_Stack {
}
func resetStack(p *_Stack) {
memclrNoHeapPointers(unsafe.Pointer(p), _StackSize)
rt.MemclrNoHeapPointers(unsafe.Pointer(p), _StackSize)
}
func freeStack(p *_Stack) {

View file

@ -1,106 +0,0 @@
// +build go1.17,!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 jitdec
import (
`unsafe`
`reflect`
_ `github.com/cloudwego/base64x`
`github.com/bytedance/sonic/internal/rt`
)
//go:linkname _subr__b64decode github.com/cloudwego/base64x._subr__b64decode
var _subr__b64decode uintptr
// runtime.maxElementSize
const _max_map_element_size uintptr = 128
func mapfast(vt reflect.Type) bool {
return vt.Elem().Size() <= _max_map_element_size
}
//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:noescape
//go:linkname memequal runtime.memequal
//goland:noinspection GoUnusedParameter
func memequal(a unsafe.Pointer, b unsafe.Pointer, size uintptr) bool
//go:noescape
//go:linkname memmove runtime.memmove
//goland:noinspection GoUnusedParameter
func memmove(to unsafe.Pointer, from unsafe.Pointer, n uintptr)
//go:linkname mallocgc runtime.mallocgc
//goland:noinspection GoUnusedParameter
func mallocgc(size uintptr, typ *rt.GoType, needzero bool) unsafe.Pointer
//go:linkname makeslice runtime.makeslice
//goland:noinspection GoUnusedParameter
func makeslice(et *rt.GoType, len int, cap int) unsafe.Pointer
//go:linkname makemap_small runtime.makemap_small
func makemap_small() unsafe.Pointer
//go:linkname mapassign runtime.mapassign
//goland:noinspection GoUnusedParameter
func mapassign(t *rt.GoType, h unsafe.Pointer, k unsafe.Pointer) unsafe.Pointer
//go:linkname mapassign_fast32 runtime.mapassign_fast32
//goland:noinspection GoUnusedParameter
func mapassign_fast32(t *rt.GoType, h unsafe.Pointer, k uint32) unsafe.Pointer
//go:linkname mapassign_fast64 runtime.mapassign_fast64
//goland:noinspection GoUnusedParameter
func mapassign_fast64(t *rt.GoType, h unsafe.Pointer, k uint64) unsafe.Pointer
//go:linkname mapassign_fast64ptr runtime.mapassign_fast64ptr
//goland:noinspection GoUnusedParameter
func mapassign_fast64ptr(t *rt.GoType, h unsafe.Pointer, k unsafe.Pointer) unsafe.Pointer
//go:linkname mapassign_faststr runtime.mapassign_faststr
//goland:noinspection GoUnusedParameter
func mapassign_faststr(t *rt.GoType, h unsafe.Pointer, s string) unsafe.Pointer
//go:nosplit
//go:linkname memclrHasPointers runtime.memclrHasPointers
//goland:noinspection GoUnusedParameter
func memclrHasPointers(ptr unsafe.Pointer, n uintptr)
//go:noescape
//go:linkname memclrNoHeapPointers runtime.memclrNoHeapPointers
//goland:noinspection GoUnusedParameter
func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr)

View file

@ -1,106 +0,0 @@
// +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 jitdec
import (
`unsafe`
`reflect`
_ `github.com/cloudwego/base64x`
`github.com/bytedance/sonic/internal/rt`
)
//go:linkname _subr__b64decode github.com/cloudwego/base64x._subr__b64decode
var _subr__b64decode uintptr
// runtime.maxElementSize
const _max_map_element_size uintptr = 128
func mapfast(vt reflect.Type) bool {
return vt.Elem().Size() <= _max_map_element_size
}
//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:noescape
//go:linkname memequal runtime.memequal
//goland:noinspection GoUnusedParameter
func memequal(a unsafe.Pointer, b unsafe.Pointer, size uintptr) bool
//go:noescape
//go:linkname memmove runtime.memmove
//goland:noinspection GoUnusedParameter
func memmove(to unsafe.Pointer, from unsafe.Pointer, n uintptr)
//go:linkname mallocgc runtime.mallocgc
//goland:noinspection GoUnusedParameter
func mallocgc(size uintptr, typ *rt.GoType, needzero bool) unsafe.Pointer
//go:linkname makeslice runtime.makeslice
//goland:noinspection GoUnusedParameter
func makeslice(et *rt.GoType, len int, cap int) unsafe.Pointer
//go:linkname makemap_small runtime.makemap_small
func makemap_small() unsafe.Pointer
//go:linkname mapassign runtime.mapassign
//goland:noinspection GoUnusedParameter
func mapassign(t *rt.GoMapType, h unsafe.Pointer, k unsafe.Pointer) unsafe.Pointer
//go:linkname mapassign_fast32 runtime.mapassign_fast32
//goland:noinspection GoUnusedParameter
func mapassign_fast32(t *rt.GoMapType, h unsafe.Pointer, k uint32) unsafe.Pointer
//go:linkname mapassign_fast64 runtime.mapassign_fast64
//goland:noinspection GoUnusedParameter
func mapassign_fast64(t *rt.GoMapType, h unsafe.Pointer, k uint64) unsafe.Pointer
//go:linkname mapassign_fast64ptr runtime.mapassign_fast64ptr
//goland:noinspection GoUnusedParameter
func mapassign_fast64ptr(t *rt.GoMapType, h unsafe.Pointer, k unsafe.Pointer) unsafe.Pointer
//go:linkname mapassign_faststr runtime.mapassign_faststr
//goland:noinspection GoUnusedParameter
func mapassign_faststr(t *rt.GoMapType, h unsafe.Pointer, s string) unsafe.Pointer
//go:nosplit
//go:linkname memclrHasPointers runtime.memclrHasPointers
//goland:noinspection GoUnusedParameter
func memclrHasPointers(ptr unsafe.Pointer, n uintptr)
//go:noescape
//go:linkname memclrNoHeapPointers runtime.memclrNoHeapPointers
//goland:noinspection GoUnusedParameter
func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr)

View file

@ -1,7 +1,6 @@
package optdec
import (
"encoding/json"
"fmt"
"reflect"
@ -169,7 +168,9 @@ func (c *compiler) compileBasic(vt reflect.Type) decFunc {
case reflect.Struct:
return c.compileStruct(vt)
default:
panic(&json.UnmarshalTypeError{Type: vt})
return &unsupportedTypeDecoder{
typ: rt.UnpackType(vt),
}
}
}
@ -263,7 +264,7 @@ func (c *compiler) compileSlice(vt reflect.Type) decFunc {
if et.IsUint64() {
return &sliceU64Decoder{}
}
if et.Kind() == reflect.String {
if et.Kind() == reflect.String && et != rt.JsonNumberType {
return &sliceStringDecoder{}
}
@ -343,7 +344,7 @@ func (c *compiler) compileMap(vt reflect.Type) decFunc {
// Some common integer map later
mt := rt.MapType(rt.UnpackType(vt))
if mt.Key.Kind() == reflect.String {
if mt.Key.Kind() == reflect.String && mt.Key != rt.JsonNumberType {
return &mapStrKeyDecoder{
mapType: mt,
assign: rt.GetMapStrAssign(vt),
@ -399,7 +400,7 @@ func tryCompileKeyUnmarshaler(vt reflect.Type) decKey {
return decodeKeyTextUnmarshaler
}
/* not support map key with `json.Unmarshaler` */
/* NOTE: encoding/json not support map key with `json.Unmarshaler` */
return nil
}
@ -413,8 +414,18 @@ func (c *compiler) compileMapKey(vt reflect.Type) decKey {
return decodeKeyU8
case reflect.Uint16:
return decodeKeyU16
// NOTE: actually, encoding/json can't use float as map key
case reflect.Float32:
return decodeFloat32Key
case reflect.Float64:
return decodeFloat64Key
case reflect.String:
if rt.UnpackType(vt.Key()) == rt.JsonNumberType {
return decodeJsonNumberKey
}
fallthrough
default:
panic(&json.UnmarshalTypeError{Type: vt})
return nil
}
}

View file

@ -70,4 +70,10 @@
Msg: msg,
}
}
func error_unsuppoted(typ *rt.GoType) error {
return &json.UnsupportedTypeError{
Type: typ.Pack(),
}
}

View file

@ -279,3 +279,16 @@ func (d *recuriveDecoder) FromDom(vp unsafe.Pointer, node Node, ctx *context) er
}
return dec.FromDom(vp, node, ctx)
}
type unsupportedTypeDecoder struct {
typ *rt.GoType
}
func (d *unsupportedTypeDecoder) FromDom(vp unsafe.Pointer, node Node, ctx *context) error {
if node.IsNull() {
return nil
}
return error_unsuppoted(d.typ)
}

View file

@ -13,32 +13,44 @@ type efaceDecoder struct {
}
func (d *efaceDecoder) FromDom(vp unsafe.Pointer, node Node, ctx *context) error {
if node.IsNull() {
*(*interface{})(vp) = interface{}(nil)
return nil
}
/* check the defined pointer type for issue 379 */
eface := (*rt.GoEface)(vp)
eface := *(*rt.GoEface)(vp)
// not pointer type, or nil pointer, or *interface{}
if eface.Value == nil || eface.Type.Kind() != reflect.Ptr || rt.PtrElem(eface.Type) == anyType {
/*
not pointer type, or nil pointer, or self-pointed interface{}, such as
```go
var v interface{}
v = &v
return v
``` see `issue758_test.go`.
*/
if eface.Value == nil || eface.Type.Kind() != reflect.Ptr || eface.Value == vp {
ret, err := node.AsEface(ctx)
if err != nil {
return err
}
*(*interface{})(vp) = ret
return nil
}
if node.IsNull() {
if eface.Type.Indirect() || (!eface.Type.Indirect() && eface.Type.Pack().Elem().Kind() != reflect.Ptr) {
*(*interface{})(vp) = nil
return nil
}
}
etp := rt.PtrElem(eface.Type)
vp = eface.Value
/* check the defined pointer type for issue 379 */
if eface.Type.IsNamed() {
// check named pointer type, avoid call its `Unmarshaler`
newp := vp
etp = eface.Type
vp = unsafe.Pointer(&newp)
} else if !eface.Type.Indirect() {
// check direct value
etp = rt.UnpackType(eface.Type.Pack().Elem())
}
dec, err := findOrCompile(etp)
@ -65,19 +77,10 @@ func (d *ifaceDecoder) FromDom(vp unsafe.Pointer, node Node, ctx *context) error
}
vt := iface.Itab.Vt
// not pointer type, or nil pointer, or *interface{}
if vp == nil || vt.Kind() != reflect.Ptr || rt.PtrElem(vt) == anyType {
ret, err := node.AsEface(ctx)
if err != nil {
return err
}
*(*interface{})(vp) = ret
return nil
if vt.Kind() != reflect.Ptr || iface.Value == nil {
return error_type(d.typ)
}
etp := rt.PtrElem(vt)
vp = iface.Value

View file

@ -292,9 +292,9 @@ func (d *mapU64KeyDecoder) FromDom(vp unsafe.Pointer, node Node, ctx *context) e
/** Decoder for generic cases */
type decKey func(dec *mapDecoder, raw string, ctx *context) (interface{}, error)
type decKey func(dec *mapDecoder, raw string) (interface{}, error)
func decodeKeyU8(dec *mapDecoder, raw string, ctx *context) (interface{}, error) {
func decodeKeyU8(dec *mapDecoder, raw string) (interface{}, error) {
key, err := Unquote(raw)
if err != nil {
return nil, err
@ -309,7 +309,7 @@ func decodeKeyU8(dec *mapDecoder, raw string, ctx *context) (interface{}, error)
return uint8(ret), nil
}
func decodeKeyU16(dec *mapDecoder, raw string, ctx *context) (interface{}, error) {
func decodeKeyU16(dec *mapDecoder, raw string) (interface{}, error) {
key, err := Unquote(raw)
if err != nil {
return nil, err
@ -324,7 +324,7 @@ func decodeKeyU16(dec *mapDecoder, raw string, ctx *context) (interface{}, error
return uint16(ret), nil
}
func decodeKeyI8(dec *mapDecoder, raw string, ctx *context) (interface{}, error) {
func decodeKeyI8(dec *mapDecoder, raw string) (interface{}, error) {
key, err := Unquote(raw)
if err != nil {
return nil, err
@ -339,7 +339,7 @@ func decodeKeyI8(dec *mapDecoder, raw string, ctx *context) (interface{}, error)
return int8(ret), nil
}
func decodeKeyI16(dec *mapDecoder, raw string, ctx *context) (interface{}, error) {
func decodeKeyI16(dec *mapDecoder, raw string) (interface{}, error) {
key, err := Unquote(raw)
if err != nil {
return nil, err
@ -354,26 +354,53 @@ func decodeKeyI16(dec *mapDecoder, raw string, ctx *context) (interface{}, error
return int16(ret), nil
}
func decodeKeyJSONUnmarshaler(dec *mapDecoder, raw string, _ *context) (interface{}, error) {
func decodeKeyTextUnmarshaler(dec *mapDecoder, raw string) (interface{}, error) {
key, err := Unquote(raw)
if err != nil {
return nil, err
}
ret := reflect.New(dec.mapType.Key.Pack()).Interface()
err := ret.(json.Unmarshaler).UnmarshalJSON([]byte(raw))
err = ret.(encoding.TextUnmarshaler).UnmarshalText(rt.Str2Mem(key))
if err != nil {
return nil, err
}
return ret, nil
}
func decodeKeyTextUnmarshaler(dec *mapDecoder, raw string, ctx *context) (interface{}, error) {
func decodeFloat32Key(dec *mapDecoder, raw string) (interface{}, error) {
key, err := Unquote(raw)
if err != nil {
return nil, err
}
ret := reflect.New(dec.mapType.Key.Pack()).Interface()
err = ret.(encoding.TextUnmarshaler).UnmarshalText([]byte(key))
ret, err := ParseF64(key)
if err != nil {
return nil, err
}
return ret, nil
if ret > math.MaxFloat32 || ret < -math.MaxFloat32 {
return nil, error_value(key, dec.mapType.Key.Pack())
}
return float32(ret), nil
}
func decodeFloat64Key(dec *mapDecoder, raw string) (interface{}, error) {
key, err := Unquote(raw)
if err != nil {
return nil, err
}
return ParseF64(key)
}
func decodeJsonNumberKey(dec *mapDecoder, raw string) (interface{}, error) {
// skip the quote
raw = raw[1:len(raw)-1]
end, ok := SkipNumberFast(raw, 0)
// check trailing chars
if !ok || end != len(raw) {
return nil, error_value(raw, rt.JsonNumberType.Pack())
}
return json.Number(raw[0:end]), nil
}
type mapDecoder struct {
@ -389,8 +416,8 @@ func (d *mapDecoder) FromDom(vp unsafe.Pointer, node Node, ctx *context) error {
}
obj, ok := node.AsObj()
if !ok {
return error_mismatch(node, ctx, d.mapType.Pack())
if !ok || d.keyDec == nil {
return error_mismatch(node, ctx, d.mapType.Pack())
}
// allocate map
@ -404,7 +431,8 @@ func (d *mapDecoder) FromDom(vp unsafe.Pointer, node Node, ctx *context) error {
for i := 0; i < obj.Len(); i++ {
keyn := NewNode(next)
raw := keyn.AsRaw(ctx)
key, err := d.keyDec(d, raw, ctx)
key, err := d.keyDec(d, raw)
if err != nil {
if gerr == nil {
gerr = error_mismatch(keyn, ctx, d.mapType.Pack())

View file

@ -74,6 +74,7 @@ type nodeBuf struct {
depth uint64
nstart uintptr
nend uintptr
iskey bool
stat jsonStat
}
@ -196,14 +197,14 @@ func (p *Parser) parse() ErrorCode {
// check OoB here
offset := p.nbuf.ncur - p.nbuf.nstart
curLen := offset / unsafe.Sizeof(node{})
if curLen != uintptr(len(p.nodes)) {
curLen := int(offset / unsafe.Sizeof(node{}))
if curLen != len(p.nodes) {
panic(fmt.Sprintf("current len: %d, real len: %d cap: %d", curLen, len(p.nodes), cap(p.nodes)))
}
// node buf is not enough, continue parse
// the maxCap is always meet all valid JSON
maxCap := calMaxNodeCap(len(p.Json))
maxCap := curLen + calMaxNodeCap(len(p.Json) - int(p.cur - p.start))
slice := rt.GoSlice{
Ptr: rt.Mallocgc(uintptr(maxCap) * nodeType.Size, nodeType, false),
Len: maxCap,

View file

@ -301,6 +301,17 @@ func (self Node) AsI64(ctx *Context) (int64, bool) {
}
}
func (self Node) AsByte(ctx *Context) (uint8, bool) {
typ := self.Type()
if typ == KUint && self.U64() <= math.MaxUint8 {
return uint8(self.U64()), true
} else if typ == KSint && self.I64() == 0 {
return 0, true
} else {
return 0, false
}
}
/********* Parse Node String into Value ***************/
func (val Node) ParseI64(ctx *Context) (int64, bool) {
@ -457,20 +468,6 @@ func (val Node) AsStrRef(ctx *Context) (string, bool) {
}
}
func (val Node) AsBytesRef(ctx *Context) ([]byte, bool) {
switch val.Type() {
case KStringEscaped:
node := ptrCast(val.cptr)
offset := val.Position()
len := int(node.val)
return ctx.Parser.JsonBytes()[offset : offset + len], true
case KStringCommon:
return rt.Str2Mem(val.StringRef(ctx)), true
default:
return nil, false
}
}
func (val Node) AsStringText(ctx *Context) ([]byte, bool) {
if !val.IsStr() {
return nil, false
@ -551,7 +548,7 @@ func (val Node) AsRaw(ctx *Context) string {
node := ptrCast(val.cptr)
len := int(node.val)
offset := val.Position()
// add start abd end quote
// add start and end quote
ref := rt.Str2Mem(ctx.Parser.Json)[offset-1 : offset+len+1]
return rt.Mem2Str(ref)
case KRawNumber: fallthrough
@ -867,15 +864,38 @@ func (node *Node) AsSliceString(ctx *Context, vp unsafe.Pointer) error {
return gerr
}
func (node *Node) AsSliceBytes(ctx *Context) ([]byte, error) {
b, ok := node.AsBytesRef(ctx)
if !ok {
return nil, newUnmatched(node.Position(), rt.BytesType)
func (val *Node) AsSliceBytes(ctx *Context) ([]byte, error) {
var origin []byte
switch val.Type() {
case KStringEscaped:
node := ptrCast(val.cptr)
offset := val.Position()
len := int(node.val)
origin = ctx.Parser.JsonBytes()[offset : offset + len]
case KStringCommon:
origin = rt.Str2Mem(val.StringRef(ctx))
case KArray:
arr := val.Array()
size := arr.Len()
a := make([]byte, size)
elem := NewNode(arr.Children())
var gerr error
var ok bool
for i := 0; i < size; i++ {
a[i], ok = elem.AsByte(ctx)
if !ok && gerr == nil {
gerr = newUnmatched(val.Position(), rt.BytesType)
}
elem = NewNode(PtrOffset(elem.cptr, 1))
}
return a, gerr
default:
return nil, newUnmatched(val.Position(), rt.BytesType)
}
b64, err := rt.DecodeBase64(b)
b64, err := rt.DecodeBase64(origin)
if err != nil {
return nil, newUnmatched(node.Position(), rt.BytesType)
return nil, newUnmatched(val.Position(), rt.BytesType)
}
return b64, nil
}

View file

@ -80,9 +80,13 @@ func (d *arrayDecoder) FromDom(vp unsafe.Pointer, node Node, ctx *context) error
}
/* zero rest of array */
ptr := unsafe.Pointer(uintptr(vp) + uintptr(i)*d.elemType.Size)
addr := uintptr(vp) + uintptr(i)*d.elemType.Size
n := uintptr(d.len-i) * d.elemType.Size
rt.ClearMemory(d.elemType, ptr, n)
/* the boundary pointer may points to another unknown object, so we need to avoid using it */
if n != 0 {
rt.ClearMemory(d.elemType, unsafe.Pointer(addr), n)
}
return gerr
}
@ -95,7 +99,18 @@ func (d *sliceEfaceDecoder) FromDom(vp unsafe.Pointer, node Node, ctx *context)
return nil
}
return node.AsSliceEface(ctx, vp)
/* if slice is empty, just call `AsSliceEface` */
if ((*rt.GoSlice)(vp)).Len == 0 {
return node.AsSliceEface(ctx, vp)
}
decoder := sliceDecoder{
elemType: rt.AnyType,
elemDec: &efaceDecoder{},
typ: rt.SliceEfaceType.Pack(),
}
return decoder.FromDom(vp, node, ctx)
}
type sliceI32Decoder struct {
@ -168,12 +183,8 @@ func (d *sliceBytesDecoder) FromDom(vp unsafe.Pointer, node Node, ctx *context)
}
s, err := node.AsSliceBytes(ctx)
if err != nil {
return err
}
*(*[]byte)(vp) = s
return nil
return err
}
type sliceBytesUnmarshalerDecoder struct {

View file

@ -4,6 +4,7 @@ import (
"reflect"
"unsafe"
"github.com/bytedance/sonic/internal/decoder/consts"
caching "github.com/bytedance/sonic/internal/optcaching"
"github.com/bytedance/sonic/internal/resolver"
)
@ -38,7 +39,7 @@ func (d *structDecoder) FromDom(vp unsafe.Pointer, node Node, ctx *context) erro
next = val.Next()
// find field idx
idx := d.fieldMap.Get(key)
idx := d.fieldMap.Get(key, ctx.Options()&uint64(consts.OptionCaseSensitive) != 0)
if idx == -1 {
if Options(ctx.Options())&OptionDisableUnknown != 0 {
return error_field(key)