Check alignment.

geesefs-0-30-9
Aaron Jacobs 2015-07-28 16:23:10 +10:00
parent c210aa8a95
commit 114432703b
1 changed files with 12 additions and 0 deletions

View File

@ -15,6 +15,7 @@
package buffer package buffer
import ( import (
"log"
"unsafe" "unsafe"
"github.com/jacobsa/fuse/internal/fusekernel" "github.com/jacobsa/fuse/internal/fusekernel"
@ -36,6 +37,17 @@ type OutMessage struct {
storage [outMessageSize]byte storage [outMessageSize]byte
} }
// Make sure alignment works out correctly, at least for the header.
func init() {
a := unsafe.Alignof(OutMessage{})
o := unsafe.Offsetof(OutMessage{}.storage)
e := unsafe.Alignof(fusekernel.OutHeader{})
if a%e != 0 || o%e != 0 {
log.Panicf("Bad alignment or offset: %d, %d, need %d", a, o, e)
}
}
// Reset the message so that it is ready to be used again. Afterward, the // Reset the message so that it is ready to be used again. Afterward, the
// contents are solely a zeroed header. // contents are solely a zeroed header.
func (m *OutMessage) Reset() { func (m *OutMessage) Reset() {