From 8c45dddd5de44a5c2f469d80195f8347d7baa41c Mon Sep 17 00:00:00 2001 From: qiulaidongfeng <2645477756@qq.com> Date: Tue, 23 Jan 2024 00:42:58 +0000 Subject: [PATCH] reflect: delete TODO pass safe to packEface don't need to copy if safe==true 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 Reviewed-by: Cherry Mui Reviewed-by: Keith Randall TryBot-Result: Gopher Robot Reviewed-by: Keith Randall Auto-Submit: Keith Randall --- src/reflect/value.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/reflect/value.go b/src/reflect/value.go index 06f22f7428..8f163fce16 100644 --- a/src/reflect/value.go +++ b/src/reflect/value.go @@ -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) } -- 2.48.1