2
0
Fork 0
mirror of https://github.com/ii64/sonic.git synced 2026-06-21 00:46:43 +08:00

fix: check flags for indirection

This commit is contained in:
chenzhuoyu 2021-08-18 13:29:57 +08:00 committed by Oxygen
parent b20904f574
commit ade38b26c4
3 changed files with 56 additions and 1 deletions

View file

@ -1022,7 +1022,7 @@ func (self *_Assembler) _asm_OP_recurse(p *_Instr) {
self.Emit("MOVQ", _AX, jit.Ptr(_SP, 8)) // MOVQ AX, 8(SP)
/* check for indirection */
if p.vk() == reflect.Ptr {
if (p.vf() & rt.F_direct) != 0 {
self.Emit("MOVQ", _SP_p, _AX) // MOVQ SP.p, AX
} else {
self.Emit("MOVQ", _SP_p, jit.Ptr(_SP, 48)) // MOVQ SP.p, 48(SP)

View file

@ -224,6 +224,10 @@ func (self _Instr) vi() int {
return rt.UnpackInt(self.u)
}
func (self _Instr) vf() uint8 {
return (*rt.GoType)(self.p).KindFlags
}
func (self _Instr) vs() (v string) {
(*rt.GoString)(unsafe.Pointer(&v)).Ptr = self.p
(*rt.GoString)(unsafe.Pointer(&v)).Len = self.vi()

51
issue76_test.go Normal file
View file

@ -0,0 +1,51 @@
/*
* 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 sonic
import (
`encoding/json`
`fmt`
`testing`
`github.com/davecgh/go-spew/spew`
)
type SingleMapField struct {
Z *int
}
type SingleMapFieldOuter struct {
Y *SingleMapField
}
type SingleMapFieldOuterContainer struct {
X *SingleMapFieldOuter
}
func TestIssue76_MarshalSingleMapField(t *testing.T) {
data := `{"X": {"Y": {"Z": 1}}}`
obj := new(SingleMapFieldOuterContainer)
if err := json.Unmarshal([]byte(data), obj); err != nil {
t.Fatal(err)
}
spew.Dump(obj)
buf, err := Marshal(obj)
if err != nil {
t.Fatal(err)
}
fmt.Println(string(buf))
}