diff options
| author | Russ Cox <rsc@golang.org> | 2010-04-01 22:31:27 -0700 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2010-04-01 22:31:27 -0700 |
| commit | fb96dda6e66ab75e6cbcdfad2575fddd49eb5857 (patch) | |
| tree | 285fdef711a90a79f5cabf60b35dfe3b877702a0 /src/pkg/runtime/string.cgo | |
| parent | c536850d434ae3dd242417175287cd74c47d9063 (diff) | |
| download | golang-fb96dda6e66ab75e6cbcdfad2575fddd49eb5857.tar.gz | |
runtime: turn run time errors checks into panics
R=ken2, r
CC=golang-dev
http://codereview.appspot.com/871042
Committer: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/pkg/runtime/string.cgo')
| -rw-r--r-- | src/pkg/runtime/string.cgo | 47 |
1 files changed, 16 insertions, 31 deletions
diff --git a/src/pkg/runtime/string.cgo b/src/pkg/runtime/string.cgo index 4a96b83ec..005b0ffc8 100644 --- a/src/pkg/runtime/string.cgo +++ b/src/pkg/runtime/string.cgo @@ -78,34 +78,25 @@ gostringw(uint16 *str) return s; } -func catstring(s1 String, s2 String) (s3 String) { - if(s1.len == 0) { - s3 = s2; - goto out; - } - if(s2.len == 0) { - s3 = s1; - goto out; - } +String +catstring(String s1, String s2) +{ + String s3; + + if(s1.len == 0) + return s2; + if(s2.len == 0) + return s1; s3 = gostringsize(s1.len + s2.len); mcpy(s3.str, s1.str, s1.len); mcpy(s3.str+s1.len, s2.str, s2.len); -out: + return s3; } -static void -prbounds(int8* s, int32 a, int32 b, int32 c) -{ - prints(s); - prints(" "); - ·printint(a); - prints("<"); - ·printint(b); - prints(">"); - ·printint(c); - prints("\n"); - throw("string bounds"); + +func catstring(s1 String, s2 String) (s3 String) { + s3 = catstring(s1, s2); } uint32 @@ -159,9 +150,7 @@ func slicestring(si String, lindex int32, hindex int32) (so String) { if(lindex < 0 || lindex > si.len || hindex < lindex || hindex > si.len) { - ·printpc(&si); - prints(" "); - prbounds("slice", lindex, si.len, hindex); + ·panicslice(); } l = hindex-lindex; @@ -177,9 +166,7 @@ func slicestring1(si String, lindex int32) (so String) { int32 l; if(lindex < 0 || lindex > si.len) { - ·printpc(&si); - prints(" "); - prbounds("slice", lindex, si.len, si.len); + ·panicslice(); } l = si.len-lindex; @@ -193,9 +180,7 @@ func slicestring1(si String, lindex int32) (so String) { func indexstring(s String, i int32) (b byte) { if(i < 0 || i >= s.len) { - ·printpc(&s); - prints(" "); - prbounds("index", 0, i, s.len); + ·panicindex(); } b = s.str[i]; |
