runtime: remove C-style strcmp and strncmp helpers
Change-Id: I4aa23e3a0e765651c91907507a0194fd528b6223
Reviewed-on: https://go-review.googlesource.com/4662
Reviewed-by: Ian Lance Taylor <iant@golang.org>
diff --git a/src/runtime/os3_plan9.go b/src/runtime/os3_plan9.go
index facaab2..8ecbca0 100644
--- a/src/runtime/os3_plan9.go
+++ b/src/runtime/os3_plan9.go
@@ -10,11 +10,11 @@
_g_ := getg()
var t sigTabT
var docrash bool
- var length int
var sig int
var flags int
c := &sigctxt{_ureg}
+ notestr := gostringnocopy(note)
// The kernel will never pass us a nil note or ureg so we probably
// made a mistake somewhere in sigtramp.
@@ -24,8 +24,7 @@
}
// Check that the note is no more than ERRMAX bytes (including
// the trailing NUL). We should never receive a longer note.
- length = findnull(note)
- if length > _ERRMAX-1 {
+ if len(notestr) > _ERRMAX-1 {
print("sighandler: note is longer than ERRMAX\n")
goto Throw
}
@@ -34,11 +33,7 @@
// level by the program but will otherwise be ignored.
flags = _SigNotify
for sig, t = range sigtable {
- n := len(t.name)
- if length < n {
- continue
- }
- if strncmp(note, &t.name[0], uintptr(n)) == 0 {
+ if hasprefix(notestr, t.name) {
flags = t.flags
break
}
@@ -49,7 +44,7 @@
if flags&_SigPanic != 0 {
// Copy the error string from sigtramp's stack into m->notesig so
// we can reliably access it from the panic routines.
- memmove(unsafe.Pointer(_g_.m.notesig), unsafe.Pointer(note), uintptr(length+1))
+ memmove(unsafe.Pointer(_g_.m.notesig), unsafe.Pointer(note), uintptr(len(notestr)+1))
gp.sig = uint32(sig)
gp.sigpc = c.pc()
// Only push sigpanic if PC != 0.
@@ -86,7 +81,7 @@
_g_.m.throwing = 1
_g_.m.caughtsig = gp
startpanic()
- print(gostringnocopy(note), "\n")
+ print(notestr, "\n")
print("PC=", hex(c.pc()), "\n")
print("\n")
if gotraceback(&docrash) > 0 {
diff --git a/src/runtime/signal_plan9.go b/src/runtime/signal_plan9.go
index 37d2435..302f156 100644
--- a/src/runtime/signal_plan9.go
+++ b/src/runtime/signal_plan9.go
@@ -6,7 +6,7 @@
type sigTabT struct {
flags int
- name []byte
+ name string
}
// Incoming notes are compared against this table using strncmp, so the
@@ -18,37 +18,37 @@
// and also update the constant values is os2_plan9.go.
var sigtable = [...]sigTabT{
// Traps that we cannot be recovered.
- {_SigThrow, []byte("sys: trap: debug exception")},
- {_SigThrow, []byte("sys: trap: invalid opcode")},
+ {_SigThrow, "sys: trap: debug exception"},
+ {_SigThrow, "sys: trap: invalid opcode"},
// We can recover from some memory errors in runtime·sigpanic.
- {_SigPanic, []byte("sys: trap: fault read addr")}, // SIGRFAULT
- {_SigPanic, []byte("sys: trap: fault write addr")}, // SIGWFAULT
+ {_SigPanic, "sys: trap: fault read addr"}, // SIGRFAULT
+ {_SigPanic, "sys: trap: fault write addr"}, // SIGWFAULT
// We can also recover from math errors.
- {_SigPanic, []byte("sys: trap: divide error")}, // SIGINTDIV
- {_SigPanic, []byte("sys: fp:")}, // SIGFLOAT
+ {_SigPanic, "sys: trap: divide error"}, // SIGINTDIV
+ {_SigPanic, "sys: fp:"}, // SIGFLOAT
// All other traps are normally handled as if they were marked SigThrow.
// We mark them SigPanic here so that debug.SetPanicOnFault will work.
- {_SigPanic, []byte("sys: trap:")}, // SIGTRAP
+ {_SigPanic, "sys: trap:"}, // SIGTRAP
// Writes to a closed pipe can be handled if desired, otherwise they're ignored.
- {_SigNotify, []byte("sys: write on closed pipe")},
+ {_SigNotify, "sys: write on closed pipe"},
// Other system notes are more serious and cannot be recovered.
- {_SigThrow, []byte("sys:")},
+ {_SigThrow, "sys:"},
// Issued to all other procs when calling runtime·exit.
- {_SigGoExit, []byte("go: exit ")},
+ {_SigGoExit, "go: exit "},
// Kill is sent by external programs to cause an exit.
- {_SigKill, []byte("kill")},
+ {_SigKill, "kill"},
// Interrupts can be handled if desired, otherwise they cause an exit.
- {_SigNotify + _SigKill, []byte("interrupt")},
- {_SigNotify + _SigKill, []byte("hangup")},
+ {_SigNotify + _SigKill, "interrupt"},
+ {_SigNotify + _SigKill, "hangup"},
// Alarms can be handled if desired, otherwise they're ignored.
- {_SigNotify, []byte("alarm")},
+ {_SigNotify, "alarm"},
}
diff --git a/src/runtime/string1.go b/src/runtime/string1.go
index 35cde43..feeb341 100644
--- a/src/runtime/string1.go
+++ b/src/runtime/string1.go
@@ -67,42 +67,3 @@
b[n2] = 0 // for luck
return s[:n2]
}
-
-func strcmp(s1, s2 *byte) int32 {
- p1 := (*[_MaxMem/2 - 1]byte)(unsafe.Pointer(s1))
- p2 := (*[_MaxMem/2 - 1]byte)(unsafe.Pointer(s2))
-
- for i := uintptr(0); ; i++ {
- c1 := p1[i]
- c2 := p2[i]
- if c1 < c2 {
- return -1
- }
- if c1 > c2 {
- return +1
- }
- if c1 == 0 {
- return 0
- }
- }
-}
-
-func strncmp(s1, s2 *byte, n uintptr) int32 {
- p1 := (*[_MaxMem/2 - 1]byte)(unsafe.Pointer(s1))
- p2 := (*[_MaxMem/2 - 1]byte)(unsafe.Pointer(s2))
-
- for i := uintptr(0); i < n; i++ {
- c1 := p1[i]
- c2 := p2[i]
- if c1 < c2 {
- return -1
- }
- if c1 > c2 {
- return +1
- }
- if c1 == 0 {
- break
- }
- }
- return 0
-}