diff options
Diffstat (limited to 'vendor/github.com/bytedance')
15 files changed, 79 insertions, 54 deletions
diff --git a/vendor/github.com/bytedance/sonic/.gitmodules b/vendor/github.com/bytedance/sonic/.gitmodules index ea84b991a..5a2d998ab 100644 --- a/vendor/github.com/bytedance/sonic/.gitmodules +++ b/vendor/github.com/bytedance/sonic/.gitmodules @@ -4,3 +4,6 @@ [submodule "tools/simde"] path = tools/simde url = https://github.com/simd-everywhere/simde.git +[submodule "fuzz/go-fuzz-corpus"] + path = fuzz/go-fuzz-corpus + url = https://github.com/dvyukov/go-fuzz-corpus.git diff --git a/vendor/github.com/bytedance/sonic/README.md b/vendor/github.com/bytedance/sonic/README.md index 317878d09..41fe77658 100644 --- a/vendor/github.com/bytedance/sonic/README.md +++ b/vendor/github.com/bytedance/sonic/README.md @@ -385,12 +385,12 @@ See [ast/visitor.go](https://github.com/bytedance/sonic/blob/main/ast/visitor.go ## Compatibility -For developers who want to use sonic to meet diffirent scenarios, we provide some integrated configs as `sonic.API` +For developers who want to use sonic to meet different scenarios, we provide some integrated configs as `sonic.API` - `ConfigDefault`: the sonic's default config (`EscapeHTML=false`,`SortKeys=false`...) to run sonic fast meanwhile ensure security. - `ConfigStd`: the std-compatible config (`EscapeHTML=true`,`SortKeys=true`...) - `ConfigFastest`: the fastest config (`NoQuoteTextMarshaler=true`) to run on sonic as fast as possible. -Sonic **DOES NOT** ensure to support all environments, due to the difficulty of developing high-performance codes. On non-sonic-supporting environment, the implementation will fall back to `encoding/json`. Thus beflow configs will all equal to `ConfigStd`. +Sonic **DOES NOT** ensure to support all environments, due to the difficulty of developing high-performance codes. On non-sonic-supporting environment, the implementation will fall back to `encoding/json`. Thus below configs will all equal to `ConfigStd`. ## Tips diff --git a/vendor/github.com/bytedance/sonic/api.go b/vendor/github.com/bytedance/sonic/api.go index 406715eca..3858d9a80 100644 --- a/vendor/github.com/bytedance/sonic/api.go +++ b/vendor/github.com/bytedance/sonic/api.go @@ -94,6 +94,9 @@ type Config struct { // Encode Infinity or Nan float into `null`, instead of returning an error. EncodeNullForInfOrNan bool + + // CaseSensitive indicates that the decoder should not ignore the case of object keys. + CaseSensitive bool } var ( @@ -111,7 +114,6 @@ var ( // ConfigFastest is the fastest config of APIs, aiming at speed. ConfigFastest = Config{ - NoQuoteTextMarshaler: true, NoValidateJSONMarshaler: true, NoValidateJSONSkip: true, }.Froze() diff --git a/vendor/github.com/bytedance/sonic/ast/iterator.go b/vendor/github.com/bytedance/sonic/ast/iterator.go index 1052dd0a0..978028a65 100644 --- a/vendor/github.com/bytedance/sonic/ast/iterator.go +++ b/vendor/github.com/bytedance/sonic/ast/iterator.go @@ -176,7 +176,7 @@ type Scanner func(path Sequence, node *Node) bool // Especially, if the node is not V_ARRAY or V_OBJECT, // the node itself will be returned and Sequence.Index == -1. // -// NOTICE: A unsetted node WON'T trigger sc, but its index still counts into Path.Index +// NOTICE: An unset node WON'T trigger sc, but its index still counts into Path.Index func (self *Node) ForEach(sc Scanner) error { if err := self.checkRaw(); err != nil { return err diff --git a/vendor/github.com/bytedance/sonic/ast/node.go b/vendor/github.com/bytedance/sonic/ast/node.go index 17964c32f..1c5ff6439 100644 --- a/vendor/github.com/bytedance/sonic/ast/node.go +++ b/vendor/github.com/bytedance/sonic/ast/node.go @@ -509,6 +509,23 @@ func (self *Node) Float64() (float64, error) { } } +func (self *Node) StrictBool() (bool, error) { + if err := self.checkRaw(); err!= nil { + return false, err + } + switch self.t { + case types.V_TRUE : return true, nil + case types.V_FALSE : return false, nil + case _V_ANY : + any := self.packAny() + switch v := any.(type) { + case bool : return v, nil + default : return false, ErrUnsupportType + } + default : return false, ErrUnsupportType + } +} + // Float64 exports underlying float64 value, including V_NUMBER, V_ANY func (self *Node) StrictFloat64() (float64, error) { if err := self.checkRaw(); err != nil { @@ -776,7 +793,7 @@ func (self *Node) Pop() error { } // Move moves the child at src index to dst index, -// meanwhile slides sliblings from src+1 to dst. +// meanwhile slides siblings from src+1 to dst. // // WARN: this will change address of elements, which is a dangerous action. func (self *Node) Move(dst, src int) error { @@ -816,7 +833,7 @@ func (self *Node) Move(dst, src int) error { return nil } -// SetAny wraps val with V_ANY node, and Add() the node. +// AddAny wraps val with V_ANY node, and Add() the node. func (self *Node) AddAny(val interface{}) error { return self.Add(NewAny(val)) } @@ -938,7 +955,7 @@ func (self *Node) Map() (map[string]interface{}, error) { return self.toGenericObject() } -// MapUseNumber loads all keys of an object node, with numeric nodes casted to json.Number +// MapUseNumber loads all keys of an object node, with numeric nodes cast to json.Number func (self *Node) MapUseNumber() (map[string]interface{}, error) { if self.isAny() { any := self.packAny() @@ -1083,7 +1100,7 @@ func (self *Node) Array() ([]interface{}, error) { return self.toGenericArray() } -// ArrayUseNumber loads all indexes of an array node, with numeric nodes casted to json.Number +// ArrayUseNumber loads all indexes of an array node, with numeric nodes cast to json.Number func (self *Node) ArrayUseNumber() ([]interface{}, error) { if self.isAny() { any := self.packAny() @@ -1149,7 +1166,7 @@ func (self *Node) unsafeArray() (*linkedNodes, error) { // Interface loads all children under all paths from this node, // and converts itself as generic type. -// WARN: all numeric nodes are casted to float64 +// WARN: all numeric nodes are cast to float64 func (self *Node) Interface() (interface{}, error) { if err := self.checkRaw(); err != nil { return nil, err @@ -1193,7 +1210,7 @@ func (self *Node) packAny() interface{} { } // InterfaceUseNumber works same with Interface() -// except numeric nodes are casted to json.Number +// except numeric nodes are cast to json.Number func (self *Node) InterfaceUseNumber() (interface{}, error) { if err := self.checkRaw(); err != nil { return nil, err diff --git a/vendor/github.com/bytedance/sonic/ast/parser.go b/vendor/github.com/bytedance/sonic/ast/parser.go index 30bd1f451..aee96f86a 100644 --- a/vendor/github.com/bytedance/sonic/ast/parser.go +++ b/vendor/github.com/bytedance/sonic/ast/parser.go @@ -63,7 +63,7 @@ func (self *Parser) delim() types.ParsingError { return types.ERR_EOF } - /* check for the delimtier */ + /* check for the delimiter */ if self.s[p] != ':' { return types.ERR_INVALID_CHAR } @@ -82,7 +82,7 @@ func (self *Parser) object() types.ParsingError { return types.ERR_EOF } - /* check for the delimtier */ + /* check for the delimiter */ if self.s[p] != '{' { return types.ERR_INVALID_CHAR } @@ -101,7 +101,7 @@ func (self *Parser) array() types.ParsingError { return types.ERR_EOF } - /* check for the delimtier */ + /* check for the delimiter */ if self.s[p] != '[' { return types.ERR_INVALID_CHAR } @@ -638,7 +638,7 @@ func Loads(src string) (int, interface{}, error) { } } -// LoadsUseNumber parse all json into interface{}, with numeric nodes casted to json.Number +// LoadsUseNumber parse all json into interface{}, with numeric nodes cast to json.Number func LoadsUseNumber(src string) (int, interface{}, error) { ps := &Parser{s: src} np, err := ps.Parse() diff --git a/vendor/github.com/bytedance/sonic/ast/visitor.go b/vendor/github.com/bytedance/sonic/ast/visitor.go index dc0478513..fc71d40cb 100644 --- a/vendor/github.com/bytedance/sonic/ast/visitor.go +++ b/vendor/github.com/bytedance/sonic/ast/visitor.go @@ -178,7 +178,7 @@ func (self *traverser) decodeArray() error { /* allocate array space and parse every element */ if err := self.visitor.OnArrayBegin(_DEFAULT_NODE_CAP); err != nil { if err == VisitOPSkip { - // NOTICE: for user needs to skip entiry object + // NOTICE: for user needs to skip entry object self.parser.p -= 1 if _, e := self.parser.skipFast(); e != 0 { return e @@ -233,7 +233,7 @@ func (self *traverser) decodeObject() error { /* allocate object space and decode each pair */ if err := self.visitor.OnObjectBegin(_DEFAULT_NODE_CAP); err != nil { if err == VisitOPSkip { - // NOTICE: for user needs to skip entiry object + // NOTICE: for user needs to skip entry object self.parser.p -= 1 if _, e := self.parser.skipFast(); e != 0 { return e @@ -328,5 +328,5 @@ func (self *traverser) decodeString(iv int64, ep int) error { } // If visitor return this error on `OnObjectBegin()` or `OnArrayBegin()`, -// the transverer will skip entiry object or array +// the traverser will skip entry object or array var VisitOPSkip = errors.New("") diff --git a/vendor/github.com/bytedance/sonic/compat.go b/vendor/github.com/bytedance/sonic/compat.go index b694d7ce9..ec996493a 100644 --- a/vendor/github.com/bytedance/sonic/compat.go +++ b/vendor/github.com/bytedance/sonic/compat.go @@ -87,7 +87,17 @@ func (cfg frozenConfig) UnmarshalFromString(buf string, val interface{}) error { if cfg.DisallowUnknownFields { dec.DisallowUnknownFields() } - return dec.Decode(val) + err := dec.Decode(val) + if err != nil { + return err + } + + // check the trailing chars + offset := dec.InputOffset() + if t, err := dec.Token(); !(t == nil && err == io.EOF) { + return &json.SyntaxError{ Offset: offset} + } + return nil } // Unmarshal is implemented by sonic diff --git a/vendor/github.com/bytedance/sonic/internal/decoder/api/stream.go b/vendor/github.com/bytedance/sonic/internal/decoder/api/stream.go index 8a8102dd5..ecf120462 100644 --- a/vendor/github.com/bytedance/sonic/internal/decoder/api/stream.go +++ b/vendor/github.com/bytedance/sonic/internal/decoder/api/stream.go @@ -76,11 +76,12 @@ func (self *StreamDecoder) Decode(val interface{}) (err error) { if y := native.SkipOneFast(&src, &x); y < 0 { if self.readMore() { goto try_skip - } else { - err = SyntaxError{e, self.s, types.ParsingError(-s), ""} - self.setErr(err) - return + } + if self.err == nil { + self.err = SyntaxError{e, self.s, types.ParsingError(-s), ""} + self.setErr(self.err) } + return self.err } else { s = y + s e = x + s diff --git a/vendor/github.com/bytedance/sonic/internal/decoder/optdec/node.go b/vendor/github.com/bytedance/sonic/internal/decoder/optdec/node.go index 774b6eef7..085e81102 100644 --- a/vendor/github.com/bytedance/sonic/internal/decoder/optdec/node.go +++ b/vendor/github.com/bytedance/sonic/internal/decoder/optdec/node.go @@ -12,7 +12,7 @@ import ( type Context struct { Parser *Parser efacePool *efacePool - Stack bounedStack + Stack boundedStack Utf8Inv bool } @@ -26,20 +26,20 @@ type parentStat struct { con unsafe.Pointer remain uint64 } -type bounedStack struct { +type boundedStack struct { stack []parentStat index int } -func newStack(size int) bounedStack { - return bounedStack{ +func newStack(size int) boundedStack { + return boundedStack{ stack: make([]parentStat, size + 2), index: 0, } } //go:nosplit -func (s *bounedStack) Pop() (unsafe.Pointer, int, bool){ +func (s *boundedStack) Pop() (unsafe.Pointer, int, bool){ s.index-- con := s.stack[s.index].con remain := s.stack[s.index].remain &^ (uint64(1) << 63) @@ -50,7 +50,7 @@ func (s *bounedStack) Pop() (unsafe.Pointer, int, bool){ } //go:nosplit -func (s *bounedStack) Push(p unsafe.Pointer, remain int, isObj bool) { +func (s *boundedStack) Push(p unsafe.Pointer, remain int, isObj bool) { s.stack[s.index].con = p s.stack[s.index].remain = uint64(remain) if isObj { @@ -1253,7 +1253,7 @@ func (node *Node) AsEfaceFallback(ctx *Context) (interface{}, error) { if ctx.Parser.options & (1 << _F_use_number) != 0 { num, ok := node.AsNumber(ctx) if !ok { - // skip the unmacthed type + // skip the unmatched type *node = NewNode(node.Next()) return nil, newUnmatched(node.Position(), rt.JsonNumberType) } else { @@ -1275,13 +1275,13 @@ func (node *Node) AsEfaceFallback(ctx *Context) (interface{}, error) { return f, nil } - // skip the unmacthed type + // skip the unmatched type *node = NewNode(node.Next()) return nil, newUnmatched(node.Position(), rt.Int64Type) } else { num, ok := node.AsF64(ctx) if !ok { - // skip the unmacthed type + // skip the unmatched type *node = NewNode(node.Next()) return nil, newUnmatched(node.Position(), rt.Float64Type) } else { diff --git a/vendor/github.com/bytedance/sonic/internal/encoder/alg/mapiter.go b/vendor/github.com/bytedance/sonic/internal/encoder/alg/mapiter.go index 032ae3b8a..090afac13 100644 --- a/vendor/github.com/bytedance/sonic/internal/encoder/alg/mapiter.go +++ b/vendor/github.com/bytedance/sonic/internal/encoder/alg/mapiter.go @@ -97,17 +97,18 @@ func (self *MapIterator) append(t *rt.GoType, k unsafe.Pointer, v unsafe.Pointer func (self *MapIterator) appendGeneric(p *_MapPair, t *rt.GoType, v reflect.Kind, k unsafe.Pointer) error { switch v { - case reflect.Int : p.k = rt.Mem2Str(strconv.AppendInt(p.m[:0], int64(*(*int)(k)), 10)) ; return nil - case reflect.Int8 : p.k = rt.Mem2Str(strconv.AppendInt(p.m[:0], int64(*(*int8)(k)), 10)) ; return nil - case reflect.Int16 : p.k = rt.Mem2Str(strconv.AppendInt(p.m[:0], int64(*(*int16)(k)), 10)) ; return nil - case reflect.Int32 : p.k = rt.Mem2Str(strconv.AppendInt(p.m[:0], int64(*(*int32)(k)), 10)) ; return nil - case reflect.Int64 : p.k = rt.Mem2Str(strconv.AppendInt(p.m[:0], int64(*(*int64)(k)), 10)) ; return nil + case reflect.Int : p.k = rt.Mem2Str(strconv.AppendInt(p.m[:0], int64(*(*int)(k)), 10)) ; return nil + case reflect.Int8 : p.k = rt.Mem2Str(strconv.AppendInt(p.m[:0], int64(*(*int8)(k)), 10)) ; return nil + case reflect.Int16 : p.k = rt.Mem2Str(strconv.AppendInt(p.m[:0], int64(*(*int16)(k)), 10)) ; return nil + case reflect.Int32 : p.k = rt.Mem2Str(strconv.AppendInt(p.m[:0], int64(*(*int32)(k)), 10)) ; return nil + case reflect.Int64 : p.k = rt.Mem2Str(strconv.AppendInt(p.m[:0], int64(*(*int64)(k)), 10)) ; return nil case reflect.Uint : p.k = rt.Mem2Str(strconv.AppendUint(p.m[:0], uint64(*(*uint)(k)), 10)) ; return nil case reflect.Uint8 : p.k = rt.Mem2Str(strconv.AppendUint(p.m[:0], uint64(*(*uint8)(k)), 10)) ; return nil case reflect.Uint16 : p.k = rt.Mem2Str(strconv.AppendUint(p.m[:0], uint64(*(*uint16)(k)), 10)) ; return nil case reflect.Uint32 : p.k = rt.Mem2Str(strconv.AppendUint(p.m[:0], uint64(*(*uint32)(k)), 10)) ; return nil - case reflect.Uint64 : p.k = rt.Mem2Str(strconv.AppendUint(p.m[:0], uint64(*(*uint64)(k)), 10)) ; return nil + case reflect.Uint64 : p.k = rt.Mem2Str(strconv.AppendUint(p.m[:0], uint64(*(*uint64)(k)), 10)) ; return nil case reflect.Uintptr : p.k = rt.Mem2Str(strconv.AppendUint(p.m[:0], uint64(*(*uintptr)(k)), 10)) ; return nil + case reflect.Bool : if *(*bool)(k) { p.k = "true" } else { p.k = "false" }; return nil case reflect.Interface : return self.appendInterface(p, t, k) case reflect.Struct, reflect.Ptr : return self.appendConcrete(p, t, k) default : panic("unexpected map key type") diff --git a/vendor/github.com/bytedance/sonic/internal/encoder/alg/spec.go b/vendor/github.com/bytedance/sonic/internal/encoder/alg/spec.go index 6f76ac739..ecdbfb7bd 100644 --- a/vendor/github.com/bytedance/sonic/internal/encoder/alg/spec.go +++ b/vendor/github.com/bytedance/sonic/internal/encoder/alg/spec.go @@ -21,6 +21,7 @@ package alg import ( "runtime" + "strconv" "unsafe" "github.com/bytedance/sonic/internal/native" @@ -177,22 +178,9 @@ func F32toa(buf []byte, v float32) ([]byte) { } func I64toa(buf []byte, v int64) ([]byte) { - buf = rt.GuardSlice2(buf, 32) - ret := native.I64toa((*byte)(rt.IndexByte(buf, len(buf))), v) - if ret > 0 { - return buf[:len(buf)+ret] - } else { - return buf - } + return strconv.AppendInt(buf, v, 10) } func U64toa(buf []byte, v uint64) ([]byte) { - buf = rt.GuardSlice2(buf, 32) - ret := native.U64toa((*byte)(rt.IndexByte(buf, len(buf))), v) - if ret > 0 { - return buf[:len(buf)+ret] - } else { - return buf - } + return strconv.AppendUint(buf, v, 10) } - diff --git a/vendor/github.com/bytedance/sonic/internal/optcaching/fcache.go b/vendor/github.com/bytedance/sonic/internal/optcaching/fcache.go index 010028203..f207b4b16 100644 --- a/vendor/github.com/bytedance/sonic/internal/optcaching/fcache.go +++ b/vendor/github.com/bytedance/sonic/internal/optcaching/fcache.go @@ -324,7 +324,7 @@ func (self *NormalFieldMap) Set(fields []resolver.FieldMeta) { } -// use hashnap +// use hashmap type FallbackFieldMap struct { oders []string inner map[string]int diff --git a/vendor/github.com/bytedance/sonic/sonic.go b/vendor/github.com/bytedance/sonic/sonic.go index 395730362..9645d5e08 100644 --- a/vendor/github.com/bytedance/sonic/sonic.go +++ b/vendor/github.com/bytedance/sonic/sonic.go @@ -90,6 +90,9 @@ func (cfg Config) Froze() API { if cfg.ValidateString { api.decoderOpts |= decoder.OptionValidateString } + if cfg.CaseSensitive { + api.decoderOpts |= decoder.OptionCaseSensitive + } return api } diff --git a/vendor/github.com/bytedance/sonic/utf8/utf8.go b/vendor/github.com/bytedance/sonic/utf8/utf8.go index 9d8bcc958..c1403fdb2 100644 --- a/vendor/github.com/bytedance/sonic/utf8/utf8.go +++ b/vendor/github.com/bytedance/sonic/utf8/utf8.go @@ -62,7 +62,7 @@ func CorrectWith(dst []byte, src []byte, repl string) []byte { return dst } -// Validate is a simd-accelereated drop-in replacement for the standard library's utf8.Valid. +// Validate is a simd-accelerated drop-in replacement for the standard library's utf8.Valid. func Validate(src []byte) bool { if src == nil { return true |
