fix:correct Sizeof to align size properly
This commit is contained in:
@@ -114,7 +114,7 @@ func (p *goProgram) Offsetsof(fields []*types.Var) (ret []int64) {
|
||||
func (p *goProgram) Sizeof(T types.Type) int64 {
|
||||
prog := Program(p)
|
||||
ptrSize := int64(prog.PointerSize())
|
||||
return prog.sizes.Sizeof(T) + extraSize(T, ptrSize)
|
||||
return align((prog.sizes.Sizeof(T) + extraSize(T, ptrSize)), prog.sizes.Alignof(T))
|
||||
}
|
||||
|
||||
func extraSize(t types.Type, ptrSize int64) (ret int64) {
|
||||
@@ -134,6 +134,10 @@ func extraSize(t types.Type, ptrSize int64) (ret int64) {
|
||||
return 0
|
||||
}
|
||||
|
||||
func align(x, a int64) int64 {
|
||||
return (x + a - 1) &^ (a - 1)
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
type rawType struct {
|
||||
|
||||
Reference in New Issue
Block a user