]> Cypherpunks repositories - gostls13.git/commitdiff
bug146: array/slice conversion before I left missed conversions
authorRuss Cox <rsc@golang.org>
Thu, 30 Apr 2009 20:49:58 +0000 (13:49 -0700)
committerRuss Cox <rsc@golang.org>
Thu, 30 Apr 2009 20:49:58 +0000 (13:49 -0700)
R=ken
OCL=28120
CL=28124

src/cmd/gc/walk.c
src/lib/net/net_darwin.go
src/lib/net/net_linux.go
src/lib/sort_test.go
test/fixedbugs/bug146.go [moved from test/bugs/bug146.go with 100% similarity]
test/golden.out

index fb7265980e5c28381b7ff87ac465b59bf6ee68b6..dab085e2765ca01c64fc2d112a30d37977402852 100644 (file)
@@ -1245,8 +1245,8 @@ walkconv(Node *n)
                return;
 
        // convert static array to dynamic array
-       if(isslice(t) && isfixedarray(l->type)) {
-               if(eqtype(t->type->type, l->type->type->type, 0)) {
+       if(isslice(t) && isptr[l->type->etype] && isfixedarray(l->type->type)) {
+               if(eqtype(t->type->type, l->type->type->type->type, 0)) {
                        indir(n, arrayop(n, Erv));
                        return;
                }
@@ -2707,7 +2707,9 @@ arrayop(Node *n, int top)
 
        case OCONV:
                // arrays2d(old *any, nel int) (ary []any)
-               t = fixarray(n->left->type);
+               if(n->left->type == T || !isptr[n->left->type->etype])
+                       break;
+               t = fixarray(n->left->type->type);
                tl = fixarray(n->type);
                if(t == T || tl == T)
                        break;
@@ -2717,39 +2719,20 @@ arrayop(Node *n, int top)
                a->type = types[TINT];
                r = a;
 
-               a = nod(OADDR, n->left, N);             // old
-               addrescapes(n->left);
-               r = list(a, r);
+               r = list(n->left, r);                           // old
 
                on = syslook("arrays2d", 1);
                argtype(on, t);                         // any-1
                argtype(on, tl->type);                  // any-2
                r = nod(OCALL, on, r);
-               walktype(r, top);
                n->left = r;
+               walktype(n, top);
                return n;
 
        case OAS:
-               // arrays2d(old *any, nel int) (ary []any)
-               t = fixarray(n->right->type->type);
-               tl = fixarray(n->left->type);
-               if(t == T || tl == T)
-                       break;
-
-               a = nodintconst(t->bound);              // nel
-               a = nod(OCONV, a, N);
-               a->type = types[TINT];
-               r = a;
-
-               r = list(n->right, r);                  // old
-
-               on = syslook("arrays2d", 1);
-               argtype(on, t);                         // any-1
-               argtype(on, tl->type);                  // any-2
-               r = nod(OCALL, on, r);
-
-               walktype(r, top);
-               n->right = r;
+               r = nod(OCONV, n->right, N);
+               r->type = n->left->type;
+               n->right = arrayop(r, Erv);
                return n;
 
        case OMAKE:
index 7e85f089b5601011fed925ffa9668e128d738ed4..2419f6c6debc1526c8dde23d11abe937032bf5b9 100644 (file)
@@ -48,14 +48,14 @@ func sockaddrToIP(sa1 *syscall.Sockaddr) (p IP, port int, err os.Error) {
        switch sa1.Family {
        case syscall.AF_INET:
                sa := (*syscall.SockaddrInet4)(unsafe.Pointer(sa1));
-               a := IP(sa.Addr).To16();
+               a := IP(&sa.Addr).To16();
                if a == nil {
                        return nil, 0, os.EINVAL
                }
                return a, int(sa.Port[0])<<8 + int(sa.Port[1]), nil;
        case syscall.AF_INET6:
                sa := (*syscall.SockaddrInet6)(unsafe.Pointer(sa1));
-               a := IP(sa.Addr).To16();
+               a := IP(&sa.Addr).To16();
                if a == nil {
                        return nil, 0, os.EINVAL
                }
index b6bfe7646c16d2014fcfd39ca93ee26f4d1f1293..9b55f67e6ab5c2ea17c6166a4f6f91f29a63cf55 100644 (file)
@@ -53,14 +53,14 @@ func sockaddrToIP(sa1 *syscall.Sockaddr) (p IP, port int, err os.Error) {
        switch sa1.Family {
        case syscall.AF_INET:
                sa := (*syscall.SockaddrInet4)(unsafe.Pointer(sa1));
-               a := IP(sa.Addr).To16();
+               a := IP(&sa.Addr).To16();
                if a == nil {
                        return nil, 0, os.EINVAL
                }
                return a, int(sa.Port[0])<<8 + int(sa.Port[1]), nil;
        case syscall.AF_INET6:
                sa := (*syscall.SockaddrInet6)(unsafe.Pointer(sa1));
-               a := IP(sa.Addr).To16();
+               a := IP(&sa.Addr).To16();
                if a == nil {
                        return nil, 0, os.EINVAL
                }
index d6c8f90e968eb9fa10647ce10d88a901020a5b68..1747daca6c88cf94d3ffcb928951add54f53d159 100644 (file)
@@ -18,7 +18,7 @@ var strings = [...]string{"", "Hello", "foo", "bar", "foo", "f00", "%*&^*&^&", "
 
 func TestSortIntArray(t *testing.T) {
        data := ints;
-       a := IntArray(data);
+       a := IntArray(&data);
        sort.Sort(a);
        if !sort.IsSorted(a) {
                t.Errorf("sorted %v", ints);
@@ -28,7 +28,7 @@ func TestSortIntArray(t *testing.T) {
 
 func TestSortFloatArray(t *testing.T) {
        data := floats;
-       a := FloatArray(data);
+       a := FloatArray(&data);
        sort.Sort(a);
        if !sort.IsSorted(a) {
                t.Errorf("sorted %v", floats);
@@ -38,7 +38,7 @@ func TestSortFloatArray(t *testing.T) {
 
 func TestSortStringArray(t *testing.T) {
        data := strings;
-       a := StringArray(data);
+       a := StringArray(&data);
        sort.Sort(a);
        if !sort.IsSorted(a) {
                t.Errorf("sorted %v", strings);
similarity index 100%
rename from test/bugs/bug146.go
rename to test/fixedbugs/bug146.go
index 36217cac378adefcf52c99abaa8805cbb62bc9ae..a3ab91b21305077704d36203bf07f08a8f9f7e45 100644 (file)
@@ -111,13 +111,6 @@ bugs/bug140.go:6: syntax error near L1
 bugs/bug140.go:7: syntax error near L2
 BUG should compile
 
-=========== bugs/bug146.go
-BUG: errchk: bugs/bug146.go:9: missing expected error: 'invalid'
-errchk: bugs/bug146.go: unmatched error messages:
-==================================================
-bugs/bug146.go:8: invalid conversion: *[1]uint8 to Slice
-==================================================
-
 =========== fixedbugs/bug016.go
 fixedbugs/bug016.go:7: constant -3 overflows uint