]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: instrument slicebytetostring for race detection
authorDmitriy Vyukov <dvyukov@google.com>
Wed, 13 Feb 2013 14:29:59 +0000 (18:29 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Wed, 13 Feb 2013 14:29:59 +0000 (18:29 +0400)
R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/7322068

src/pkg/runtime/race/testdata/slice_test.go
src/pkg/runtime/string.goc

index 1440a5f13e2d276118fb827697f3d91cbbb8c5a2..773463662b2eee9654a56ada52438be308508863 100644 (file)
@@ -443,3 +443,23 @@ func TestRaceSliceIndexAccess2(t *testing.T) {
        _ = s[v]
        <-c
 }
+
+func TestRaceSliceByteToString(t *testing.T) {
+       c := make(chan string)
+       s := make([]byte, 10)
+       go func() {
+               c <- string(s)
+       }()
+       s[0] = 42
+       <-c
+}
+
+func TestRaceSliceRuneToString(t *testing.T) {
+       c := make(chan string)
+       s := make([]rune, 10)
+       go func() {
+               c <- string(s)
+       }()
+       s[9] = 42
+       <-c
+}
index cafcdb6cedcabe2edfaf960cdc35e3b16926582b..c0d3f2bde912997e6751a80ca7c0e0e95e3ffce8 100644 (file)
@@ -6,6 +6,7 @@ package runtime
 #include "runtime.h"
 #include "arch_GOARCH.h"
 #include "malloc.h"
+#include "race.h"
 
 String runtime·emptystring;
 
@@ -271,6 +272,12 @@ func intstring(v int64) (s String) {
 }
 
 func slicebytetostring(b Slice) (s String) {
+       void *pc;
+
+       if(raceenabled) {
+               pc = runtime·getcallerpc(&b);
+               runtime·racereadrangepc(b.array, b.len, 1, pc, runtime·slicebytetostring);
+       }
        s = gostringsize(b.len);
        runtime·memmove(s.str, b.array, s.len);
 }
@@ -286,7 +293,12 @@ func slicerunetostring(b Slice) (s String) {
        intgo siz1, siz2, i;
        int32 *a;
        byte dum[8];
+       void *pc;
 
+       if(raceenabled) {
+               pc = runtime·getcallerpc(&b);
+               runtime·racereadrangepc(b.array, b.len*sizeof(*a), sizeof(*a), pc, runtime·slicerunetostring);
+       }
        a = (int32*)b.array;
        siz1 = 0;
        for(i=0; i<b.len; i++) {