Commit 928fe05a authored by Russ Cox's avatar Russ Cox

reflect: record unsafe.Pointer, not uintptr, during DeepEqual

This is more correct with respect to garbage collection.
I don't know of any specific failures it could cause today.

Change-Id: I7eed6a06d2f281051199e79e4a9913aa8360ded7
Reviewed-on: https://go-review.googlesource.com/14137Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent ace30329
......@@ -6,13 +6,15 @@
package reflect
import "unsafe"
// During deepValueEqual, must keep track of checks that are
// in progress. The comparison algorithm assumes that all
// checks in progress are true when it reencounters them.
// Visited comparisons are stored in a map indexed by visit.
type visit struct {
a1 uintptr
a2 uintptr
a1 unsafe.Pointer
a2 unsafe.Pointer
typ Type
}
......@@ -37,9 +39,9 @@ func deepValueEqual(v1, v2 Value, visited map[visit]bool, depth int) bool {
}
if v1.CanAddr() && v2.CanAddr() && hard(v1.Kind()) {
addr1 := v1.UnsafeAddr()
addr2 := v2.UnsafeAddr()
if addr1 > addr2 {
addr1 := unsafe.Pointer(v1.UnsafeAddr())
addr2 := unsafe.Pointer(v2.UnsafeAddr())
if uintptr(addr1) > uintptr(addr2) {
// Canonicalize order to reduce number of entries in visited.
addr1, addr2 = addr2, addr1
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment