Skip to content

Commit

Permalink
fix: check Stackoverflow wrongly
Browse files Browse the repository at this point in the history
  • Loading branch information
AsterDY committed Feb 1, 2024
1 parent 9c39139 commit 3976560
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
23 changes: 11 additions & 12 deletions generic_test/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
`reflect`
`fmt`
`github.com/bytedance/sonic`
dev `github.com/bytedance/sonic/dev`
// dev `github.com/bytedance/sonic/dev`
`encoding/json`
gojson `github.com/goccy/go-json`
jsoniter `github.com/json-iterator/go`
Expand All @@ -46,19 +46,18 @@ var jsonTotalLibs = []jsonLibEntry {
{"Std", json.Marshal, json.Unmarshal},
{"StdV2", jsonv2.Marshal, jsonv2.Unmarshal},
{"Sonic", sonic.Marshal, sonic.Unmarshal},
{"SonicDev", dev.Marshal, dev.Unmarshal},
// {"SonicDev", dev.Marshal, dev.Unmarshal},
{"SonicStd", sonic.ConfigStd.Marshal, sonic.ConfigStd.Unmarshal},
{"GoJson", gojson.Marshal, gojson.Unmarshal},
{"JsonIter", jsoniter.Marshal, jsoniter.Unmarshal},
{"JsonIterStd", jsoniter.ConfigCompatibleWithStandardLibrary.Marshal, jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal},
}


var jsonLibs = []jsonLibEntry {
{"Std", json.Marshal, json.Unmarshal},
{"Sonic", sonic.Marshal, sonic.Unmarshal},
{"SonicDev", dev.Marshal, dev.Unmarshal},
}
// var jsonTotalLibs = []jsonLibEntry {
// {"Std", json.Marshal, json.Unmarshal},
// {"Sonic", sonic.Marshal, sonic.Unmarshal},
// {"SonicDev", dev.Marshal, dev.Unmarshal},
// }

func BenchmarkUnmarshalConcrete(b *testing.B) {
runUnmarshalC(b)
Expand All @@ -78,7 +77,7 @@ func BenchmarkMarshalInterface(b *testing.B) {

func runUnmarshalC(b *testing.B) {
for _, tt := range jsonTestdata() {
for _, lib := range jsonLibs {
for _, lib := range jsonTotalLibs {
var val any = tt.new()
pretouch := func() {
_ = lib.unmarshal(tt.data, val)
Expand Down Expand Up @@ -123,7 +122,7 @@ func runUnmarshalC(b *testing.B) {

func runUnmarshalI(b *testing.B) {
for _, tt := range jsonTestdata() {
for _, lib := range jsonLibs {
for _, lib := range jsonTotalLibs {
var val any = tt.newI()
pretouch := func() {
_ = lib.unmarshal(tt.data, val)
Expand Down Expand Up @@ -168,7 +167,7 @@ func runUnmarshalI(b *testing.B) {

func runMarshalC(b *testing.B) {
for _, tt := range jsonTestdata() {
for _, lib := range jsonLibs {
for _, lib := range jsonTotalLibs {
pretouch := func() {
_, _ = lib.marshal(tt.val)
}
Expand Down Expand Up @@ -223,7 +222,7 @@ func runMarshalC(b *testing.B) {

func runMarshalI(b *testing.B) {
for _, tt := range jsonTestdata() {
for _, lib := range jsonLibs {
for _, lib := range jsonTotalLibs {
pretouch := func() {
_, _ = lib.marshal(tt.valI)
}
Expand Down
5 changes: 3 additions & 2 deletions internal/encoder/vars/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ func ResetStack(p *Stack) {
rt.MemclrNoHeapPointers(unsafe.Pointer(p), StackSize)
}


func (s *Stack) Top() *State {
return (*State)(unsafe.Add(unsafe.Pointer(&s.sb[0]), s.sp))
}
Expand All @@ -77,8 +76,10 @@ func (s *Stack) Cur() *State {
return (*State)(unsafe.Add(unsafe.Pointer(&s.sb[0]), s.sp - uintptr(StateSize)))
}

const _MaxStackSP = uintptr(MaxStack * StateSize)

func (s *Stack) Push(v State) bool {
if uintptr(s.sp) > uintptr(unsafe.Pointer(&s.sb[MaxStack-1])) {
if uintptr(s.sp) >= _MaxStackSP {
return false
}
st := s.Top()
Expand Down

0 comments on commit 3976560

Please sign in to comment.