import "unsafe"
-type ptrAlign struct {
+type ptrAlignError struct {
ptr unsafe.Pointer
elem *_type
n uintptr
}
+func (e ptrAlignError) RuntimeError() {}
+
+func (e ptrAlignError) Error() string {
+ return "runtime error: unsafe pointer conversion"
+}
+
func checkptrAlignment(p unsafe.Pointer, elem *_type, n uintptr) {
// Check that (*[n]elem)(p) is appropriately aligned.
// TODO(mdempsky): What about fieldAlign?
if uintptr(p)&(uintptr(elem.align)-1) != 0 {
- panic(ptrAlign{p, elem, n})
+ panic(ptrAlignError{p, elem, n})
}
// Check that (*[n]elem)(p) doesn't straddle multiple heap objects.
if size := n * elem.size; size > 1 && checkptrBase(p) != checkptrBase(add(p, size-1)) {
- panic(ptrAlign{p, elem, n})
+ panic(ptrAlignError{p, elem, n})
}
}
-type ptrArith struct {
+type ptrArithError struct {
ptr unsafe.Pointer
originals []unsafe.Pointer
}
+func (e ptrArithError) RuntimeError() {}
+
+func (e ptrArithError) Error() string {
+ return "runtime error: unsafe pointer arithmetic"
+}
+
func checkptrArithmetic(p unsafe.Pointer, originals []unsafe.Pointer) {
if 0 < uintptr(p) && uintptr(p) < minLegalPointer {
- panic(ptrArith{p, originals})
+ panic(ptrArithError{p, originals})
}
// Check that if the computed pointer p points into a heap
}
}
- panic(ptrArith{p, originals})
+ panic(ptrArithError{p, originals})
}
func checkptrBase(p unsafe.Pointer) uintptr {