reflect.Value: Uint fix
This commit is contained in:
28
_cmptest/printfdemo/demo.go
Normal file
28
_cmptest/printfdemo/demo.go
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/goplus/llgo/xtool/nm"
|
||||
)
|
||||
|
||||
func main() {
|
||||
sym := nm.Symbol{Name: "abc", Type: nm.Text}
|
||||
fmt.Printf("%016x %c %s\n", sym.Addr, sym.Type, sym.Name)
|
||||
}
|
||||
@@ -1579,8 +1579,10 @@ func (v Value) CanUint() bool {
|
||||
// Uint returns v's underlying value, as a uint64.
|
||||
// It panics if v's Kind is not Uint, Uintptr, Uint8, Uint16, Uint32, or Uint64.
|
||||
func (v Value) Uint() uint64 {
|
||||
f := v.flag
|
||||
k := v.kind()
|
||||
p := v.ptr
|
||||
if f&flagAddr != 0 {
|
||||
switch k {
|
||||
case Uint:
|
||||
return uint64(*(*uint)(p))
|
||||
@@ -1595,10 +1597,21 @@ func (v Value) Uint() uint64 {
|
||||
case Uintptr:
|
||||
return uint64(*(*uintptr)(p))
|
||||
}
|
||||
} else if unsafe.Sizeof(uintptr(0)) == 8 {
|
||||
if k >= Uint && k <= Uintptr {
|
||||
return uint64(uintptr(p))
|
||||
}
|
||||
} else {
|
||||
if k >= Uint && k <= Uint32 {
|
||||
return uint64(uintptr(p))
|
||||
}
|
||||
if k == Uint64 || k == Uintptr {
|
||||
return *(*uint64)(p)
|
||||
}
|
||||
}
|
||||
panic(&ValueError{"reflect.Value.Uint", v.kind()})
|
||||
}
|
||||
|
||||
//go:nocheckptr
|
||||
// This prevents inlining Value.UnsafeAddr when -d=checkptr is enabled,
|
||||
// which ensures cmd/compile can recognize unsafe.Pointer(v.UnsafeAddr())
|
||||
// and make an exception.
|
||||
|
||||
Reference in New Issue
Block a user