]> Cypherpunks.ru repositories - gostls13.git/commitdiff
code changes for array conversion.
authorRuss Cox <rsc@golang.org>
Thu, 16 Apr 2009 03:27:45 +0000 (20:27 -0700)
committerRuss Cox <rsc@golang.org>
Thu, 16 Apr 2009 03:27:45 +0000 (20:27 -0700)
as a reminder, the old conversion
was that you could write

var arr [10]byte;
var slice []byte;
slice = arr;

but now you have to write

slice = &arr;

the change eliminates an implicit &, so that
the only implicit &s left are in the . operator
and in string(arr).

also, removed utf8.EncodeRuneToString
in favor of string(rune).

R=r
DELTA=83  (1 added, 23 deleted, 59 changed)
OCL=27531
CL=27534

25 files changed:
doc/progs/cat.go
doc/progs/cat_rot13.go
doc/progs/sum.go
src/lib/exec.go
src/lib/exec_test.go
src/lib/go/scanner.go
src/lib/hash/md5.go
src/lib/hash/sha1.go
src/lib/http/fs.go
src/lib/io/pipe_test.go
src/lib/net/fd.go
src/lib/net/fd_darwin.go
src/lib/net/tcpserver_test.go
src/lib/net/timeout_test.go
src/lib/os/os_test.go
src/lib/sort_test.go
src/lib/tabwriter/tabwriter.go
src/lib/utf8.go
src/lib/utf8_test.go
test/fixedbugs/bug045.go
test/fixedbugs/bug059.go
test/ken/array.go
test/ken/rob2.go
usr/gri/pretty/platform.go
usr/gri/pretty/utils.go

