@@ -6,45 +6,22 @@ package runtime
6
6
7
7
import "unsafe"
8
8
9
- type ptrAlignError struct {
10
- ptr unsafe.Pointer
11
- elem * _type
12
- n uintptr
13
- }
14
-
15
- func (e ptrAlignError ) RuntimeError () {}
16
-
17
- func (e ptrAlignError ) Error () string {
18
- return "runtime error: unsafe pointer conversion"
19
- }
20
-
21
9
func checkptrAlignment (p unsafe.Pointer , elem * _type , n uintptr ) {
22
10
// Check that (*[n]elem)(p) is appropriately aligned.
23
11
// TODO(mdempsky): What about fieldAlign?
24
12
if uintptr (p )& (uintptr (elem .align )- 1 ) != 0 {
25
- panic ( ptrAlignError { p , elem , n } )
13
+ throw ( "checkptr: unsafe pointer conversion" )
26
14
}
27
15
28
16
// Check that (*[n]elem)(p) doesn't straddle multiple heap objects.
29
17
if size := n * elem .size ; size > 1 && checkptrBase (p ) != checkptrBase (add (p , size - 1 )) {
30
- panic ( ptrAlignError { p , elem , n } )
18
+ throw ( "checkptr: unsafe pointer conversion" )
31
19
}
32
20
}
33
21
34
- type ptrArithError struct {
35
- ptr unsafe.Pointer
36
- originals []unsafe.Pointer
37
- }
38
-
39
- func (e ptrArithError ) RuntimeError () {}
40
-
41
- func (e ptrArithError ) Error () string {
42
- return "runtime error: unsafe pointer arithmetic"
43
- }
44
-
45
22
func checkptrArithmetic (p unsafe.Pointer , originals []unsafe.Pointer ) {
46
23
if 0 < uintptr (p ) && uintptr (p ) < minLegalPointer {
47
- panic ( ptrArithError { p , originals } )
24
+ throw ( "checkptr: unsafe pointer arithmetic" )
48
25
}
49
26
50
27
// Check that if the computed pointer p points into a heap
@@ -61,7 +38,7 @@ func checkptrArithmetic(p unsafe.Pointer, originals []unsafe.Pointer) {
61
38
}
62
39
}
63
40
64
- panic ( ptrArithError { p , originals } )
41
+ throw ( "checkptr: unsafe pointer arithmetic" )
65
42
}
66
43
67
44
// checkptrBase returns the base address for the allocation containing
0 commit comments