1
0
mirror of https://github.com/golang/go synced 2024-11-22 07:04:40 -07:00

bug146: array/slice conversion before I left missed conversions

R=ken
OCL=28120
CL=28124
This commit is contained in:
Russ Cox 2009-04-30 13:49:58 -07:00
parent bd8e25ca57
commit 83e976d53e
6 changed files with 17 additions and 41 deletions

View File

@ -1245,8 +1245,8 @@ walkconv(Node *n)
return; return;
// convert static array to dynamic array // convert static array to dynamic array
if(isslice(t) && isfixedarray(l->type)) { if(isslice(t) && isptr[l->type->etype] && isfixedarray(l->type->type)) {
if(eqtype(t->type->type, l->type->type->type, 0)) { if(eqtype(t->type->type, l->type->type->type->type, 0)) {
indir(n, arrayop(n, Erv)); indir(n, arrayop(n, Erv));
return; return;
} }
@ -2707,7 +2707,9 @@ arrayop(Node *n, int top)
case OCONV: case OCONV:
// arrays2d(old *any, nel int) (ary []any) // 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); tl = fixarray(n->type);
if(t == T || tl == T) if(t == T || tl == T)
break; break;
@ -2717,39 +2719,20 @@ arrayop(Node *n, int top)
a->type = types[TINT]; a->type = types[TINT];
r = a; r = a;
a = nod(OADDR, n->left, N); // old r = list(n->left, r); // old
addrescapes(n->left);
r = list(a, r);
on = syslook("arrays2d", 1); on = syslook("arrays2d", 1);
argtype(on, t); // any-1 argtype(on, t); // any-1
argtype(on, tl->type); // any-2 argtype(on, tl->type); // any-2
r = nod(OCALL, on, r); r = nod(OCALL, on, r);
walktype(r, top);
n->left = r; n->left = r;
walktype(n, top);
return n; return n;
case OAS: case OAS:
// arrays2d(old *any, nel int) (ary []any) r = nod(OCONV, n->right, N);
t = fixarray(n->right->type->type); r->type = n->left->type;
tl = fixarray(n->left->type); n->right = arrayop(r, Erv);
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;
return n; return n;
case OMAKE: case OMAKE:

View File

@ -48,14 +48,14 @@ func sockaddrToIP(sa1 *syscall.Sockaddr) (p IP, port int, err os.Error) {
switch sa1.Family { switch sa1.Family {
case syscall.AF_INET: case syscall.AF_INET:
sa := (*syscall.SockaddrInet4)(unsafe.Pointer(sa1)); sa := (*syscall.SockaddrInet4)(unsafe.Pointer(sa1));
a := IP(sa.Addr).To16(); a := IP(&sa.Addr).To16();
if a == nil { if a == nil {
return nil, 0, os.EINVAL return nil, 0, os.EINVAL
} }
return a, int(sa.Port[0])<<8 + int(sa.Port[1]), nil; return a, int(sa.Port[0])<<8 + int(sa.Port[1]), nil;
case syscall.AF_INET6: case syscall.AF_INET6:
sa := (*syscall.SockaddrInet6)(unsafe.Pointer(sa1)); sa := (*syscall.SockaddrInet6)(unsafe.Pointer(sa1));
a := IP(sa.Addr).To16(); a := IP(&sa.Addr).To16();
if a == nil { if a == nil {
return nil, 0, os.EINVAL return nil, 0, os.EINVAL
} }

View File

@ -53,14 +53,14 @@ func sockaddrToIP(sa1 *syscall.Sockaddr) (p IP, port int, err os.Error) {
switch sa1.Family { switch sa1.Family {
case syscall.AF_INET: case syscall.AF_INET:
sa := (*syscall.SockaddrInet4)(unsafe.Pointer(sa1)); sa := (*syscall.SockaddrInet4)(unsafe.Pointer(sa1));
a := IP(sa.Addr).To16(); a := IP(&sa.Addr).To16();
if a == nil { if a == nil {
return nil, 0, os.EINVAL return nil, 0, os.EINVAL
} }
return a, int(sa.Port[0])<<8 + int(sa.Port[1]), nil; return a, int(sa.Port[0])<<8 + int(sa.Port[1]), nil;
case syscall.AF_INET6: case syscall.AF_INET6:
sa := (*syscall.SockaddrInet6)(unsafe.Pointer(sa1)); sa := (*syscall.SockaddrInet6)(unsafe.Pointer(sa1));
a := IP(sa.Addr).To16(); a := IP(&sa.Addr).To16();
if a == nil { if a == nil {
return nil, 0, os.EINVAL return nil, 0, os.EINVAL
} }

View File

@ -18,7 +18,7 @@ var strings = [...]string{"", "Hello", "foo", "bar", "foo", "f00", "%*&^*&^&", "
func TestSortIntArray(t *testing.T) { func TestSortIntArray(t *testing.T) {
data := ints; data := ints;
a := IntArray(data); a := IntArray(&data);
sort.Sort(a); sort.Sort(a);
if !sort.IsSorted(a) { if !sort.IsSorted(a) {
t.Errorf("sorted %v", ints); t.Errorf("sorted %v", ints);
@ -28,7 +28,7 @@ func TestSortIntArray(t *testing.T) {
func TestSortFloatArray(t *testing.T) { func TestSortFloatArray(t *testing.T) {
data := floats; data := floats;
a := FloatArray(data); a := FloatArray(&data);
sort.Sort(a); sort.Sort(a);
if !sort.IsSorted(a) { if !sort.IsSorted(a) {
t.Errorf("sorted %v", floats); t.Errorf("sorted %v", floats);
@ -38,7 +38,7 @@ func TestSortFloatArray(t *testing.T) {
func TestSortStringArray(t *testing.T) { func TestSortStringArray(t *testing.T) {
data := strings; data := strings;
a := StringArray(data); a := StringArray(&data);
sort.Sort(a); sort.Sort(a);
if !sort.IsSorted(a) { if !sort.IsSorted(a) {
t.Errorf("sorted %v", strings); t.Errorf("sorted %v", strings);

View File

@ -111,13 +111,6 @@ bugs/bug140.go:6: syntax error near L1
bugs/bug140.go:7: syntax error near L2 bugs/bug140.go:7: syntax error near L2
BUG should compile 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
fixedbugs/bug016.go:7: constant -3 overflows uint fixedbugs/bug016.go:7: constant -3 overflows uint