diff options
author | Damian Gryski <[email protected]> | 2023-03-22 10:12:42 -0700 |
---|---|---|
committer | Ayke <[email protected]> | 2023-03-27 18:53:37 +0200 |
commit | 39f76f43fc647061a22571950ca2725f70ebd0c4 (patch) | |
tree | 88fb48398b6b0d06ffb0c9b3d33134d9a3a94ea2 | |
parent | f239e8e2d918322d67c80bf4f44a78d35da18f96 (diff) | |
download | tinygo-39f76f43fc647061a22571950ca2725f70ebd0c4.tar.gz tinygo-39f76f43fc647061a22571950ca2725f70ebd0c4.zip |
reflect: fix indirect issues with makeInt/makeUint/makeFloat
-rw-r--r-- | src/reflect/value.go | 55 |
1 files changed, 33 insertions, 22 deletions
diff --git a/src/reflect/value.go b/src/reflect/value.go index 2cbd4a7cf..53bd573ba 100644 --- a/src/reflect/value.go +++ b/src/reflect/value.go @@ -1235,7 +1235,18 @@ func cvtBytesString(v Value, t *rawType) Value { func makeInt(flags valueFlags, bits uint64, t *rawType) Value { size := t.Size() - ptr := alloc(size, nil) + + v := Value{ + typecode: t, + flags: flags, + } + + ptr := unsafe.Pointer(&v.value) + if size > unsafe.Sizeof(uintptr(0)) { + ptr = alloc(size, nil) + v.value = ptr + } + switch size { case 1: *(*uint8)(ptr) = uint8(bits) @@ -1246,38 +1257,38 @@ func makeInt(flags valueFlags, bits uint64, t *rawType) Value { case 8: *(*uint64)(ptr) = bits } - return Value{ - typecode: t, - value: ptr, - flags: flags | valueFlagIndirect, - } + return v } -func makeFloat(flags valueFlags, v float64, t *rawType) Value { +func makeFloat(flags valueFlags, f float64, t *rawType) Value { size := t.Size() - ptr := alloc(size, nil) + + v := Value{ + typecode: t, + flags: flags, + } + + ptr := unsafe.Pointer(&v.value) + if size > unsafe.Sizeof(uintptr(0)) { + ptr = alloc(size, nil) + } + switch size { case 4: - *(*float32)(ptr) = float32(v) + *(*float32)(ptr) = float32(f) case 8: - *(*float64)(ptr) = v - } - return Value{ - typecode: t, - value: ptr, - flags: flags | valueFlagIndirect, + *(*float64)(ptr) = f } + return v } -func makeFloat32(flags valueFlags, v float32, t *rawType) Value { - size := t.Size() - ptr := alloc(size, nil) - *(*float32)(ptr) = float32(v) - return Value{ +func makeFloat32(flags valueFlags, f float32, t *rawType) Value { + v := Value{ typecode: t, - value: ptr, - flags: flags | valueFlagIndirect, + flags: flags, } + *(*float32)(unsafe.Pointer(&v.value)) = float32(f) + return v } func cvtIntString(src Value, t *rawType) Value { |