index c06a730cefa55e30eaabfcc1f20dab03645b2bef..1f6c0f9df65c2115be9dcf0460d1f790c4e3ac91 100644 (file)
@@ -15,7 +15,7 @@ func cat(f *file.File) {
        const NBUF = 512;
        var buf [NBUF]byte;
        for {
-               switch nr, er := f.Read(buf); true {
+               switch nr, er := f.Read(&buf); true {
                case nr < 0:
                        fmt.Fprintf(os.Stderr, "error reading from %s: %s\n", f.String(), er.String());
                        sys.Exit(1);
index 618ae9111675956c72463e8b42c3bbca0a9f140f..aba8b4c7fb06afed270d1396a824d867b80505d8 100644 (file)
@@ -57,7 +57,7 @@ func cat(r reader) {
                r = newRotate13(r)
        }
        for {
-               switch nr, er := r.Read(buf); {
+               switch nr, er := r.Read(&buf); {
                case nr < 0:
                        fmt.Fprintf(os.Stderr, "error reading from %s: %s\n", r.String(), er.String());
                        sys.Exit(1);
index 19600af066ad9a84f6199b4cec804bc16e66c6c8..f087ca3e5c4b3f8f726d2b7c311ab7fb0ff862ce 100644 (file)
@@ -16,6 +16,6 @@ func sum(a []int) int {   // returns an int
 
 
 func main() {
-       s := sum([3]int{1,2,3});  // a slice of the array is passed to sum
+       s := sum(&[3]int{1,2,3});  // a slice of the array is passed to sum
        fmt.Print(s, "\n");
 }
index 425b94eb3ac8ecef0bbddfced6debb719511f18d..6808b95542e685209ea4424263ca74a36778653d 100644 (file)
@@ -96,7 +96,7 @@ func Run(argv0 string, argv, envv []string, stdin, stdout, stderr int) (p *Cmd,
        }
 
        // Run command.
-       p.Pid, err = os.ForkExec(argv0, argv, envv, fd);
+       p.Pid, err = os.ForkExec(argv0, argv, envv, &fd);
        if err != nil {
                goto Error;
        }
index f4038fbc2360547e4e12d9c4e4305083a329dd64..e67c75da3a0b8e98e62fdabab9ab1ac33872f95c 100644 (file)
@@ -19,7 +19,7 @@ func TestRunCat(t *testing.T) {
        io.WriteString(cmd.Stdin, "hello, world\n");
        cmd.Stdin.Close();
        var buf [64]byte;
-       n, err1 := io.Readn(cmd.Stdout, buf);
+       n, err1 := io.Readn(cmd.Stdout, &buf);
        if err1 != nil && err1 != io.ErrEOF {
                t.Fatalf("reading from /bin/cat: %v", err1);
        }
@@ -38,7 +38,7 @@ func TestRunEcho(t *testing.T) {
                t.Fatalf("opencmd /bin/echo: %v", err);
        }
        var buf [64]byte;
-       n, err1 := io.Readn(cmd.Stdout, buf);
+       n, err1 := io.Readn(cmd.Stdout, &buf);
        if err1 != nil && err1 != io.ErrEOF {
                t.Fatalf("reading from /bin/echo: %v", err1);
        }
index e35cc5c7223d11fb4f3eefb93a6e3dea574ac4ea..ea5f13769c9fba6b3cfb70abc8a3eb0e07da8dc5 100644 (file)
@@ -104,7 +104,7 @@ func charString(ch int) string {
        case '\v': s = `\v`;
        case '\\': s = `\\`;
        case '\'': s = `\'`;
-       default  : s = utf8.EncodeRuneToString(ch);
+       default  : s = string(ch);
        }
        return "'" + s + "' (U+" + strconv.Itob(ch, 16) + ")";
 }
index ab3201ffb8b562e897390b6279b5d7735bd3baf2..d9fc6157dc5e6dbe8728008ae0a3148821b23d85 100644 (file)
@@ -51,7 +51,7 @@ func (d *Digest) Write(p []byte) (nn int, err *os.Error) {
                }
                d.nx += n;
                if d.nx == _Chunk {
-                       _Block(d, d.x);
+                       _Block(d, &d.x);
                        d.nx = 0;
                }
                p = p[n:len(p)];
index 0bf284ef1ac49f1ceb821f47a7e0d17da7d4644c..788eda860ecc1385ca98c36db77acbe84ad6c99f 100644 (file)
@@ -53,7 +53,7 @@ func (d *Digest) Write(p []byte) (nn int, err *os.Error) {
                }
                d.nx += n;
                if d.nx == _Chunk {
-                       _Block(d, d.x);
+                       _Block(d, &d.x);
                        d.nx = 0;
                }
                p = p[n:len(p)];
index d93859dd25c086342e98d997962cb8e460991e10..23a994aa0d76d9bfb6f2333f16ec1e321fe9fa6e 100644 (file)
@@ -142,7 +142,7 @@ func serveFileInternal(c *Conn, r *Request, name string, redirect bool) {
        } else {
                // read first chunk to decide between utf-8 text and binary
                var buf [1024]byte;
-               n, err := io.Readn(f, buf);
+               n, err := io.Readn(f, &buf);
                b := buf[0:n];
                if isText(b) {
                        c.SetHeader("Content-Type", "text-plain; charset=utf-8");
index df2ed89417b08be156c2ced64f50267ff20b661e..3358ef20329064bf263c31d8f3696c604cfe21b8 100644 (file)
@@ -26,7 +26,7 @@ func checkWrite(t *testing.T, w io.Write, data []byte, c chan int) {
 func TestPipe1(t *testing.T) {
        c := make(chan int);
        r, w := io.Pipe();
-       var buf [64]byte;
+       var buf = make([]byte, 64);
        go checkWrite(t, w, io.StringBytes("hello, world"), c);
        n, err := r.Read(buf);
        if err != nil {
@@ -41,7 +41,7 @@ func TestPipe1(t *testing.T) {
 }
 
 func reader(t *testing.T, r io.Read, c chan int) {
-       var buf [64]byte;
+       var buf = make([]byte, 64);
        for {
                n, err := r.Read(buf);
                if err != nil {
@@ -59,7 +59,7 @@ func TestPipe2(t *testing.T) {
        c := make(chan int);
        r, w := io.Pipe();
        go reader(t, r, c);
-       var buf [64]byte;
+       var buf = make([]byte, 64);
        for i := 0; i < 5; i++ {
                p := buf[0:5+i*10];
                n, err := w.Write(p);
@@ -91,12 +91,12 @@ func writer(w io.WriteClose, buf []byte, c chan pipeReturn) {
 func TestPipe3(t *testing.T) {
        c := make(chan pipeReturn);
        r, w := io.Pipe();
-       var wdat [128]byte;
+       var wdat = make([]byte, 128);
        for i := 0; i < len(wdat); i++ {
                wdat[i] = byte(i);
        }
        go writer(w, wdat, c);
-       var rdat [1024]byte;
+       var rdat = make([]byte, 1024);
        tot := 0;
        for n := 1; n <= 256; n *= 2 {
                nn, err := r.Read(rdat[tot:tot+n]);
@@ -148,7 +148,7 @@ func testPipeReadClose(t *testing.T, async bool) {
        } else {
                delayClose(t, w, c);
        }
-       var buf [64]byte;
+       var buf = make([]byte, 64);
        n, err := r.Read(buf);
        <-c;
        if err != nil {
index c098c20b20f9ef47bdead08cb8a1d10201363b85..8b26efed503e1bec285d7c93a5094f33997429f8 100644 (file)
@@ -265,8 +265,8 @@ func (s *pollServer) Run() {
                }
                if fd == s.pr.Fd() {
                        // Drain our wakeup pipe.
-                       for nn, e := s.pr.Read(scratch); nn > 0; {
-                               nn, e = s.pr.Read(scratch)
+                       for nn, e := s.pr.Read(&scratch); nn > 0; {
+                               nn, e = s.pr.Read(&scratch)
                        }
 
                        // Read from channels
@@ -287,9 +287,9 @@ func (s *pollServer) Run() {
        }
 }
 
+var wakeupbuf [1]byte;
 func (s *pollServer) Wakeup() {
-       var b [1]byte;
-       s.pw.Write(b)
+       s.pw.Write(&wakeupbuf)
 }
 
 func (s *pollServer) WaitRead(fd *netFD) {
index 74f0f48677937c5b352f841833c4f9871bab15f5..c543755b97fc5ca326ab4276dc7db4ad0d8f4c74 100644 (file)
@@ -49,7 +49,7 @@ func (p *pollster) AddFD(fd int64, mode int, repeat bool) *os.Error {
                ev.Flags |= syscall.EV_ONESHOT
        }
 
-       n, e := syscall.Kevent(p.kq, events, events, nil);
+       n, e := syscall.Kevent(p.kq, &events, &events, nil);
        if e != 0 {
                return os.ErrnoToError(e)
        }
@@ -78,7 +78,7 @@ func (p *pollster) DelFD(fd int64, mode int) {
        // EV_RECEIPT - generate fake EV_ERROR as result of add,
        //      rather than waiting for real event
        ev.Flags = syscall.EV_DELETE | syscall.EV_RECEIPT;
-       syscall.Kevent(p.kq, events, events, nil);
+       syscall.Kevent(p.kq, &events, &events, nil);
 }
 
 func (p *pollster) WaitFD(nsec int64) (fd int64, mode int, err *os.Error) {
@@ -91,7 +91,7 @@ func (p *pollster) WaitFD(nsec int64) (fd int64, mode int, err *os.Error) {
                        t.Sec = nsec / 1e9;
                        t.Nsec = uint64(nsec % 1e9);
                }
-               nn, e := syscall.Kevent(p.kq, nil, p.eventbuf, t);
+               nn, e := syscall.Kevent(p.kq, nil, &p.eventbuf, t);
                if e != 0 {
                        if e == syscall.EINTR {
                                continue
index 820220b033828056eae02962597ab41ef487f319..11b13664b1a1c20c74007ee44a079a830a199f76 100644 (file)
@@ -15,7 +15,7 @@ func runEcho(fd io.ReadWrite, done chan<- int) {
        var buf [1024]byte;
 
        for {
-               n, err := fd.Read(buf);
+               n, err := fd.Read(&buf);
                if err != nil || n == 0 {
                        break;
                }
@@ -58,7 +58,7 @@ func connect(t *testing.T, network, addr string) {
                t.Fatalf("fd.Write(%q) = %d, %v", b, n, errno);
        }
 
-       n, errno = fd.Read(b1);
+       n, errno = fd.Read(&b1);
        if n != len(b) {
                t.Fatalf("fd.Read() = %d, %v", n, errno);
        }
index e1ce9178906d59ebbd3253632e51b559b7be15e9..d94b049402fb663c45e902991ce04cd9c3fd9ebf 100644 (file)
@@ -20,7 +20,7 @@ func testTimeout(t *testing.T, network, addr string) {
        t0 := time.Nanoseconds();
        fd.SetReadTimeout(1e8); // 100ms
        var b [100]byte;
-       n, err1 := fd.Read(b);
+       n, err1 := fd.Read(&b);
        t1 := time.Nanoseconds();
        if n != 0 || err1 != os.EAGAIN {
                t.Errorf("fd.Read on %s %s did not return 0, EAGAIN: %v, %v", network, addr, n, err1);
index 93a2c5e089b6d565051442ab85b08fc4bf5bd3d4..7349b22476dcec86599cfd92cb6171ffbba2f891 100644 (file)
@@ -38,7 +38,7 @@ func size(name string, t *testing.T) uint64 {
        var buf [100]byte;
        len := 0;
        for {
-               n, e := file.Read(buf);
+               n, e := file.Read(&buf);
                if n < 0 || e != nil {
                        t.Fatal("read failed:", err);
                }
index aa80aa10e3607d9620aa212ff6f11fe6d7870f73..d6c8f90e968eb9fa10647ce10d88a901020a5b68 100644 (file)
@@ -48,8 +48,8 @@ func TestSortStringArray(t *testing.T) {
 
 func TestSortInts(t *testing.T) {
        data := ints;
-       sort.SortInts(data);
-       if !sort.IntsAreSorted(data) {
+       sort.SortInts(&data);
+       if !sort.IntsAreSorted(&data) {
                t.Errorf("sorted %v", ints);
                t.Errorf("   got %v", data);
        }
@@ -57,8 +57,8 @@ func TestSortInts(t *testing.T) {
 
 func TestSortFloats(t *testing.T) {
        data := floats;
-       sort.SortFloats(data);
-       if !sort.FloatsAreSorted(data) {
+       sort.SortFloats(&data);
+       if !sort.FloatsAreSorted(&data) {
                t.Errorf("sorted %v", floats);
                t.Errorf("   got %v", data);
        }
@@ -66,8 +66,8 @@ func TestSortFloats(t *testing.T) {
 
 func TestSortStrings(t *testing.T) {
        data := strings;
-       sort.SortStrings(data);
-       if !sort.StringsAreSorted(data) {
+       sort.SortStrings(&data);
+       if !sort.StringsAreSorted(&data) {
                t.Errorf("sorted %v", strings);
                t.Errorf("   got %v", data);
        }
index 26679740bb12edb29db8325bc5e2d1b02536b6ad..fa0437d0894b37c90778d2530e18633e8dc88f81 100644 (file)
@@ -249,7 +249,7 @@ func (b *Writer) writePadding(textw, cellw int) (err *os.Error) {
        }
 
        for n > len(b.padbytes) {
-               err = b.write0(b.padbytes);
+               err = b.write0(&b.padbytes);
                if err != nil {
                        goto exit;
                }
index 448f4819cc5d6c7529bae51d60aee28c3c1b1314..ff55df80210b6076af0d662def66abd944a6ae24 100644 (file)
@@ -256,17 +256,6 @@ func EncodeRune(rune int, p []byte) int {
        return 4;
 }
 
-// EncodeRuneToString returns the UTF-8 encoding of the rune.
-func EncodeRuneToString(rune int) string {
-       if rune < _Rune1Max {
-               return string([1]byte{byte(rune)})
-       }
-
-       var buf [UTFMax]byte;
-       size := EncodeRune(rune, buf);
-       return string(buf[0:size]);
-}
-
 // RuneCount returns the number of runes in p.  Erroneous and short
 // encodings are treated as single runes of width 1 byte.
 func RuneCount(p []byte) int {
index 966b2c97515122f405cd0a006835843f04848e4d..1f29cb82d926c763cc0ec633700f7239a5f840c1 100644 (file)
@@ -90,7 +90,7 @@ func TestEncodeRune(t *testing.T) {
                m := utf8map[i];
                b := bytes(m.str);
                var buf [10]byte;
-               n := utf8.EncodeRune(m.rune, buf);
+               n := utf8.EncodeRune(m.rune, &buf);
                b1 := buf[0:n];
                if !equalBytes(b, b1) {
                        t.Errorf("EncodeRune(0x%04x) = %q want %q", m.rune, b1, b);
@@ -98,17 +98,6 @@ func TestEncodeRune(t *testing.T) {
        }
 }
 
-func TestEncodeRuneToString(t *testing.T) {
-       for i := 0; i < len(utf8map); i++ {
-               m := utf8map[i];
-               s := m.str;
-               s1 := utf8.EncodeRuneToString(m.rune);
-               if s != s1 {
-                       t.Errorf("EncodeRuneToString(0x%04x) = %s want %s", m.rune, s1, s);
-               }
-       }
-}
-
 func TestDecodeRune(t *testing.T) {
        for i := 0; i < len(utf8map); i++ {
                m := utf8map[i];
index 88c005d32da67d1f6e5c3d11a662812d76e18c62..d8a712c6dab0cf47f65bd25b4684850220185abf 100644 (file)
@@ -13,7 +13,7 @@ type T struct {
 func main() {
        var ta []*T;
 
-       ta = *new([1]*T);       // TODO: the first * shouldn't be necessary
+       ta = new([1]*T);
        ta[0] = nil;
 }
 /*
index 21c078361bb75ae4c7f424071ff01e429d495ce3..44f60fedbcb2a0fbc927aaebb01983416dd4cba6 100644 (file)
@@ -23,7 +23,7 @@ func main() {
        as := new([2]string);
        as[0] = "0";
        as[1] = "1";
-       m["0"] = *as;
+       m["0"] = as;
 
        a := m["0"];
        a[0] = "x";
index e1a3aed3a86dd865e370ec7f0658a19ec1b0d075..809d243a42c6186e500f73deb840aeb56ebe6721 100644 (file)
@@ -96,8 +96,8 @@ func
 testpdpf1()
 {
        a := new([40]int);
-       setpd(*a);
-       res(sumpd(*a), 0, 40);
+       setpd(a);
+       res(sumpd(a), 0, 40);
 
        b := (*a)[5:30];
        res(sumpd(b), 5, 30);
@@ -109,8 +109,8 @@ testpdpf2()
 {
        var a [80]int;
 
-       setpd(a);
-       res(sumpd(a), 0, 80);
+       setpd(&a);
+       res(sumpd(&a), 0, 80);
 }
 
 // generate bounds error with ptr dynamic
index 1b4d86e6f2a516f007599c3df97cc504a97b192e..29be2efcc183e7cda592e82fec5ef5e910e60829 100644 (file)
@@ -241,7 +241,7 @@ func atom(i int) *Slist     // BUG: uses tokenbuf; should take argument
                slist.atom.integer = i;
                slist.isstring = false;
        } else {
-               slist.atom.str = string(tokenbuf)[0:tokenlen];
+               slist.atom.str = string(tokenbuf[0:tokenlen]);
                slist.isstring = true;
        }
        slist.isatom = true;
index ed680305247fb185561b1e6bbd4301b6cd96d235..90b9d5ebb960311fd8153cc7a70ee85bfffdda5f 100644 (file)
@@ -43,7 +43,7 @@ func readfile(filename string) ([]byte, *OS.Error) {
                return []byte{}, err;
        }
        var buf [1<<20]byte;
-       n, err1 := IO.Readn(f, buf);
+       n, err1 := IO.Readn(f, &buf);
        f.Close();
        if err1 == IO.ErrEOF {
                err1 = nil;
index 1b925b4833b6eca0b3513fb16d79acaa31f17647..baacc75de53f84ae99683074bdba9d8cb14eb93f 100644 (file)
@@ -87,5 +87,5 @@ func IntToString(x, base int) string {
                buf[i] = '-';
        }
 
-       return string(buf)[i : len(buf)];
+       return string(buf[i : len(buf)]);
 }