New Upstream Release - golang-github-mitchellh-reflectwalk

Ready changes

Summary

Merged new upstream version: 1.0.2 (was: 1.0.1).

Resulting package

Built on 2023-03-14T03:29 (took 4m29s)

The resulting binary packages can be installed (if you have the apt repository enabled) by running one of:

apt install -t fresh-releases golang-github-mitchellh-reflectwalk-dev

Lintian Result

Diff

diff --git a/debian/changelog b/debian/changelog
index 21cd6d3..a779537 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,10 +1,11 @@
-golang-github-mitchellh-reflectwalk (1.0.1-2) UNRELEASED; urgency=medium
+golang-github-mitchellh-reflectwalk (1.0.2-1) UNRELEASED; urgency=medium
 
   * Set upstream metadata fields: Bug-Database, Bug-Submit, Repository,
     Repository-Browse.
   * Update standards version to 4.5.1, no changes needed.
+  * New upstream release.
 
- -- Debian Janitor <janitor@jelmer.uk>  Fri, 24 Sep 2021 04:18:21 -0000
+ -- Debian Janitor <janitor@jelmer.uk>  Tue, 14 Mar 2023 03:25:39 -0000
 
 golang-github-mitchellh-reflectwalk (1.0.1-1) unstable; urgency=medium
 
diff --git a/reflectwalk.go b/reflectwalk.go
index 3a93a0b..7fee7b0 100644
--- a/reflectwalk.go
+++ b/reflectwalk.go
@@ -69,6 +69,13 @@ type PointerWalker interface {
 	PointerExit(bool) error
 }
 
+// PointerValueWalker implementations are notified with the value of
+// a particular pointer when a pointer is walked. Pointer is called
+// right before PointerEnter.
+type PointerValueWalker interface {
+	Pointer(reflect.Value) error
+}
+
 // SkipEntry can be returned from walk functions to skip walking
 // the value of this field. This is only valid in the following functions:
 //
@@ -130,6 +137,17 @@ func walk(v reflect.Value, w interface{}) (err error) {
 		}
 
 		if pointerV.Kind() == reflect.Ptr {
+			if pw, ok := w.(PointerValueWalker); ok {
+				if err = pw.Pointer(pointerV); err != nil {
+					if err == SkipEntry {
+						// Skip the rest of this entry but clear the error
+						return nil
+					}
+
+					return
+				}
+			}
+
 			pointer = true
 			v = reflect.Indirect(pointerV)
 		}
diff --git a/reflectwalk_test.go b/reflectwalk_test.go
index 8936a9a..83c49d6 100644
--- a/reflectwalk_test.go
+++ b/reflectwalk_test.go
@@ -49,6 +49,20 @@ func (t *TestPointerWalker) PointerExit(v bool) error {
 	return nil
 }
 
+type TestPointerValueWalker struct {
+	skip     bool
+	pointers []reflect.Type
+}
+
+func (t *TestPointerValueWalker) Pointer(v reflect.Value) error {
+	t.pointers = append(t.pointers, v.Type())
+	if t.skip {
+		return SkipEntry
+	}
+
+	return nil
+}
+
 type TestPrimitiveWalker struct {
 	Value reflect.Value
 }
@@ -482,6 +496,61 @@ func TestWalk_PointerPointer(t *testing.T) {
 	}
 }
 
+func TestWalk_PointerValue(t *testing.T) {
+	type X struct{}
+	type T struct {
+		x *X
+	}
+
+	v := &T{x: &X{}}
+
+	expected := []reflect.Type{
+		reflect.TypeOf(v),
+		reflect.TypeOf(v.x),
+	}
+
+	w := new(TestPointerValueWalker)
+	err := Walk(v, w)
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	if !reflect.DeepEqual(expected, w.pointers) {
+		t.Fatalf("unexpected pointer order or length (expected len=%d, actual len=%d)", len(expected), len(w.pointers))
+	}
+}
+
+func TestWalk_PointerValueSkip(t *testing.T) {
+	type T struct{}
+	type W struct {
+		TestPointerValueWalker
+		TestPointerWalker
+	}
+
+	v := &T{}
+	w := &W{
+		TestPointerValueWalker: TestPointerValueWalker{
+			skip: true,
+		},
+	}
+	err := Walk(v, w)
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	if len(w.TestPointerValueWalker.pointers) != 1 {
+		t.Errorf("expected len=1, got len=%d", len(w.TestPointerValueWalker.pointers))
+	}
+
+	if w.TestPointerValueWalker.pointers[0] != reflect.TypeOf(v) {
+		t.Error("pointer value type mismatch")
+	}
+
+	if w.enters != 0 || w.exits != 0 {
+		t.Error("should have been skipped and have zero enters or exits")
+	}
+}
+
 func TestWalk_Slice(t *testing.T) {
 	w := new(TestSliceWalker)
 

Debdiff

File lists identical (after any substitutions)

No differences were encountered in the control files

More details

Full run details