]> Cypherpunks repositories - gostls13.git/commitdiff
reflect: delete TODO pass safe to packEface don't need to copy if safe==true
authorqiulaidongfeng <2645477756@qq.com>
Tue, 23 Jan 2024 00:42:58 +0000 (00:42 +0000)
committerGopher Robot <gobot@golang.org>
Tue, 23 Jan 2024 17:19:58 +0000 (17:19 +0000)
valueInterface not copy result in the follow incorrect behavior
w1.  x := ValueOf(&v).Elem()
r1.  iface := Value.Interface()
w2.  x.Set() or x.SetT()

The write operation of W2 will be observed by the read operation of r1,
but the existing behavior is not.

The valueInterface in deepValueEqual can, in theory, pass safe==true to not copy the object,
but there is no benchmark to indicate that the memory allocation has changed,
maybe we don't actually need safe==true here.

Change-Id: I55c423fd50adac8822a7fdbfe67af89ee223eace
GitHub-Last-Rev: 4a6386709817f3ea6055711dd39d2694d58b3043
GitHub-Pull-Request: golang/go#64618
Reviewed-on: https://go-review.googlesource.com/c/go/+/548436
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Keith Randall <khr@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Keith Randall <khr@golang.org>

src/reflect/value.go

index 06f22f7428139f57d06412662cf9cd3880626111..8f163fce161b7791a5dffbb310cfdc7668dbdfee 100644 (file)
@@ -129,8 +129,6 @@ func packEface(v Value) any {
                // Value is indirect, and so is the interface we're making.
                ptr := v.ptr
                if v.flag&flagAddr != 0 {
-                       // TODO: pass safe boolean from valueInterface so
-                       // we don't need to copy if safe==true?
                        c := unsafe_New(t)
                        typedmemmove(t, c, ptr)
                        ptr = c
@@ -1522,7 +1520,6 @@ func valueInterface(v Value, safe bool) any {
                })(v.ptr)
        }
 
-       // TODO: pass safe to packEface so we don't need to copy if safe==true?
        return packEface(v)
 }