Skip to content

Commit 56d6b87

Browse files
committed
runtime: change checkptr to use throw instead of panic
Updates #34964. Change-Id: I5afb2c1e77a9a47358a1d0d108c4a787d7172b94 Reviewed-on: https://go-review.googlesource.com/c/go/+/214217 Run-TryBot: Matthew Dempsky <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Austin Clements <[email protected]>
1 parent 6521965 commit 56d6b87

File tree

1 file changed

+4
-27
lines changed

1 file changed

+4
-27
lines changed

src/runtime/checkptr.go

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,22 @@ package runtime
66

77
import "unsafe"
88

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-
219
func checkptrAlignment(p unsafe.Pointer, elem *_type, n uintptr) {
2210
// Check that (*[n]elem)(p) is appropriately aligned.
2311
// TODO(mdempsky): What about fieldAlign?
2412
if uintptr(p)&(uintptr(elem.align)-1) != 0 {
25-
panic(ptrAlignError{p, elem, n})
13+
throw("checkptr: unsafe pointer conversion")
2614
}
2715

2816
// Check that (*[n]elem)(p) doesn't straddle multiple heap objects.
2917
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")
3119
}
3220
}
3321

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-
4522
func checkptrArithmetic(p unsafe.Pointer, originals []unsafe.Pointer) {
4623
if 0 < uintptr(p) && uintptr(p) < minLegalPointer {
47-
panic(ptrArithError{p, originals})
24+
throw("checkptr: unsafe pointer arithmetic")
4825
}
4926

5027
// Check that if the computed pointer p points into a heap
@@ -61,7 +38,7 @@ func checkptrArithmetic(p unsafe.Pointer, originals []unsafe.Pointer) {
6138
}
6239
}
6340

64-
panic(ptrArithError{p, originals})
41+
throw("checkptr: unsafe pointer arithmetic")
6542
}
6643

6744
// checkptrBase returns the base address for the allocation containing

0 commit comments

Comments
 (0)