From 01635b5efdafabaabf13bf9cbd87fb24557ff8f7 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Thu, 6 Sep 2018 09:59:32 +0200 Subject: [PATCH] runtime: move panic functions to a separate file --- src/runtime/panic.go | 34 ++++++++++++++++++++++++++++++++++ src/runtime/runtime.go | 33 --------------------------------- 2 files changed, 34 insertions(+), 33 deletions(-) create mode 100644 src/runtime/panic.go diff --git a/src/runtime/panic.go b/src/runtime/panic.go new file mode 100644 index 00000000..eb49c12c --- /dev/null +++ b/src/runtime/panic.go @@ -0,0 +1,34 @@ +package runtime + +func _panic(message interface{}) { + printstring("panic: ") + printitf(message) + printnl() + abort() +} + +// Check for bounds in *ssa.Index, *ssa.IndexAddr and *ssa.Lookup. +func lookupBoundsCheck(length, index int) { + if index < 0 || index >= length { + // printstring() here is safe as this function is excluded from bounds + // checking. + printstring("panic: runtime error: index out of range\n") + abort() + } +} + +// Check for bounds in *ssa.Slice. +func sliceBoundsCheck(length, low, high uint) { + if !(0 <= low && low <= high && high <= length) { + printstring("panic: runtime error: slice out of range\n") + abort() + } +} + +// Check for bounds in *ssa.MakeSlice. +func sliceBoundsCheckMake(length, capacity uint) { + if !(0 <= length && length <= capacity) { + printstring("panic: runtime error: slice size out of range\n") + abort() + } +} diff --git a/src/runtime/runtime.go b/src/runtime/runtime.go index 013fdf7c..e7c7f23b 100644 --- a/src/runtime/runtime.go +++ b/src/runtime/runtime.go @@ -81,36 +81,3 @@ func memequal(x, y unsafe.Pointer, n uintptr) bool { } return true } - -func _panic(message interface{}) { - printstring("panic: ") - printitf(message) - printnl() - abort() -} - -// Check for bounds in *ssa.Index, *ssa.IndexAddr and *ssa.Lookup. -func lookupBoundsCheck(length, index int) { - if index < 0 || index >= length { - // printstring() here is safe as this function is excluded from bounds - // checking. - printstring("panic: runtime error: index out of range\n") - abort() - } -} - -// Check for bounds in *ssa.Slice. -func sliceBoundsCheck(length, low, high uint) { - if !(0 <= low && low <= high && high <= length) { - printstring("panic: runtime error: slice out of range\n") - abort() - } -} - -// Check for bounds in *ssa.MakeSlice. -func sliceBoundsCheckMake(length, capacity uint) { - if !(0 <= length && length <= capacity) { - printstring("panic: runtime error: slice size out of range\n") - abort() - } -}