Skip to content

Commit

Permalink
Merge branch 'fix-pernicious-map-struct-map-memory-reuse-bug'
Browse files Browse the repository at this point in the history
  • Loading branch information
warpfork committed Jan 31, 2018
2 parents 11c0101 + 4ab725f commit 852c21d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
29 changes: 29 additions & 0 deletions obj/objFixtures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,35 @@ var objFixtures = []struct {
}},
},
},
{title: "nested map-struct-map",
// the tmp slot required in map unmarshalling creates the potential for
// some really wild edge cases...
sequence: fixtures.SequenceMap["map[str]map[str]map[str]str"],
atlas: atlas.MustBuild(
atlas.BuildEntry(tObjMap{}).StructMap().
AddField("X", atlas.StructMapEntry{SerialName: "f"}).
Complete(),
),
marshalResults: []marshalResults{
{title: "from map[str]tObjMap{map[str]iface}",
valueFn: func() interface{} {
return map[string]tObjMap{
"k1": {X: map[string]interface{}{"d": "aa"}},
"k2": {X: map[string]interface{}{"d": "bb"}},
}
}},
},
unmarshalResults: []unmarshalResults{
{title: "into map[str]tObjMap",
slotFn: func() interface{} { return &map[string]tObjMap{} },
valueFn: func() interface{} {
return map[string]tObjMap{
"k1": {X: map[string]interface{}{"d": "aa"}},
"k2": {X: map[string]interface{}{"d": "bb"}},
}
}},
},
},
{title: "transform funks (struct<->string)",
sequence: fixtures.SequenceMap["flat string"],
atlas: atlas.MustBuild(
Expand Down
1 change: 1 addition & 0 deletions obj/unmarshalMapWildcard.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func (mach *unmarshalMachineMapStringWildcard) mustAcceptKey(key_rv reflect.Valu

func (mach *unmarshalMachineMapStringWildcard) step_AcceptValue(driver *Unmarshaller, slab *unmarshalSlab, tok *Token) (done bool, err error) {
mach.step = mach.step_AcceptKey
mach.tmp_rv.Set(reflect.Zero(mach.value_rt))
mach.haveValue = true
return false, driver.Recurse(
tok,
Expand Down
17 changes: 17 additions & 0 deletions tok/fixtures/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,23 @@ var Sequences = []Sequence{
{Type: TMapClose},
},
},
{"map[str]map[str]map[str]str",
// this is primarily for the objmapper tests (map-struct-map case).
[]Token{
{Type: TMapOpen, Length: 2},
TokStr("k1"), {Type: TMapOpen, Length: 1},
/**/ TokStr("f"), {Type: TMapOpen, Length: 1},
/**/ /**/ TokStr("d"), TokStr("aa"),
/**/ /**/ {Type: TMapClose},
/**/ {Type: TMapClose},
TokStr("k2"), {Type: TMapOpen, Length: 1},
/**/ TokStr("f"), {Type: TMapOpen, Length: 1},
/**/ /**/ TokStr("d"), TokStr("bb"),
/**/ /**/ {Type: TMapClose},
/**/ {Type: TMapClose},
{Type: TMapClose},
},
},

// Empty and null and null-at-depth.
{"empty",
Expand Down

0 comments on commit 852c21d

Please sign in to comment.