summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTing-Yu Wang <anivia@google.com>2020-08-20 15:38:06 -0700
committerAndrei Vagin <avagin@gmail.com>2020-09-09 17:53:10 -0700
commitb17c7094f706ce92eba44e72e2cede8814b29607 (patch)
treec84266b3c69cf6b975f9517ed7061863e464a82d
parent76e5213c113a0eefa7341122dc06e4a4191800e8 (diff)
stateify: Fix afterLoad not being called for root object
PiperOrigin-RevId: 327711264
-rw-r--r--pkg/state/decode.go6
-rw-r--r--pkg/state/tests/load_test.go8
2 files changed, 12 insertions, 2 deletions
diff --git a/pkg/state/decode.go b/pkg/state/decode.go
index c9971cdf6..89467ca8e 100644
--- a/pkg/state/decode.go
+++ b/pkg/state/decode.go
@@ -584,10 +584,12 @@ func (ds *decodeState) Load(obj reflect.Value) {
})
// Create the root object.
- ds.objectsByID = append(ds.objectsByID, &objectDecodeState{
+ rootOds := &objectDecodeState{
id: 1,
obj: obj,
- })
+ }
+ ds.objectsByID = append(ds.objectsByID, rootOds)
+ ds.pending.PushBack(rootOds)
// Read the number of objects.
lastID, object, err := ReadHeader(ds.r)
diff --git a/pkg/state/tests/load_test.go b/pkg/state/tests/load_test.go
index 1e9794296..3c73ac391 100644
--- a/pkg/state/tests/load_test.go
+++ b/pkg/state/tests/load_test.go
@@ -20,6 +20,14 @@ import (
func TestLoadHooks(t *testing.T) {
runTestCases(t, false, "load-hooks", []interface{}{
+ // Root object being a struct.
+ afterLoadStruct{v: 1},
+ valueLoadStruct{v: 1},
+ genericContainer{v: &afterLoadStruct{v: 1}},
+ genericContainer{v: &valueLoadStruct{v: 1}},
+ sliceContainer{v: []interface{}{&afterLoadStruct{v: 1}}},
+ sliceContainer{v: []interface{}{&valueLoadStruct{v: 1}}},
+ // Root object being a pointer.
&afterLoadStruct{v: 1},
&valueLoadStruct{v: 1},
&genericContainer{v: &afterLoadStruct{v: 1}},