mirror of
https://github.com/golang/go
synced 2024-11-21 18:14:42 -07:00
misc cleanup: gofmt + &x -> x[0:] conversion
R=gri CC=golang-dev https://golang.org/cl/1620042
This commit is contained in:
parent
f29fb251dc
commit
6aaef04469
@ -168,11 +168,11 @@ func NewFile(r io.ReaderAt) (*File, os.Error) {
|
|||||||
// Read and decode Mach magic to determine byte order, size.
|
// Read and decode Mach magic to determine byte order, size.
|
||||||
// Magic32 and Magic64 differ only in the bottom bit.
|
// Magic32 and Magic64 differ only in the bottom bit.
|
||||||
var ident [4]byte
|
var ident [4]byte
|
||||||
if _, err := r.ReadAt(&ident, 0); err != nil {
|
if _, err := r.ReadAt(ident[0:], 0); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
be := binary.BigEndian.Uint32(&ident)
|
be := binary.BigEndian.Uint32(ident[0:])
|
||||||
le := binary.LittleEndian.Uint32(&ident)
|
le := binary.LittleEndian.Uint32(ident[0:])
|
||||||
switch Magic32 &^ 1 {
|
switch Magic32 &^ 1 {
|
||||||
case be &^ 1:
|
case be &^ 1:
|
||||||
f.ByteOrder = binary.BigEndian
|
f.ByteOrder = binary.BigEndian
|
||||||
@ -227,7 +227,7 @@ func NewFile(r io.ReaderAt) (*File, os.Error) {
|
|||||||
s.LoadBytes = cmddat
|
s.LoadBytes = cmddat
|
||||||
s.Cmd = cmd
|
s.Cmd = cmd
|
||||||
s.Len = siz
|
s.Len = siz
|
||||||
s.Name = cstring(&seg32.Name)
|
s.Name = cstring(seg32.Name[0:])
|
||||||
s.Addr = uint64(seg32.Addr)
|
s.Addr = uint64(seg32.Addr)
|
||||||
s.Memsz = uint64(seg32.Memsz)
|
s.Memsz = uint64(seg32.Memsz)
|
||||||
s.Offset = uint64(seg32.Offset)
|
s.Offset = uint64(seg32.Offset)
|
||||||
@ -243,8 +243,8 @@ func NewFile(r io.ReaderAt) (*File, os.Error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
sh := new(Section)
|
sh := new(Section)
|
||||||
sh.Name = cstring(&sh32.Name)
|
sh.Name = cstring(sh32.Name[0:])
|
||||||
sh.Seg = cstring(&sh32.Seg)
|
sh.Seg = cstring(sh32.Seg[0:])
|
||||||
sh.Addr = uint64(sh32.Addr)
|
sh.Addr = uint64(sh32.Addr)
|
||||||
sh.Size = uint64(sh32.Size)
|
sh.Size = uint64(sh32.Size)
|
||||||
sh.Offset = sh32.Offset
|
sh.Offset = sh32.Offset
|
||||||
@ -265,7 +265,7 @@ func NewFile(r io.ReaderAt) (*File, os.Error) {
|
|||||||
s.LoadBytes = cmddat
|
s.LoadBytes = cmddat
|
||||||
s.Cmd = cmd
|
s.Cmd = cmd
|
||||||
s.Len = siz
|
s.Len = siz
|
||||||
s.Name = cstring(&seg64.Name)
|
s.Name = cstring(seg64.Name[0:])
|
||||||
s.Addr = seg64.Addr
|
s.Addr = seg64.Addr
|
||||||
s.Memsz = seg64.Memsz
|
s.Memsz = seg64.Memsz
|
||||||
s.Offset = seg64.Offset
|
s.Offset = seg64.Offset
|
||||||
@ -281,8 +281,8 @@ func NewFile(r io.ReaderAt) (*File, os.Error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
sh := new(Section)
|
sh := new(Section)
|
||||||
sh.Name = cstring(&sh64.Name)
|
sh.Name = cstring(sh64.Name[0:])
|
||||||
sh.Seg = cstring(&sh64.Seg)
|
sh.Seg = cstring(sh64.Seg[0:])
|
||||||
sh.Addr = sh64.Addr
|
sh.Addr = sh64.Addr
|
||||||
sh.Size = sh64.Size
|
sh.Size = sh64.Size
|
||||||
sh.Offset = sh64.Offset
|
sh.Offset = sh64.Offset
|
||||||
|
@ -15,7 +15,7 @@ type _386Regs struct {
|
|||||||
setter func(*syscall.PtraceRegs) os.Error
|
setter func(*syscall.PtraceRegs) os.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
var names = [...]string{
|
var names = []string{
|
||||||
"eax",
|
"eax",
|
||||||
"ebx",
|
"ebx",
|
||||||
"ecx",
|
"ecx",
|
||||||
@ -55,7 +55,7 @@ func (r *_386Regs) SetSP(val Word) os.Error {
|
|||||||
return r.setter(&r.PtraceRegs)
|
return r.setter(&r.PtraceRegs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *_386Regs) Names() []string { return &names }
|
func (r *_386Regs) Names() []string { return names }
|
||||||
|
|
||||||
func (r *_386Regs) Get(i int) Word {
|
func (r *_386Regs) Get(i int) Word {
|
||||||
switch i {
|
switch i {
|
||||||
|
@ -6,13 +6,12 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"bufio"
|
|
||||||
"expvar"
|
"expvar"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"http"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
@ -67,7 +66,7 @@ func FileServer(c *http.Conn, req *http.Request) {
|
|||||||
fmt.Fprintf(c, "open %s: %v\n", path, err)
|
fmt.Fprintf(c, "open %s: %v\n", path, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
n, err1 := io.Copy(c, f)
|
n, _ := io.Copy(c, f)
|
||||||
fmt.Fprintf(c, "[%d bytes]\n", n)
|
fmt.Fprintf(c, "[%d bytes]\n", n)
|
||||||
f.Close()
|
f.Close()
|
||||||
}
|
}
|
||||||
@ -89,7 +88,7 @@ func FlagServer(c *http.Conn, req *http.Request) {
|
|||||||
|
|
||||||
// simple argument server
|
// simple argument server
|
||||||
func ArgServer(c *http.Conn, req *http.Request) {
|
func ArgServer(c *http.Conn, req *http.Request) {
|
||||||
for i, s := range os.Args {
|
for _, s := range os.Args {
|
||||||
fmt.Fprint(c, s, " ")
|
fmt.Fprint(c, s, " ")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -138,6 +137,13 @@ func DateServer(c *http.Conn, req *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Logger(c *http.Conn, req *http.Request) {
|
||||||
|
log.Stdout(req.URL.Raw)
|
||||||
|
c.WriteHeader(404)
|
||||||
|
c.Write([]byte("oops"))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
@ -146,6 +152,7 @@ func main() {
|
|||||||
http.Handle("/counter", ctr)
|
http.Handle("/counter", ctr)
|
||||||
expvar.Publish("counter", ctr)
|
expvar.Publish("counter", ctr)
|
||||||
|
|
||||||
|
http.Handle("/", http.HandlerFunc(Logger))
|
||||||
http.Handle("/go/", http.HandlerFunc(FileServer))
|
http.Handle("/go/", http.HandlerFunc(FileServer))
|
||||||
http.Handle("/flags", http.HandlerFunc(FlagServer))
|
http.Handle("/flags", http.HandlerFunc(FlagServer))
|
||||||
http.Handle("/args", http.HandlerFunc(ArgServer))
|
http.Handle("/args", http.HandlerFunc(ArgServer))
|
||||||
|
@ -109,7 +109,7 @@ func TestRawMessage(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unmarshal: %v", err)
|
t.Fatalf("Unmarshal: %v", err)
|
||||||
}
|
}
|
||||||
if string(*data.Id) != raw {
|
if string([]byte(*data.Id)) != raw {
|
||||||
t.Fatalf("Raw mismatch: have %#q want %#q", []byte(*data.Id), raw)
|
t.Fatalf("Raw mismatch: have %#q want %#q", []byte(*data.Id), raw)
|
||||||
}
|
}
|
||||||
b, err := Marshal(&data)
|
b, err := Marshal(&data)
|
||||||
|
@ -15,9 +15,9 @@ import (
|
|||||||
func sockaddrToIP(sa syscall.Sockaddr) Addr {
|
func sockaddrToIP(sa syscall.Sockaddr) Addr {
|
||||||
switch sa := sa.(type) {
|
switch sa := sa.(type) {
|
||||||
case *syscall.SockaddrInet4:
|
case *syscall.SockaddrInet4:
|
||||||
return &IPAddr{&sa.Addr}
|
return &IPAddr{sa.Addr[0:]}
|
||||||
case *syscall.SockaddrInet6:
|
case *syscall.SockaddrInet6:
|
||||||
return &IPAddr{&sa.Addr}
|
return &IPAddr{sa.Addr[0:]}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -176,14 +176,14 @@ func (c *IPConn) ReadFromIP(b []byte) (n int, addr *IPAddr, err os.Error) {
|
|||||||
n, sa, err := c.fd.ReadFrom(b)
|
n, sa, err := c.fd.ReadFrom(b)
|
||||||
switch sa := sa.(type) {
|
switch sa := sa.(type) {
|
||||||
case *syscall.SockaddrInet4:
|
case *syscall.SockaddrInet4:
|
||||||
addr = &IPAddr{&sa.Addr}
|
addr = &IPAddr{sa.Addr[0:]}
|
||||||
if len(b) >= 4 { // discard ipv4 header
|
if len(b) >= 4 { // discard ipv4 header
|
||||||
hsize := (int(b[0]) & 0xf) * 4
|
hsize := (int(b[0]) & 0xf) * 4
|
||||||
copy(b, b[hsize:])
|
copy(b, b[hsize:])
|
||||||
n -= hsize
|
n -= hsize
|
||||||
}
|
}
|
||||||
case *syscall.SockaddrInet6:
|
case *syscall.SockaddrInet6:
|
||||||
addr = &IPAddr{&sa.Addr}
|
addr = &IPAddr{sa.Addr[0:]}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -14,9 +14,9 @@ import (
|
|||||||
func sockaddrToTCP(sa syscall.Sockaddr) Addr {
|
func sockaddrToTCP(sa syscall.Sockaddr) Addr {
|
||||||
switch sa := sa.(type) {
|
switch sa := sa.(type) {
|
||||||
case *syscall.SockaddrInet4:
|
case *syscall.SockaddrInet4:
|
||||||
return &TCPAddr{&sa.Addr, sa.Port}
|
return &TCPAddr{sa.Addr[0:], sa.Port}
|
||||||
case *syscall.SockaddrInet6:
|
case *syscall.SockaddrInet6:
|
||||||
return &TCPAddr{&sa.Addr, sa.Port}
|
return &TCPAddr{sa.Addr[0:], sa.Port}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -14,9 +14,9 @@ import (
|
|||||||
func sockaddrToUDP(sa syscall.Sockaddr) Addr {
|
func sockaddrToUDP(sa syscall.Sockaddr) Addr {
|
||||||
switch sa := sa.(type) {
|
switch sa := sa.(type) {
|
||||||
case *syscall.SockaddrInet4:
|
case *syscall.SockaddrInet4:
|
||||||
return &UDPAddr{&sa.Addr, sa.Port}
|
return &UDPAddr{sa.Addr[0:], sa.Port}
|
||||||
case *syscall.SockaddrInet6:
|
case *syscall.SockaddrInet6:
|
||||||
return &UDPAddr{&sa.Addr, sa.Port}
|
return &UDPAddr{sa.Addr[0:], sa.Port}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -176,9 +176,9 @@ func (c *UDPConn) ReadFromUDP(b []byte) (n int, addr *UDPAddr, err os.Error) {
|
|||||||
n, sa, err := c.fd.ReadFrom(b)
|
n, sa, err := c.fd.ReadFrom(b)
|
||||||
switch sa := sa.(type) {
|
switch sa := sa.(type) {
|
||||||
case *syscall.SockaddrInet4:
|
case *syscall.SockaddrInet4:
|
||||||
addr = &UDPAddr{&sa.Addr, sa.Port}
|
addr = &UDPAddr{sa.Addr[0:], sa.Port}
|
||||||
case *syscall.SockaddrInet6:
|
case *syscall.SockaddrInet6:
|
||||||
addr = &UDPAddr{&sa.Addr, sa.Port}
|
addr = &UDPAddr{sa.Addr[0:], sa.Port}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
210
test/copy.go
210
test/copy.go
@ -9,8 +9,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt";
|
"fmt"
|
||||||
"os";
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
const N = 40
|
const N = 40
|
||||||
@ -25,53 +25,53 @@ var input64 = make([]uint64, N)
|
|||||||
var output64 = make([]uint64, N)
|
var output64 = make([]uint64, N)
|
||||||
|
|
||||||
func u8(i int) uint8 {
|
func u8(i int) uint8 {
|
||||||
i = 'a' + i%26;
|
i = 'a' + i%26
|
||||||
return uint8(i);
|
return uint8(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
func u16(ii int) uint16 {
|
func u16(ii int) uint16 {
|
||||||
var i = uint16(ii);
|
var i = uint16(ii)
|
||||||
i = 'a' + i%26;
|
i = 'a' + i%26
|
||||||
i |= i << 8;
|
i |= i << 8
|
||||||
return i;
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
func u32(ii int) uint32 {
|
func u32(ii int) uint32 {
|
||||||
var i = uint32(ii);
|
var i = uint32(ii)
|
||||||
i = 'a' + i%26;
|
i = 'a' + i%26
|
||||||
i |= i << 8;
|
i |= i << 8
|
||||||
i |= i << 16;
|
i |= i << 16
|
||||||
return i;
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
func u64(ii int) uint64 {
|
func u64(ii int) uint64 {
|
||||||
var i = uint64(ii);
|
var i = uint64(ii)
|
||||||
i = 'a' + i%26;
|
i = 'a' + i%26
|
||||||
i |= i << 8;
|
i |= i << 8
|
||||||
i |= i << 16;
|
i |= i << 16
|
||||||
i |= i << 32;
|
i |= i << 32
|
||||||
return i;
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
func reset() {
|
func reset() {
|
||||||
// swap in and out to exercise copy-up and copy-down
|
// swap in and out to exercise copy-up and copy-down
|
||||||
input8, output8 = output8, input8;
|
input8, output8 = output8, input8
|
||||||
input16, output16 = output16, input16;
|
input16, output16 = output16, input16
|
||||||
input32, output32 = output32, input32;
|
input32, output32 = output32, input32
|
||||||
input64, output64 = output64, input64;
|
input64, output64 = output64, input64
|
||||||
in := 0;
|
in := 0
|
||||||
out := 13;
|
out := 13
|
||||||
for i := range input8 {
|
for i := range input8 {
|
||||||
input8[i] = u8(in);
|
input8[i] = u8(in)
|
||||||
output8[i] = u8(out);
|
output8[i] = u8(out)
|
||||||
input16[i] = u16(in);
|
input16[i] = u16(in)
|
||||||
output16[i] = u16(out);
|
output16[i] = u16(out)
|
||||||
input32[i] = u32(in);
|
input32[i] = u32(in)
|
||||||
output32[i] = u32(out);
|
output32[i] = u32(out)
|
||||||
input64[i] = u64(in);
|
input64[i] = u64(in)
|
||||||
output64[i] = u64(out);
|
output64[i] = u64(out)
|
||||||
in++;
|
in++
|
||||||
out++;
|
out++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,30 +79,30 @@ func clamp(n int) int {
|
|||||||
if n > N {
|
if n > N {
|
||||||
return N
|
return N
|
||||||
}
|
}
|
||||||
return n;
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
func ncopied(length, in, out int) int {
|
func ncopied(length, in, out int) int {
|
||||||
n := length;
|
n := length
|
||||||
if in+n > N {
|
if in+n > N {
|
||||||
n = N-in
|
n = N - in
|
||||||
}
|
}
|
||||||
if out+n > N {
|
if out+n > N {
|
||||||
n = N-out
|
n = N - out
|
||||||
}
|
}
|
||||||
return n;
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
func doAllSlices(length, in, out int) {
|
func doAllSlices(length, in, out int) {
|
||||||
reset();
|
reset()
|
||||||
n := copy(output8[out:clamp(out+length)], input8[in:clamp(in+length)]);
|
n := copy(output8[out:clamp(out+length)], input8[in:clamp(in+length)])
|
||||||
verify8(length, in, out, n);
|
verify8(length, in, out, n)
|
||||||
n = copy(output16[out:clamp(out+length)], input16[in:clamp(in+length)]);
|
n = copy(output16[out:clamp(out+length)], input16[in:clamp(in+length)])
|
||||||
verify16(length, in, out, n);
|
verify16(length, in, out, n)
|
||||||
n = copy(output32[out:clamp(out+length)], input32[in:clamp(in+length)]);
|
n = copy(output32[out:clamp(out+length)], input32[in:clamp(in+length)])
|
||||||
verify32(length, in, out, n);
|
verify32(length, in, out, n)
|
||||||
n = copy(output64[out:clamp(out+length)], input64[in:clamp(in+length)]);
|
n = copy(output64[out:clamp(out+length)], input64[in:clamp(in+length)])
|
||||||
verify64(length, in, out, n);
|
verify64(length, in, out, n)
|
||||||
}
|
}
|
||||||
|
|
||||||
func bad8(state string, i, length, in, out int) {
|
func bad8(state string, i, length, in, out int) {
|
||||||
@ -111,36 +111,36 @@ func bad8(state string, i, length, in, out int) {
|
|||||||
length, in, out,
|
length, in, out,
|
||||||
output8[i],
|
output8[i],
|
||||||
uint8(i+13),
|
uint8(i+13),
|
||||||
input8, output8);
|
input8, output8)
|
||||||
os.Exit(1);
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func verify8(length, in, out, m int) {
|
func verify8(length, in, out, m int) {
|
||||||
n := ncopied(length, in, out);
|
n := ncopied(length, in, out)
|
||||||
if m != n {
|
if m != n {
|
||||||
fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n);
|
fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n)
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
// before
|
// before
|
||||||
var i int;
|
var i int
|
||||||
for i = 0; i < out; i++ {
|
for i = 0; i < out; i++ {
|
||||||
if output8[i] != u8(i+13) {
|
if output8[i] != u8(i+13) {
|
||||||
bad8("before8", i, length, in, out);
|
bad8("before8", i, length, in, out)
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// copied part
|
// copied part
|
||||||
for ; i < out+n; i++ {
|
for ; i < out+n; i++ {
|
||||||
if output8[i] != u8(i+in-out) {
|
if output8[i] != u8(i+in-out) {
|
||||||
bad8("copied8", i, length, in, out);
|
bad8("copied8", i, length, in, out)
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// after
|
// after
|
||||||
for ; i < len(output8); i++ {
|
for ; i < len(output8); i++ {
|
||||||
if output8[i] != u8(i+13) {
|
if output8[i] != u8(i+13) {
|
||||||
bad8("after8", i, length, in, out);
|
bad8("after8", i, length, in, out)
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -151,36 +151,36 @@ func bad16(state string, i, length, in, out int) {
|
|||||||
length, in, out,
|
length, in, out,
|
||||||
output16[i],
|
output16[i],
|
||||||
uint16(i+13),
|
uint16(i+13),
|
||||||
input16, output16);
|
input16, output16)
|
||||||
os.Exit(1);
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func verify16(length, in, out, m int) {
|
func verify16(length, in, out, m int) {
|
||||||
n := ncopied(length, in, out);
|
n := ncopied(length, in, out)
|
||||||
if m != n {
|
if m != n {
|
||||||
fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n);
|
fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n)
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
// before
|
// before
|
||||||
var i int;
|
var i int
|
||||||
for i = 0; i < out; i++ {
|
for i = 0; i < out; i++ {
|
||||||
if output16[i] != u16(i+13) {
|
if output16[i] != u16(i+13) {
|
||||||
bad16("before16", i, length, in, out);
|
bad16("before16", i, length, in, out)
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// copied part
|
// copied part
|
||||||
for ; i < out+n; i++ {
|
for ; i < out+n; i++ {
|
||||||
if output16[i] != u16(i+in-out) {
|
if output16[i] != u16(i+in-out) {
|
||||||
bad16("copied16", i, length, in, out);
|
bad16("copied16", i, length, in, out)
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// after
|
// after
|
||||||
for ; i < len(output16); i++ {
|
for ; i < len(output16); i++ {
|
||||||
if output16[i] != u16(i+13) {
|
if output16[i] != u16(i+13) {
|
||||||
bad16("after16", i, length, in, out);
|
bad16("after16", i, length, in, out)
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -191,36 +191,36 @@ func bad32(state string, i, length, in, out int) {
|
|||||||
length, in, out,
|
length, in, out,
|
||||||
output32[i],
|
output32[i],
|
||||||
uint32(i+13),
|
uint32(i+13),
|
||||||
input32, output32);
|
input32, output32)
|
||||||
os.Exit(1);
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func verify32(length, in, out, m int) {
|
func verify32(length, in, out, m int) {
|
||||||
n := ncopied(length, in, out);
|
n := ncopied(length, in, out)
|
||||||
if m != n {
|
if m != n {
|
||||||
fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n);
|
fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n)
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
// before
|
// before
|
||||||
var i int;
|
var i int
|
||||||
for i = 0; i < out; i++ {
|
for i = 0; i < out; i++ {
|
||||||
if output32[i] != u32(i+13) {
|
if output32[i] != u32(i+13) {
|
||||||
bad32("before32", i, length, in, out);
|
bad32("before32", i, length, in, out)
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// copied part
|
// copied part
|
||||||
for ; i < out+n; i++ {
|
for ; i < out+n; i++ {
|
||||||
if output32[i] != u32(i+in-out) {
|
if output32[i] != u32(i+in-out) {
|
||||||
bad32("copied32", i, length, in, out);
|
bad32("copied32", i, length, in, out)
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// after
|
// after
|
||||||
for ; i < len(output32); i++ {
|
for ; i < len(output32); i++ {
|
||||||
if output32[i] != u32(i+13) {
|
if output32[i] != u32(i+13) {
|
||||||
bad32("after32", i, length, in, out);
|
bad32("after32", i, length, in, out)
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -231,36 +231,36 @@ func bad64(state string, i, length, in, out int) {
|
|||||||
length, in, out,
|
length, in, out,
|
||||||
output64[i],
|
output64[i],
|
||||||
uint64(i+13),
|
uint64(i+13),
|
||||||
input64, output64);
|
input64, output64)
|
||||||
os.Exit(1);
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func verify64(length, in, out, m int) {
|
func verify64(length, in, out, m int) {
|
||||||
n := ncopied(length, in, out);
|
n := ncopied(length, in, out)
|
||||||
if m != n {
|
if m != n {
|
||||||
fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n);
|
fmt.Printf("count bad(%d %d %d): %d not %d\n", length, in, out, m, n)
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
// before
|
// before
|
||||||
var i int;
|
var i int
|
||||||
for i = 0; i < out; i++ {
|
for i = 0; i < out; i++ {
|
||||||
if output64[i] != u64(i+13) {
|
if output64[i] != u64(i+13) {
|
||||||
bad64("before64", i, length, in, out);
|
bad64("before64", i, length, in, out)
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// copied part
|
// copied part
|
||||||
for ; i < out+n; i++ {
|
for ; i < out+n; i++ {
|
||||||
if output64[i] != u64(i+in-out) {
|
if output64[i] != u64(i+in-out) {
|
||||||
bad64("copied64", i, length, in, out);
|
bad64("copied64", i, length, in, out)
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// after
|
// after
|
||||||
for ; i < len(output64); i++ {
|
for ; i < len(output64); i++ {
|
||||||
if output64[i] != u64(i+13) {
|
if output64[i] != u64(i+13) {
|
||||||
bad64("after64", i, length, in, out);
|
bad64("after64", i, length, in, out)
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -275,19 +275,19 @@ func slice() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Array test. Can be much simpler. It's mostly checking for promotion of *[N] to []
|
// Array test. Can be much simpler. It's only checking for correct handling of [0:].
|
||||||
func array() {
|
func array() {
|
||||||
var array [N]uint8;
|
var array [N]uint8
|
||||||
reset();
|
reset()
|
||||||
copy(&array, input8);
|
copy(array[0:], input8)
|
||||||
for i := 0; i < N; i++ {
|
for i := 0; i < N; i++ {
|
||||||
output8[i] = 0
|
output8[i] = 0
|
||||||
}
|
}
|
||||||
copy(output8, &array);
|
copy(output8, array[0:])
|
||||||
verify8(N, 0, 0, N);
|
verify8(N, 0, 0, N)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
slice();
|
slice()
|
||||||
array();
|
array()
|
||||||
}
|
}
|
||||||
|
@ -7,19 +7,20 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var b [0]byte;
|
var b [0]byte
|
||||||
s := string(&b); // out of bounds trap
|
s := string(b[0:]) // out of bounds trap
|
||||||
if s != "" {
|
if s != "" {
|
||||||
panic("bad convert")
|
panic("bad convert")
|
||||||
}
|
}
|
||||||
var b1 = [5]byte{'h', 'e', 'l', 'l', 'o'};
|
var b1 = [5]byte{'h', 'e', 'l', 'l', 'o'}
|
||||||
if string(&b1) != "hello" {
|
if string(b1[0:]) != "hello" {
|
||||||
panic("bad convert 1")
|
panic("bad convert 1")
|
||||||
}
|
}
|
||||||
var b2 = make([]byte, 5);
|
var b2 = make([]byte, 5)
|
||||||
for i := 0; i < 5; i++ { b2[i] = b1[i] }
|
for i := 0; i < 5; i++ {
|
||||||
|
b2[i] = b1[i]
|
||||||
|
}
|
||||||
if string(b2) != "hello" {
|
if string(b2) != "hello" {
|
||||||
panic("bad convert 2")
|
panic("bad convert 2")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ func main() {
|
|||||||
z1[0] = 'a'
|
z1[0] = 'a'
|
||||||
z1[1] = 'b'
|
z1[1] = 'b'
|
||||||
z1[2] = 'c'
|
z1[2] = 'c'
|
||||||
c = string(&z1)
|
c = string(z1[0:])
|
||||||
if c != "abc" {
|
if c != "abc" {
|
||||||
print("create byte array ", c)
|
print("create byte array ", c)
|
||||||
panic("fail")
|
panic("fail")
|
||||||
@ -99,7 +99,7 @@ func main() {
|
|||||||
z2[0] = 'a'
|
z2[0] = 'a'
|
||||||
z2[1] = '\u1234'
|
z2[1] = '\u1234'
|
||||||
z2[2] = 'c'
|
z2[2] = 'c'
|
||||||
c = string(&z2)
|
c = string(z2[0:])
|
||||||
if c != "a\u1234c" {
|
if c != "a\u1234c" {
|
||||||
print("create int array ", c)
|
print("create int array ", c)
|
||||||
panic("fail")
|
panic("fail")
|
||||||
@ -110,7 +110,7 @@ func main() {
|
|||||||
z3[0] = 'a'
|
z3[0] = 'a'
|
||||||
z3[1] = 'b'
|
z3[1] = 'b'
|
||||||
z3[2] = 'c'
|
z3[2] = 'c'
|
||||||
c = string(z3)
|
c = string(z3[0:])
|
||||||
if c != "abc" {
|
if c != "abc" {
|
||||||
print("create array pointer ", c)
|
print("create array pointer ", c)
|
||||||
panic("fail")
|
panic("fail")
|
||||||
|
Loading…
Reference in New Issue
Block a user