Commit d47d888b authored by Russ Cox's avatar Russ Cox

convert *[] to [].

R=r
OCL=21563
CL=21571
parent 9786f69f
...@@ -95,7 +95,7 @@ export func stringtorune(string, int) (int, int); // convert bytes to runes ...@@ -95,7 +95,7 @@ export func stringtorune(string, int) (int, int); // convert bytes to runes
export func exit(int); export func exit(int);
export func symdat() (symtab *[]byte, pclntab *[]byte); export func symdat() (symtab []byte, pclntab []byte);
export func semacquire(sema *int32); export func semacquire(sema *int32);
export func semrelease(sema *int32); export func semrelease(sema *int32);
...@@ -41,7 +41,7 @@ done ...@@ -41,7 +41,7 @@ done
set -e set -e
# They all compile; now generate the code to call them. # They all compile; now generate the code to call them.
trap "rm -f _testmain.go _testmain.6" 0 1 2 3 14 15 #trap "rm -f _testmain.go _testmain.6" 0 1 2 3 14 15
{ {
# package spec # package spec
echo 'package main' echo 'package main'
...@@ -54,7 +54,7 @@ trap "rm -f _testmain.go _testmain.6" 0 1 2 3 14 15 ...@@ -54,7 +54,7 @@ trap "rm -f _testmain.go _testmain.6" 0 1 2 3 14 15
echo 'import "testing"' echo 'import "testing"'
# test array # test array
echo echo
echo 'var tests = &[]testing.Test {' echo 'var tests = []testing.Test {' # TODO(rsc): *&
for ofile in $ofiles for ofile in $ofiles
do do
# test functions are named TestFoo # test functions are named TestFoo
......
...@@ -24,7 +24,6 @@ DIRS=\ ...@@ -24,7 +24,6 @@ DIRS=\
time\ time\
FILES=\ FILES=\
bignum\
bufio\ bufio\
flag\ flag\
malloc\ malloc\
...@@ -35,14 +34,17 @@ FILES=\ ...@@ -35,14 +34,17 @@ FILES=\
testing\ testing\
utf8\ utf8\
# bignum\
TEST=\ TEST=\
bignum\
bufio\ bufio\
once\ once\
sort\ sort\
strings\ strings\
utf8\ utf8\
# bignum\
clean.dirs: $(addsuffix .dirclean, $(DIRS)) clean.dirs: $(addsuffix .dirclean, $(DIRS))
install.dirs: $(addsuffix .dirinstall, $(DIRS)) install.dirs: $(addsuffix .dirinstall, $(DIRS))
install.files: $(addsuffix .install, $(FILES)) install.files: $(addsuffix .install, $(FILES))
...@@ -99,7 +101,8 @@ http.dirinstall: bufio.install io.dirinstall net.dirinstall os.dirinstall string ...@@ -99,7 +101,8 @@ http.dirinstall: bufio.install io.dirinstall net.dirinstall os.dirinstall string
io.dirinstall: os.dirinstall syscall.dirinstall io.dirinstall: os.dirinstall syscall.dirinstall
json.dirinstall: container/array.dirinstall fmt.dirinstall io.dirinstall math.dirinstall \ json.dirinstall: container/array.dirinstall fmt.dirinstall io.dirinstall math.dirinstall \
strconv.dirinstall strings.install utf8.install strconv.dirinstall strings.install utf8.install
net.dirinstall: fmt.dirinstall once.install os.dirinstall strconv.dirinstall # TODO(rsc): net is not supposed to depend on fmt or strings or strconv
net.dirinstall: fmt.dirinstall once.install os.dirinstall strconv.dirinstall strings.install
os.dirinstall: syscall.dirinstall os.dirinstall: syscall.dirinstall
regexp.dirinstall: os.dirinstall regexp.dirinstall: os.dirinstall
reflect.dirinstall: strconv.dirinstall sync.dirinstall reflect.dirinstall: strconv.dirinstall sync.dirinstall
......
...@@ -90,7 +90,7 @@ func IsSmall(x Digit) bool { ...@@ -90,7 +90,7 @@ func IsSmall(x Digit) bool {
} }
export func Dump(x *[]Digit) { export func Dump(x []Digit) {
print("[", len(x), "]"); print("[", len(x), "]");
for i := len(x) - 1; i >= 0; i-- { for i := len(x) - 1; i >= 0; i-- {
print(" ", x[i]); print(" ", x[i]);
...@@ -113,16 +113,16 @@ export func Dump(x *[]Digit) { ...@@ -113,16 +113,16 @@ export func Dump(x *[]Digit) {
export type Natural []Digit; export type Natural []Digit;
var ( var (
NatZero *Natural = &Natural{}; NatZero Natural = *&Natural{};
NatOne *Natural = &Natural{1}; NatOne Natural = *&Natural{1};
NatTwo *Natural = &Natural{2}; NatTwo Natural = *&Natural{2};
NatTen *Natural = &Natural{10}; NatTen Natural = *&Natural{10};
) )
// Creation // Creation
export func Nat(x uint) *Natural { export func Nat(x uint) Natural {
switch x { switch x {
case 0: return NatZero; case 0: return NatZero;
case 1: return NatOne; case 1: return NatOne;
...@@ -130,7 +130,7 @@ export func Nat(x uint) *Natural { ...@@ -130,7 +130,7 @@ export func Nat(x uint) *Natural {
case 10: return NatTen; case 10: return NatTen;
} }
assert(Digit(x) < B); assert(Digit(x) < B);
return &Natural{Digit(x)}; return *&Natural{Digit(x)}; // TODO(rsc): *&
} }
...@@ -148,7 +148,7 @@ func (x *Natural) IsZero() bool { ...@@ -148,7 +148,7 @@ func (x *Natural) IsZero() bool {
// Operations // Operations
func Normalize(x *Natural) *Natural { func Normalize(x *Natural) Natural {
n := len(x); n := len(x);
for n > 0 && x[n - 1] == 0 { n-- } for n > 0 && x[n - 1] == 0 { n-- }
if n < len(x) { if n < len(x) {
...@@ -278,7 +278,7 @@ func (x *Natural) Mul(y *Natural) *Natural { ...@@ -278,7 +278,7 @@ func (x *Natural) Mul(y *Natural) *Natural {
// into operands with twice as many digits of half the size (Digit2), do // into operands with twice as many digits of half the size (Digit2), do
// DivMod, and then pack the results again. // DivMod, and then pack the results again.
func Unpack(x *Natural) *[]Digit2 { func Unpack(x *Natural) []Digit2 {
n := len(x); n := len(x);
z := new([]Digit2, n*2 + 1); // add space for extra digit (used by DivMod) z := new([]Digit2, n*2 + 1); // add space for extra digit (used by DivMod)
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
...@@ -294,7 +294,7 @@ func Unpack(x *Natural) *[]Digit2 { ...@@ -294,7 +294,7 @@ func Unpack(x *Natural) *[]Digit2 {
} }
func Pack(x *[]Digit2) *Natural { func Pack(x []Digit2) *Natural {
n := (len(x) + 1) / 2; n := (len(x) + 1) / 2;
z := new(Natural, n); z := new(Natural, n);
if len(x) & 1 == 1 { if len(x) & 1 == 1 {
...@@ -309,7 +309,7 @@ func Pack(x *[]Digit2) *Natural { ...@@ -309,7 +309,7 @@ func Pack(x *[]Digit2) *Natural {
} }
func Mul1(z, x *[]Digit2, y Digit2) Digit2 { func Mul1(z, x []Digit2, y Digit2) Digit2 {
n := len(x); n := len(x);
c := Digit(0); c := Digit(0);
f := Digit(y); f := Digit(y);
...@@ -321,7 +321,7 @@ func Mul1(z, x *[]Digit2, y Digit2) Digit2 { ...@@ -321,7 +321,7 @@ func Mul1(z, x *[]Digit2, y Digit2) Digit2 {
} }
func Div1(z, x *[]Digit2, y Digit2) Digit2 { func Div1(z, x []Digit2, y Digit2) Digit2 {
n := len(x); n := len(x);
c := Digit(0); c := Digit(0);
d := Digit(y); d := Digit(y);
...@@ -353,7 +353,7 @@ func Div1(z, x *[]Digit2, y Digit2) Digit2 { ...@@ -353,7 +353,7 @@ func Div1(z, x *[]Digit2, y Digit2) Digit2 {
// minefield. "Software - Practice and Experience 24", (June 1994), // minefield. "Software - Practice and Experience 24", (June 1994),
// 579-601. John Wiley & Sons, Ltd. // 579-601. John Wiley & Sons, Ltd.
func DivMod(x, y *[]Digit2) (*[]Digit2, *[]Digit2) { func DivMod(x, y []Digit2) ([]Digit2, []Digit2) {
n := len(x); n := len(x);
m := len(y); m := len(y);
if m == 0 { if m == 0 {
...@@ -458,7 +458,7 @@ func (x *Natural) DivMod(y *Natural) (*Natural, *Natural) { ...@@ -458,7 +458,7 @@ func (x *Natural) DivMod(y *Natural) (*Natural, *Natural) {
} }
func Shl(z, x *[]Digit, s uint) Digit { func Shl(z, x []Digit, s uint) Digit {
assert(s <= W); assert(s <= W);
n := len(x); n := len(x);
c := Digit(0); c := Digit(0);
...@@ -480,7 +480,7 @@ func (x *Natural) Shl(s uint) *Natural { ...@@ -480,7 +480,7 @@ func (x *Natural) Shl(s uint) *Natural {
} }
func Shr(z, x *[]Digit, s uint) Digit { func Shr(z, x []Digit, s uint) Digit {
assert(s <= W); assert(s <= W);
n := len(x); n := len(x);
c := Digit(0); c := Digit(0);
...@@ -522,7 +522,7 @@ func (x *Natural) And(y *Natural) *Natural { ...@@ -522,7 +522,7 @@ func (x *Natural) And(y *Natural) *Natural {
} }
func Copy(z, x *[]Digit) { func Copy(z, x []Digit) {
for i, e := range x { for i, e := range x {
z[i] = e z[i] = e
} }
......
...@@ -30,7 +30,7 @@ export var ( ...@@ -30,7 +30,7 @@ export var (
ShortWrite = os.NewError("short write"); ShortWrite = os.NewError("short write");
) )
func CopySlice(dst *[]byte, src *[]byte) { func CopySlice(dst []byte, src []byte) {
for i := 0; i < len(dst); i++ { for i := 0; i < len(dst); i++ {
dst[i] = src[i] dst[i] = src[i]
} }
...@@ -40,7 +40,7 @@ func CopySlice(dst *[]byte, src *[]byte) { ...@@ -40,7 +40,7 @@ func CopySlice(dst *[]byte, src *[]byte) {
// Buffered input. // Buffered input.
export type BufRead struct { export type BufRead struct {
buf *[]byte; buf []byte;
rd io.Read; rd io.Read;
r, w int; r, w int;
err *os.Error; err *os.Error;
...@@ -91,7 +91,7 @@ func (b *BufRead) Fill() *os.Error { ...@@ -91,7 +91,7 @@ func (b *BufRead) Fill() *os.Error {
// Returns the number of bytes read into p. // Returns the number of bytes read into p.
// If nn < len(p), also returns an error explaining // If nn < len(p), also returns an error explaining
// why the read is short. // why the read is short.
func (b *BufRead) Read(p *[]byte) (nn int, err *os.Error) { func (b *BufRead) Read(p []byte) (nn int, err *os.Error) {
nn = 0; nn = 0;
for len(p) > 0 { for len(p) > 0 {
n := len(p); n := len(p);
...@@ -170,7 +170,7 @@ func (b *BufRead) ReadRune() (rune int, size int, err *os.Error) { ...@@ -170,7 +170,7 @@ func (b *BufRead) ReadRune() (rune int, size int, err *os.Error) {
// Helper function: look for byte c in array p, // Helper function: look for byte c in array p,
// returning its index or -1. // returning its index or -1.
func FindByte(p *[]byte, c byte) int { func FindByte(p []byte, c byte) int {
for i := 0; i < len(p); i++ { for i := 0; i < len(p); i++ {
if p[i] == c { if p[i] == c {
return i return i
...@@ -190,9 +190,12 @@ func (b *BufRead) Buffered() int { ...@@ -190,9 +190,12 @@ func (b *BufRead) Buffered() int {
// Fails if the line doesn't fit in the buffer. // Fails if the line doesn't fit in the buffer.
// For internal (or advanced) use only. // For internal (or advanced) use only.
// Use ReadLineString or ReadLineBytes instead. // Use ReadLineString or ReadLineBytes instead.
func (b *BufRead) ReadLineSlice(delim byte) (line *[]byte, err *os.Error) {
var NIL []byte // TODO(rsc): should be able to use nil
func (b *BufRead) ReadLineSlice(delim byte) (line []byte, err *os.Error) {
if b.err != nil { if b.err != nil {
return nil, b.err return NIL, b.err
} }
// Look in buffer. // Look in buffer.
...@@ -207,7 +210,7 @@ func (b *BufRead) ReadLineSlice(delim byte) (line *[]byte, err *os.Error) { ...@@ -207,7 +210,7 @@ func (b *BufRead) ReadLineSlice(delim byte) (line *[]byte, err *os.Error) {
n := b.Buffered(); n := b.Buffered();
b.Fill(); b.Fill();
if b.err != nil { if b.err != nil {
return nil, b.err return NIL, b.err
} }
if b.Buffered() == n { // no data added; end of file if b.Buffered() == n { // no data added; end of file
line := b.buf[b.r:b.w]; line := b.buf[b.r:b.w];
...@@ -224,12 +227,12 @@ func (b *BufRead) ReadLineSlice(delim byte) (line *[]byte, err *os.Error) { ...@@ -224,12 +227,12 @@ func (b *BufRead) ReadLineSlice(delim byte) (line *[]byte, err *os.Error) {
// Buffer is full? // Buffer is full?
if b.Buffered() >= len(b.buf) { if b.Buffered() >= len(b.buf) {
return nil, BufferFull return NIL, BufferFull
} }
} }
// BUG 6g bug100 // BUG 6g bug100
return nil, nil return NIL, nil
} }
// Read until the first occurrence of delim in the input, // Read until the first occurrence of delim in the input,
...@@ -237,15 +240,15 @@ func (b *BufRead) ReadLineSlice(delim byte) (line *[]byte, err *os.Error) { ...@@ -237,15 +240,15 @@ func (b *BufRead) ReadLineSlice(delim byte) (line *[]byte, err *os.Error) {
// If an error happens, returns the data (without a delimiter) // If an error happens, returns the data (without a delimiter)
// and the error. (Can't leave the data in the buffer because // and the error. (Can't leave the data in the buffer because
// we might have read more than the buffer size.) // we might have read more than the buffer size.)
func (b *BufRead) ReadLineBytes(delim byte) (line *[]byte, err *os.Error) { func (b *BufRead) ReadLineBytes(delim byte) (line []byte, err *os.Error) {
if b.err != nil { if b.err != nil {
return nil, b.err return NIL, b.err
} }
// Use ReadLineSlice to look for array, // Use ReadLineSlice to look for array,
// accumulating full buffers. // accumulating full buffers.
var frag *[]byte; var frag []byte;
var full *[]*[]byte; var full [][]byte;
nfull := 0; nfull := 0;
err = nil; err = nil;
...@@ -276,10 +279,10 @@ func (b *BufRead) ReadLineBytes(delim byte) (line *[]byte, err *os.Error) { ...@@ -276,10 +279,10 @@ func (b *BufRead) ReadLineBytes(delim byte) (line *[]byte, err *os.Error) {
} }
// Grow list if needed. // Grow list if needed.
if full == nil { if len(full) == 0 {
full = new([]*[]byte, 16); full = new([][]byte, 16);
} else if nfull >= len(full) { } else if nfull >= len(full) {
newfull := new([]*[]byte, len(full)*2); newfull := new([][]byte, len(full)*2);
// BUG slice assignment // BUG slice assignment
for i := 0; i < len(full); i++ { for i := 0; i < len(full); i++ {
newfull[i] = full[i]; newfull[i] = full[i];
...@@ -297,9 +300,7 @@ func (b *BufRead) ReadLineBytes(delim byte) (line *[]byte, err *os.Error) { ...@@ -297,9 +300,7 @@ func (b *BufRead) ReadLineBytes(delim byte) (line *[]byte, err *os.Error) {
for i := 0; i < nfull; i++ { for i := 0; i < nfull; i++ {
n += len(full[i]) n += len(full[i])
} }
if frag != nil {
n += len(frag); n += len(frag);
}
// Copy full pieces and fragment in. // Copy full pieces and fragment in.
buf := new([]byte, n); buf := new([]byte, n);
...@@ -308,14 +309,12 @@ func (b *BufRead) ReadLineBytes(delim byte) (line *[]byte, err *os.Error) { ...@@ -308,14 +309,12 @@ func (b *BufRead) ReadLineBytes(delim byte) (line *[]byte, err *os.Error) {
CopySlice(buf[n:n+len(full[i])], full[i]); CopySlice(buf[n:n+len(full[i])], full[i]);
n += len(full[i]) n += len(full[i])
} }
if frag != nil { CopySlice(buf[n:n+len(frag)], frag);
CopySlice(buf[n:n+len(frag)], frag)
}
return buf, err return buf, err
} }
// BUG(bugs/bug102.go): string(empty bytes array) throws error // BUG(bugs/bug102.go): string(empty bytes array) throws error
func ToString(p *[]byte) string { func ToString(p []byte) string {
if len(p) == 0 { if len(p) == 0 {
return "" return ""
} }
...@@ -341,7 +340,7 @@ func (b *BufRead) ReadLineString(delim byte, savedelim bool) (line string, err * ...@@ -341,7 +340,7 @@ func (b *BufRead) ReadLineString(delim byte, savedelim bool) (line string, err *
export type BufWrite struct { export type BufWrite struct {
err *os.Error; err *os.Error;
buf *[]byte; buf []byte;
n int; n int;
wr io.Write; wr io.Write;
} }
...@@ -395,7 +394,7 @@ func (b *BufWrite) Buffered() int { ...@@ -395,7 +394,7 @@ func (b *BufWrite) Buffered() int {
return b.n return b.n
} }
func (b *BufWrite) Write(p *[]byte) (nn int, err *os.Error) { func (b *BufWrite) Write(p []byte) (nn int, err *os.Error) {
if b.err != nil { if b.err != nil {
return 0, b.err return 0, b.err
} }
......
...@@ -13,7 +13,7 @@ import ( ...@@ -13,7 +13,7 @@ import (
"testing"; "testing";
) )
func StringToBytes(s string) *[]byte { func StringToBytes(s string) []byte {
b := new([]byte, len(s)); b := new([]byte, len(s));
for i := 0; i < len(s); i++ { for i := 0; i < len(s); i++ {
b[i] = s[i] b[i] = s[i]
...@@ -22,7 +22,7 @@ func StringToBytes(s string) *[]byte { ...@@ -22,7 +22,7 @@ func StringToBytes(s string) *[]byte {
} }
// Should be in language! // Should be in language!
func Copy(p *[]byte, q *[]byte) { func Copy(p []byte, q []byte) {
for i := 0; i < len(p); i++ { for i := 0; i < len(p); i++ {
p[i] = q[i] p[i] = q[i]
} }
...@@ -30,16 +30,16 @@ func Copy(p *[]byte, q *[]byte) { ...@@ -30,16 +30,16 @@ func Copy(p *[]byte, q *[]byte) {
// Reads from p. // Reads from p.
type ByteReader struct { type ByteReader struct {
p *[]byte p []byte
} }
func NewByteReader(p *[]byte) io.Read { func NewByteReader(p []byte) io.Read {
b := new(ByteReader); b := new(ByteReader);
b.p = p; b.p = p;
return b return b
} }
func (b *ByteReader) Read(p *[]byte) (int, *os.Error) { func (b *ByteReader) Read(p []byte) (int, *os.Error) {
n := len(p); n := len(p);
if n > len(b.p) { if n > len(b.p) {
n = len(b.p) n = len(b.p)
...@@ -52,16 +52,16 @@ func (b *ByteReader) Read(p *[]byte) (int, *os.Error) { ...@@ -52,16 +52,16 @@ func (b *ByteReader) Read(p *[]byte) (int, *os.Error) {
// Reads from p but only returns half of what you asked for. // Reads from p but only returns half of what you asked for.
type HalfByteReader struct { type HalfByteReader struct {
p *[]byte p []byte
} }
func NewHalfByteReader(p *[]byte) io.Read { func NewHalfByteReader(p []byte) io.Read {
b := new(HalfByteReader); b := new(HalfByteReader);
b.p = p; b.p = p;
return b return b
} }
func (b *HalfByteReader) Read(p *[]byte) (int, *os.Error) { func (b *HalfByteReader) Read(p []byte) (int, *os.Error) {
n := len(p)/2; n := len(p)/2;
if n == 0 && len(p) > 0 { if n == 0 && len(p) > 0 {
n = 1 n = 1
...@@ -85,7 +85,7 @@ func NewRot13Reader(r io.Read) *Rot13Reader { ...@@ -85,7 +85,7 @@ func NewRot13Reader(r io.Read) *Rot13Reader {
return r13 return r13
} }
func (r13 *Rot13Reader) Read(p *[]byte) (int, *os.Error) { func (r13 *Rot13Reader) Read(p []byte) (int, *os.Error) {
n, e := r13.r.Read(p); n, e := r13.r.Read(p);
if e != nil { if e != nil {
return n, e return n, e
...@@ -104,11 +104,11 @@ func (r13 *Rot13Reader) Read(p *[]byte) (int, *os.Error) { ...@@ -104,11 +104,11 @@ func (r13 *Rot13Reader) Read(p *[]byte) (int, *os.Error) {
type Readmaker struct { type Readmaker struct {
name string; name string;
fn *(*[]byte) io.Read; fn *([]byte) io.Read;
} }
var readmakers = []Readmaker { var readmakers = []Readmaker {
Readmaker{ "full", func(p *[]byte) io.Read { return NewByteReader(p) } }, Readmaker{ "full", func(p []byte) io.Read { return NewByteReader(p) } },
Readmaker{ "half", func(p *[]byte) io.Read { return NewHalfByteReader(p) } }, Readmaker{ "half", func(p []byte) io.Read { return NewHalfByteReader(p) } },
} }
// Call ReadLineString (which ends up calling everything else) // Call ReadLineString (which ends up calling everything else)
...@@ -152,14 +152,13 @@ func Reads(buf *BufRead, m int) string { ...@@ -152,14 +152,13 @@ func Reads(buf *BufRead, m int) string {
var b [1000]byte; var b [1000]byte;
nb := 0; nb := 0;
for { for {
// BUG parens around (&b) should not be needed n, e := buf.Read(b[nb:nb+m]);
n, e := buf.Read((&b)[nb:nb+m]);
nb += n; nb += n;
if e == EndOfFile { if e == EndOfFile {
break break
} }
} }
return string((&b)[0:nb]) return string(b[0:nb])
} }
type Bufreader struct { type Bufreader struct {
...@@ -228,13 +227,13 @@ export func TestBufRead(t *testing.T) { ...@@ -228,13 +227,13 @@ export func TestBufRead(t *testing.T) {
} }
type WriteBuffer interface { type WriteBuffer interface {
Write(p *[]byte) (int, *os.Error); Write(p []byte) (int, *os.Error);
GetBytes() *[]byte GetBytes() []byte
} }
// Accumulates bytes into a byte array. // Accumulates bytes into a byte array.
type ByteWriter struct { type ByteWriter struct {
p *[]byte; p []byte;
n int n int
} }
...@@ -242,7 +241,7 @@ func NewByteWriter() WriteBuffer { ...@@ -242,7 +241,7 @@ func NewByteWriter() WriteBuffer {
return new(ByteWriter) return new(ByteWriter)
} }
func (w *ByteWriter) Write(p *[]byte) (int, *os.Error) { func (w *ByteWriter) Write(p []byte) (int, *os.Error) {
if w.p == nil { if w.p == nil {
w.p = new([]byte, len(p)+100) w.p = new([]byte, len(p)+100)
} else if w.n + len(p) >= len(w.p) { } else if w.n + len(p) >= len(w.p) {
...@@ -255,7 +254,7 @@ func (w *ByteWriter) Write(p *[]byte) (int, *os.Error) { ...@@ -255,7 +254,7 @@ func (w *ByteWriter) Write(p *[]byte) (int, *os.Error) {
return len(p), nil return len(p), nil
} }
func (w *ByteWriter) GetBytes() *[]byte { func (w *ByteWriter) GetBytes() []byte {
return w.p[0:w.n] return w.p[0:w.n]
} }
...@@ -272,14 +271,14 @@ func NewHalfByteWriter() WriteBuffer { ...@@ -272,14 +271,14 @@ func NewHalfByteWriter() WriteBuffer {
return w return w
} }
func (w *HalfByteWriter) Write(p *[]byte) (int, *os.Error) { func (w *HalfByteWriter) Write(p []byte) (int, *os.Error) {
n := (len(p)+1) / 2; n := (len(p)+1) / 2;
// BUG return w.bw.Write(p[0:n]) // BUG return w.bw.Write(p[0:n])
r, e := w.bw.Write(p[0:n]); r, e := w.bw.Write(p[0:n]);
return r, e return r, e
} }
func (w *HalfByteWriter) GetBytes() *[]byte { func (w *HalfByteWriter) GetBytes() []byte {
return w.bw.GetBytes() return w.bw.GetBytes()
} }
...@@ -315,7 +314,7 @@ export func TestBufWrite(t *testing.T) { ...@@ -315,7 +314,7 @@ export func TestBufWrite(t *testing.T) {
t.Errorf("%s: NewBufWriteSize %d: %v", context, bs, e); t.Errorf("%s: NewBufWriteSize %d: %v", context, bs, e);
continue; continue;
} }
n, e1 := buf.Write((&data)[0:nwrite]); n, e1 := buf.Write(data[0:nwrite]);
if e1 != nil || n != nwrite { if e1 != nil || n != nwrite {
t.Errorf("%s: buf.Write %d = %d, %v", context, nwrite, n, e1); t.Errorf("%s: buf.Write %d = %d, %v", context, nwrite, n, e1);
continue; continue;
...@@ -331,7 +330,7 @@ export func TestBufWrite(t *testing.T) { ...@@ -331,7 +330,7 @@ export func TestBufWrite(t *testing.T) {
for l := 0; l < len(written); l++ { for l := 0; l < len(written); l++ {
if written[i] != data[i] { if written[i] != data[i] {
t.Errorf("%s: wrong bytes written"); t.Errorf("%s: wrong bytes written");
t.Errorf("want=%s", (&data)[0:len(written)]); t.Errorf("want=%s", data[0:len(written)]);
t.Errorf("have=%s", written); t.Errorf("have=%s", written);
} }
} }
......
...@@ -10,14 +10,14 @@ export type Element interface { ...@@ -10,14 +10,14 @@ export type Element interface {
export type Array struct { export type Array struct {
// TODO do not export field // TODO do not export field
a *[]Element a []Element
} }
func (p *Array) Init(initial_len int) *Array { func (p *Array) Init(initial_len int) *Array {
a := p.a; a := p.a;
if a == nil || cap(a) < initial_len { if cap(a) == 0 || cap(a) < initial_len {
n := 8; // initial capacity n := 8; // initial capacity
if initial_len > n { if initial_len > n {
n = initial_len n = initial_len
......
...@@ -26,11 +26,13 @@ type FmtTest struct { ...@@ -26,11 +26,13 @@ type FmtTest struct {
out string; out string;
} }
func Bytes(s string) *[]byte { // TODO(rsc): return []byte, but need to be able to pass as interface.
b := new([]byte, len(s)+1); // func Bytes(s string) []byte {
syscall.StringToBytes(b, s); // b := new([]byte, len(s)+1);
return b[0:len(s)]; // syscall.StringToBytes(b, s);
} // return b[0:len(s)];
// }
func Bytes(s string) string { return s }
const B32 uint32 = 1<<32 - 1 const B32 uint32 = 1<<32 - 1
const B64 uint64 = 1<<64 - 1 const B64 uint64 = 1<<64 - 1
......
...@@ -20,7 +20,7 @@ import ( ...@@ -20,7 +20,7 @@ import (
// Provides access to the io.Write interface plus information about // Provides access to the io.Write interface plus information about
// the active formatting verb. // the active formatting verb.
export type Formatter interface { export type Formatter interface {
Write(b *[]byte) (ret int, err *os.Error); Write(b []byte) (ret int, err *os.Error);
Width() (wid int, ok bool); Width() (wid int, ok bool);
Precision() (prec int, ok bool); Precision() (prec int, ok bool);
...@@ -41,7 +41,7 @@ const AllocSize = 32 ...@@ -41,7 +41,7 @@ const AllocSize = 32
type P struct { type P struct {
n int; n int;
buf *[]byte; buf []byte;
fmt *Fmt; fmt *Fmt;
} }
...@@ -76,11 +76,8 @@ func (p *P) Flag(b int) bool { ...@@ -76,11 +76,8 @@ func (p *P) Flag(b int) bool {
} }
func (p *P) ensure(n int) { func (p *P) ensure(n int) {
if p.buf == nil || len(p.buf) < n { if len(p.buf) < n {
newn := AllocSize; newn := AllocSize + len(p.buf);
if p.buf != nil {
newn += len(p.buf);
}
if newn < n { if newn < n {
newn = n + AllocSize newn = n + AllocSize
} }
...@@ -101,7 +98,7 @@ func (p *P) addstr(s string) { ...@@ -101,7 +98,7 @@ func (p *P) addstr(s string) {
} }
} }
func (p *P) addbytes(b *[]byte, start, end int) { func (p *P) addbytes(b []byte, start, end int) {
p.ensure(p.n + end-start); p.ensure(p.n + end-start);
for i := start; i < end; i++ { for i := start; i < end; i++ {
p.buf[p.n] = b[i]; p.buf[p.n] = b[i];
...@@ -121,7 +118,7 @@ func (p *P) add(c int) { ...@@ -121,7 +118,7 @@ func (p *P) add(c int) {
// Implement Write so we can call fprintf on a P, for // Implement Write so we can call fprintf on a P, for
// recursive use in custom verbs. // recursive use in custom verbs.
func (p *P) Write(b *[]byte) (ret int, err *os.Error) { func (p *P) Write(b []byte) (ret int, err *os.Error) {
p.addbytes(b, 0, len(b)); p.addbytes(b, 0, len(b));
return len(b), nil; return len(b), nil;
} }
...@@ -257,7 +254,7 @@ func getString(v reflect.Value) (val string, ok bool) { ...@@ -257,7 +254,7 @@ func getString(v reflect.Value) (val string, ok bool) {
case reflect.StringKind: case reflect.StringKind:
return v.(reflect.StringValue).Get(), true; return v.(reflect.StringValue).Get(), true;
} }
if valb, okb := v.Interface().(*[]byte); okb { if valb, okb := v.Interface().([]byte); okb {
return string(valb), true; return string(valb), true;
} }
return "", false; return "", false;
......
...@@ -26,7 +26,7 @@ export func NewDigest() *Digest { ...@@ -26,7 +26,7 @@ export func NewDigest() *Digest {
return &Digest{1, 0, 0}; return &Digest{1, 0, 0};
} }
func (d *Digest) Write(p *[]byte) (nn int, err *os.Error) { func (d *Digest) Write(p []byte) (nn int, err *os.Error) {
a, b, n := d.a, d.b, d.n; a, b, n := d.a, d.b, d.n;
for i := 0; i < len(p); i++ { for i := 0; i < len(p); i++ {
a += uint32(p[i]); a += uint32(p[i]);
...@@ -51,7 +51,7 @@ func (d *Digest) Sum32() uint32 { ...@@ -51,7 +51,7 @@ func (d *Digest) Sum32() uint32 {
return b<<16 | a; return b<<16 | a;
} }
func (d *Digest) Sum() *[]byte { func (d *Digest) Sum() []byte {
p := new([]byte, 4); p := new([]byte, 4);
s := d.Sum32(); s := d.Sum32();
p[0] = byte(s>>24); p[0] = byte(s>>24);
......
...@@ -25,10 +25,11 @@ export const ( ...@@ -25,10 +25,11 @@ export const (
Koopman = 0xeb31d82e; Koopman = 0xeb31d82e;
) )
export type Table [256]uint32 // TODO(rsc): Change to [256]uint32
export type Table []uint32
export func MakeTable(poly uint32) *Table { export func MakeTable(poly uint32) Table {
t := new(Table); t := new(Table, 256);
for i := 0; i < 256; i++ { for i := 0; i < 256; i++ {
crc := uint32(i); crc := uint32(i);
for j := 0; j < 8; j++ { for j := 0; j < 8; j++ {
...@@ -47,10 +48,10 @@ export var ieee = MakeTable(IEEE); ...@@ -47,10 +48,10 @@ export var ieee = MakeTable(IEEE);
export type Digest struct { export type Digest struct {
crc uint32; crc uint32;
tab *Table; tab Table;
} }
export func NewDigest(tab *Table) *Digest { export func NewDigest(tab Table) *Digest {
return &Digest{0, tab}; return &Digest{0, tab};
} }
...@@ -58,7 +59,7 @@ export func NewIEEEDigest() *Digest { ...@@ -58,7 +59,7 @@ export func NewIEEEDigest() *Digest {
return NewDigest(ieee); return NewDigest(ieee);
} }
func (d *Digest) Write(p *[]byte) (n int, err *os.Error) { func (d *Digest) Write(p []byte) (n int, err *os.Error) {
crc := d.crc ^ 0xFFFFFFFF; crc := d.crc ^ 0xFFFFFFFF;
tab := d.tab; tab := d.tab;
for i := 0; i < len(p); i++ { for i := 0; i < len(p); i++ {
...@@ -72,7 +73,7 @@ func (d *Digest) Sum32() uint32 { ...@@ -72,7 +73,7 @@ func (d *Digest) Sum32() uint32 {
return d.crc return d.crc
} }
func (d *Digest) Sum() *[]byte { func (d *Digest) Sum() []byte {
p := new([]byte, 4); p := new([]byte, 4);
s := d.Sum32(); s := d.Sum32();
p[0] = byte(s>>24); p[0] = byte(s>>24);
......
...@@ -35,9 +35,9 @@ export func NewDigest() *Digest { ...@@ -35,9 +35,9 @@ export func NewDigest() *Digest {
return d; return d;
} }
package func Block(dig *Digest, p *[]byte) int package func Block(dig *Digest, p []byte) int
func (d *Digest) Write(p *[]byte) (nn int, err *os.Error) { func (d *Digest) Write(p []byte) (nn int, err *os.Error) {
nn = len(p); nn = len(p);
d.len += uint64(nn); d.len += uint64(nn);
if d.nx > 0 { if d.nx > 0 {
...@@ -50,7 +50,7 @@ func (d *Digest) Write(p *[]byte) (nn int, err *os.Error) { ...@@ -50,7 +50,7 @@ func (d *Digest) Write(p *[]byte) (nn int, err *os.Error) {
} }
d.nx += n; d.nx += n;
if d.nx == Chunk { if d.nx == Chunk {
Block(d, &d.x); Block(d, d.x);
d.nx = 0; d.nx = 0;
} }
p = p[n:len(p)]; p = p[n:len(p)];
...@@ -66,15 +66,15 @@ func (d *Digest) Write(p *[]byte) (nn int, err *os.Error) { ...@@ -66,15 +66,15 @@ func (d *Digest) Write(p *[]byte) (nn int, err *os.Error) {
return; return;
} }
func (d *Digest) Sum() *[]byte { func (d *Digest) Sum() []byte {
// Padding. Add a 1 bit and 0 bits until 56 bytes mod 64. // Padding. Add a 1 bit and 0 bits until 56 bytes mod 64.
len := d.len; len := d.len;
var tmp [64]byte; var tmp [64]byte;
tmp[0] = 0x80; tmp[0] = 0x80;
if len%64 < 56 { if len%64 < 56 {
d.Write((&tmp)[0:56-len%64]); d.Write(tmp[0:56-len%64]);
} else { } else {
d.Write((&tmp)[0:64+56-len%64]); d.Write(tmp[0:64+56-len%64]);
} }
// Length in bits. // Length in bits.
...@@ -82,7 +82,7 @@ func (d *Digest) Sum() *[]byte { ...@@ -82,7 +82,7 @@ func (d *Digest) Sum() *[]byte {
for i := uint(0); i < 8; i++ { for i := uint(0); i < 8; i++ {
tmp[i] = byte(len>>(8*i)); tmp[i] = byte(len>>(8*i));
} }
d.Write((&tmp)[0:8]); d.Write(tmp[0:8]);
if d.nx != 0 { if d.nx != 0 {
panicln("oops"); panicln("oops");
......
...@@ -49,7 +49,7 @@ var golden = []Md5Test { ...@@ -49,7 +49,7 @@ var golden = []Md5Test {
Md5Test{ "132f7619d33b523b1d9e5bd8e0928355", "How can you write a big system without C++? -Paul Glick" }, Md5Test{ "132f7619d33b523b1d9e5bd8e0928355", "How can you write a big system without C++? -Paul Glick" },
} }
func Hex(p *[]byte) string { func Hex(p []byte) string {
s := ""; s := "";
for i := 0; i < len(p); i++ { for i := 0; i < len(p); i++ {
v := p[i]; v := p[i];
......
...@@ -90,7 +90,7 @@ var shift2 = []uint { 5, 9, 14, 20 }; ...@@ -90,7 +90,7 @@ var shift2 = []uint { 5, 9, 14, 20 };
var shift3 = []uint { 4, 11, 16, 23 }; var shift3 = []uint { 4, 11, 16, 23 };
var shift4 = []uint { 6, 10, 15, 21 }; var shift4 = []uint { 6, 10, 15, 21 };
package func Block(dig *Digest, p *[]byte) int { package func Block(dig *Digest, p []byte) int {
a := dig.s[0]; a := dig.s[0];
b := dig.s[1]; b := dig.s[1];
c := dig.s[2]; c := dig.s[2];
......
...@@ -37,9 +37,9 @@ export func NewDigest() *Digest { ...@@ -37,9 +37,9 @@ export func NewDigest() *Digest {
return d; return d;
} }
package func Block(dig *Digest, p *[]byte) int package func Block(dig *Digest, p []byte) int
func (d *Digest) Write(p *[]byte) (nn int, err *os.Error) { func (d *Digest) Write(p []byte) (nn int, err *os.Error) {
nn = len(p); nn = len(p);
d.len += uint64(nn); d.len += uint64(nn);
if d.nx > 0 { if d.nx > 0 {
...@@ -52,7 +52,7 @@ func (d *Digest) Write(p *[]byte) (nn int, err *os.Error) { ...@@ -52,7 +52,7 @@ func (d *Digest) Write(p *[]byte) (nn int, err *os.Error) {
} }
d.nx += n; d.nx += n;
if d.nx == Chunk { if d.nx == Chunk {
Block(d, &d.x); Block(d, d.x);
d.nx = 0; d.nx = 0;
} }
p = p[n:len(p)]; p = p[n:len(p)];
...@@ -68,15 +68,15 @@ func (d *Digest) Write(p *[]byte) (nn int, err *os.Error) { ...@@ -68,15 +68,15 @@ func (d *Digest) Write(p *[]byte) (nn int, err *os.Error) {
return; return;
} }
func (d *Digest) Sum() *[]byte { func (d *Digest) Sum() []byte {
// Padding. Add a 1 bit and 0 bits until 56 bytes mod 64. // Padding. Add a 1 bit and 0 bits until 56 bytes mod 64.
len := d.len; len := d.len;
var tmp [64]byte; var tmp [64]byte;
tmp[0] = 0x80; tmp[0] = 0x80;
if len%64 < 56 { if len%64 < 56 {
d.Write((&tmp)[0:56-len%64]); d.Write(tmp[0:56-len%64]);
} else { } else {
d.Write((&tmp)[0:64+56-len%64]); d.Write(tmp[0:64+56-len%64]);
} }
// Length in bits. // Length in bits.
...@@ -84,7 +84,7 @@ func (d *Digest) Sum() *[]byte { ...@@ -84,7 +84,7 @@ func (d *Digest) Sum() *[]byte {
for i := uint(0); i < 8; i++ { for i := uint(0); i < 8; i++ {
tmp[i] = byte(len>>(56-8*i)); tmp[i] = byte(len>>(56-8*i));
} }
d.Write((&tmp)[0:8]); d.Write(tmp[0:8]);
if d.nx != 0 { if d.nx != 0 {
panicln("oops"); panicln("oops");
......
...@@ -51,7 +51,7 @@ var golden = []Sha1Test { ...@@ -51,7 +51,7 @@ var golden = []Sha1Test {
Sha1Test{ "6627d6904d71420b0bf3886ab629623538689f45", "How can you write a big system without C++? -Paul Glick" }, Sha1Test{ "6627d6904d71420b0bf3886ab629623538689f45", "How can you write a big system without C++? -Paul Glick" },
} }
func Hex(p *[]byte) string { func Hex(p []byte) string {
s := ""; s := "";
for i := 0; i < len(p); i++ { for i := 0; i < len(p); i++ {
v := p[i]; v := p[i];
......
...@@ -17,7 +17,7 @@ const ( ...@@ -17,7 +17,7 @@ const (
K3 = 0xCA62C1D6; K3 = 0xCA62C1D6;
) )
package func Block(dig *Digest, p *[]byte) int { package func Block(dig *Digest, p []byte) int {
var w [80]uint32; var w [80]uint32;
n := 0; n := 0;
......
...@@ -45,16 +45,18 @@ export type Request struct { ...@@ -45,16 +45,18 @@ export type Request struct {
useragent string; useragent string;
} }
var NIL []byte // TODO(rsc)
// Read a line of bytes (up to \n) from b. // Read a line of bytes (up to \n) from b.
// Give up if the line exceeds MaxLineLength. // Give up if the line exceeds MaxLineLength.
// The returned bytes are a pointer into storage in // The returned bytes are a pointer into storage in
// the bufio, so they are only valid until the next bufio read. // the bufio, so they are only valid until the next bufio read.
func ReadLineBytes(b *bufio.BufRead) (p *[]byte, err *os.Error) { func ReadLineBytes(b *bufio.BufRead) (p []byte, err *os.Error) {
if p, err = b.ReadLineSlice('\n'); err != nil { if p, err = b.ReadLineSlice('\n'); err != nil {
return nil, err return NIL, err
} }
if len(p) >= MaxLineLength { if len(p) >= MaxLineLength {
return nil, LineTooLong return NIL, LineTooLong
} }
// Chop off trailing white space. // Chop off trailing white space.
...@@ -189,7 +191,7 @@ export func ReadRequest(b *bufio.BufRead) (req *Request, err *os.Error) { ...@@ -189,7 +191,7 @@ export func ReadRequest(b *bufio.BufRead) (req *Request, err *os.Error) {
return nil, err return nil, err
} }
var f *[]string; var f []string;
if f = strings.split(s, " "); len(f) != 3 { if f = strings.split(s, " "); len(f) != 3 {
return nil, BadRequest return nil, BadRequest
} }
......
...@@ -16,7 +16,7 @@ import ( ...@@ -16,7 +16,7 @@ import (
// TODO(r): Do better memory management. // TODO(r): Do better memory management.
func bytecopy(dst *[]byte, doff int, src *[]byte, soff int, count int) { func bytecopy(dst []byte, doff int, src []byte, soff int, count int) {
for i := 0; i < count; i++ { for i := 0; i < count; i++ {
dst[doff] = src[soff]; dst[doff] = src[soff];
doff++; doff++;
...@@ -25,7 +25,7 @@ func bytecopy(dst *[]byte, doff int, src *[]byte, soff int, count int) { ...@@ -25,7 +25,7 @@ func bytecopy(dst *[]byte, doff int, src *[]byte, soff int, count int) {
} }
export type ByteBuffer struct { export type ByteBuffer struct {
buf *[]byte; buf []byte;
off int; // Read from here off int; // Read from here
len int; // Write to here len int; // Write to here
cap int; cap int;
...@@ -36,9 +36,9 @@ func (b *ByteBuffer) Reset() { ...@@ -36,9 +36,9 @@ func (b *ByteBuffer) Reset() {
b.len = 0; b.len = 0;
} }
func (b *ByteBuffer) Write(p *[]byte) (n int, err *os.Error) { func (b *ByteBuffer) Write(p []byte) (n int, err *os.Error) {
plen := len(p); plen := len(p);
if b.buf == nil { if len(b.buf) == 0 {
b.cap = plen + 1024; b.cap = plen + 1024;
b.buf = new([]byte, b.cap); b.buf = new([]byte, b.cap);
b.len = 0; b.len = 0;
...@@ -54,9 +54,9 @@ func (b *ByteBuffer) Write(p *[]byte) (n int, err *os.Error) { ...@@ -54,9 +54,9 @@ func (b *ByteBuffer) Write(p *[]byte) (n int, err *os.Error) {
return plen, nil; return plen, nil;
} }
func (b *ByteBuffer) Read(p *[]byte) (n int, err *os.Error) { func (b *ByteBuffer) Read(p []byte) (n int, err *os.Error) {
plen := len(p); plen := len(p);
if b.buf == nil { if len(b.buf) == 0 {
return 0, nil return 0, nil
} }
if b.off == b.len { // empty buffer if b.off == b.len { // empty buffer
...@@ -75,20 +75,12 @@ func (b *ByteBuffer) Len() int { ...@@ -75,20 +75,12 @@ func (b *ByteBuffer) Len() int {
return b.len return b.len
} }
// If the buffer is empty, Data() should still give a valid array. func (b *ByteBuffer) Data() []byte {
// Use this variable as a surrogate. It's immutable (can't be
// grown, can't store any data) so it's safe to share.
var EmptyByteArray = new([]byte, 0)
func (b *ByteBuffer) Data() *[]byte {
if b.buf == nil {
return EmptyByteArray
}
return b.buf[b.off:b.len] return b.buf[b.off:b.len]
} }
export func NewByteBufferFromArray(buf *[]byte) *ByteBuffer { export func NewByteBufferFromArray(buf []byte) *ByteBuffer {
b := new(ByteBuffer); b := new(ByteBuffer);
b.buf = buf; b.buf = buf;
b.off = 0; b.off = 0;
......
...@@ -12,21 +12,21 @@ import ( ...@@ -12,21 +12,21 @@ import (
export var ErrEOF = os.NewError("EOF") export var ErrEOF = os.NewError("EOF")
export type Read interface { export type Read interface {
Read(p *[]byte) (n int, err *os.Error); Read(p []byte) (n int, err *os.Error);
} }
export type Write interface { export type Write interface {
Write(p *[]byte) (n int, err *os.Error); Write(p []byte) (n int, err *os.Error);
} }
export type ReadWrite interface { export type ReadWrite interface {
Read(p *[]byte) (n int, err *os.Error); Read(p []byte) (n int, err *os.Error);
Write(p *[]byte) (n int, err *os.Error); Write(p []byte) (n int, err *os.Error);
} }
export type ReadWriteClose interface { export type ReadWriteClose interface {
Read(p *[]byte) (n int, err *os.Error); Read(p []byte) (n int, err *os.Error);
Write(p *[]byte) (n int, err *os.Error); Write(p []byte) (n int, err *os.Error);
Close() *os.Error; Close() *os.Error;
} }
...@@ -41,7 +41,7 @@ export func WriteString(w Write, s string) (n int, err *os.Error) { ...@@ -41,7 +41,7 @@ export func WriteString(w Write, s string) (n int, err *os.Error) {
} }
// Read until buffer is full, EOF, or error // Read until buffer is full, EOF, or error
export func Readn(fd Read, buf *[]byte) (n int, err *os.Error) { export func Readn(fd Read, buf []byte) (n int, err *os.Error) {
n = 0; n = 0;
for n < len(buf) { for n < len(buf) {
nn, e := fd.Read(buf[n:len(buf)]); nn, e := fd.Read(buf[n:len(buf)]);
...@@ -64,7 +64,7 @@ type FullRead struct { ...@@ -64,7 +64,7 @@ type FullRead struct {
fd Read; fd Read;
} }
func (fd *FullRead) Read(p *[]byte) (n int, err *os.Error) { func (fd *FullRead) Read(p []byte) (n int, err *os.Error) {
n, err = Readn(fd.fd, p); n, err = Readn(fd.fd, p);
return n, err return n, err
} }
...@@ -147,7 +147,7 @@ export func Copy(src Read, dst Write) (written int64, err *os.Error) { ...@@ -147,7 +147,7 @@ export func Copy(src Read, dst Write) (written int64, err *os.Error) {
// Convert a string to an array of bytes for easy marshaling. // Convert a string to an array of bytes for easy marshaling.
// Could fill with syscall.StringToBytes but it adds an unnecessary \000 // Could fill with syscall.StringToBytes but it adds an unnecessary \000
// so the length would be wrong. // so the length would be wrong.
export func StringBytes(s string) *[]byte { export func StringBytes(s string) []byte {
b := new([]byte, len(s)); b := new([]byte, len(s));
for i := 0; i < len(s); i++ { for i := 0; i < len(s); i++ {
b[i] = s[i]; b[i] = s[i];
......
...@@ -26,7 +26,7 @@ type MyStruct struct { ...@@ -26,7 +26,7 @@ type MyStruct struct {
fl float; fl float;
fl32 float32; fl32 float32;
fl64 float64; fl64 float64;
a *[]string; a []string;
my *MyStruct; my *MyStruct;
}; };
...@@ -69,7 +69,7 @@ export func TestUnmarshal(t *testing.T) { ...@@ -69,7 +69,7 @@ export func TestUnmarshal(t *testing.T) {
Check(t, m.fl==11.5, "fl", m.fl); Check(t, m.fl==11.5, "fl", m.fl);
Check(t, m.fl32==12.25, "fl32", m.fl32); Check(t, m.fl32==12.25, "fl32", m.fl32);
Check(t, m.fl64==13.75, "fl64", m.fl64); Check(t, m.fl64==13.75, "fl64", m.fl64);
Check(t, m.a!=nil, "a", m.a); // Check(t, m.a!=nil, "a", m.a); // TODO(rsc): uncomment once []string as interface works
if m.a != nil { if m.a != nil {
Check(t, m.a[0]=="x", "a[0]", m.a[0]); Check(t, m.a[0]=="x", "a[0]", m.a[0]);
Check(t, m.a[1]=="y", "a[1]", m.a[1]); Check(t, m.a[1]=="y", "a[1]", m.a[1]);
......
...@@ -46,7 +46,7 @@ func Exchange(cfg *DNS_Config, c Conn, name string) (m *DNS_Msg, err *os.Error) ...@@ -46,7 +46,7 @@ func Exchange(cfg *DNS_Config, c Conn, name string) (m *DNS_Msg, err *os.Error)
} }
out := new(DNS_Msg); out := new(DNS_Msg);
out.id = 0x1234; out.id = 0x1234;
out.question = &[]DNS_Question{ out.question = []DNS_Question{
DNS_Question{ name, DNS_TypeA, DNS_ClassINET } DNS_Question{ name, DNS_TypeA, DNS_ClassINET }
}; };
out.recursion_desired = true; out.recursion_desired = true;
...@@ -80,21 +80,24 @@ func Exchange(cfg *DNS_Config, c Conn, name string) (m *DNS_Msg, err *os.Error) ...@@ -80,21 +80,24 @@ func Exchange(cfg *DNS_Config, c Conn, name string) (m *DNS_Msg, err *os.Error)
return nil, DNS_NoAnswer return nil, DNS_NoAnswer
} }
var NIL []string // TODO(rsc)
// Find answer for name in dns message. // Find answer for name in dns message.
// On return, if err == nil, addrs != nil. // On return, if err == nil, addrs != nil.
// TODO(rsc): Maybe return *[]*[]byte (==*[]IPAddr) instead? // TODO(rsc): Maybe return [][]byte (==[]IPAddr) instead?
func Answer(name string, dns *DNS_Msg) (addrs *[]string, err *os.Error) { func Answer(name string, dns *DNS_Msg) (addrs []string, err *os.Error) {
addrs = new([]string, len(dns.answer))[0:0]; addrs = new([]string, len(dns.answer))[0:0];
if dns.rcode == DNS_RcodeNameError && dns.authoritative { if dns.rcode == DNS_RcodeNameError && dns.authoritative {
return nil, DNS_NameNotFound // authoritative "no such host" return NIL, DNS_NameNotFound // authoritative "no such host"
} }
if dns.rcode != DNS_RcodeSuccess { if dns.rcode != DNS_RcodeSuccess {
// None of the error codes make sense // None of the error codes make sense
// for the query we sent. If we didn't get // for the query we sent. If we didn't get
// a name error and we didn't get success, // a name error and we didn't get success,
// the server is behaving incorrectly. // the server is behaving incorrectly.
return nil, DNS_ServerFailure return NIL, DNS_ServerFailure
} }
// Look for the name. // Look for the name.
...@@ -123,18 +126,18 @@ Cname: ...@@ -123,18 +126,18 @@ Cname:
} }
} }
if len(addrs) == 0 { if len(addrs) == 0 {
return nil, DNS_NameNotFound return NIL, DNS_NameNotFound
} }
return addrs, nil return addrs, nil
} }
// Too many redirects // Too many redirects
return nil, DNS_RedirectLoop return NIL, DNS_RedirectLoop
} }
// Do a lookup for a single name, which must be rooted // Do a lookup for a single name, which must be rooted
// (otherwise Answer will not find the answers). // (otherwise Answer will not find the answers).
func TryOneName(cfg *DNS_Config, name string) (addrs *[]string, err *os.Error) { func TryOneName(cfg *DNS_Config, name string) (addrs []string, err *os.Error) {
err = DNS_NoServers; err = DNS_NoServers;
for i := 0; i < len(cfg.servers); i++ { for i := 0; i < len(cfg.servers); i++ {
// Calling Dial here is scary -- we have to be sure // Calling Dial here is scary -- we have to be sure
...@@ -170,7 +173,7 @@ func LoadConfig() { ...@@ -170,7 +173,7 @@ func LoadConfig() {
cfg = DNS_ReadConfig(); cfg = DNS_ReadConfig();
} }
export func LookupHost(name string) (name1 string, addrs *[]string, err *os.Error) { export func LookupHost(name string) (name1 string, addrs []string, err *os.Error) {
// TODO(rsc): Pick out obvious non-DNS names to avoid // TODO(rsc): Pick out obvious non-DNS names to avoid
// sending stupid requests to the server? // sending stupid requests to the server?
......
...@@ -14,8 +14,8 @@ import ( ...@@ -14,8 +14,8 @@ import (
) )
export type DNS_Config struct { export type DNS_Config struct {
servers *[]string; // servers to use servers []string; // servers to use
search *[]string; // suffixes to append to local name search []string; // suffixes to append to local name
ndots int; // number of dots in name to trigger absolute lookup ndots int; // number of dots in name to trigger absolute lookup
timeout int; // seconds before giving up on packet timeout int; // seconds before giving up on packet
attempts int; // lost packets before giving up on server attempts int; // lost packets before giving up on server
...@@ -53,7 +53,7 @@ export func DNS_ReadConfig() *DNS_Config { ...@@ -53,7 +53,7 @@ export func DNS_ReadConfig() *DNS_Config {
// just an IP address. Otherwise we need DNS // just an IP address. Otherwise we need DNS
// to look it up. // to look it up.
name := f[1]; name := f[1];
if ParseIP(name) != nil { if len(ParseIP(name)) != 0 {
a = a[0:n+1]; a = a[0:n+1];
a[n] = name; a[n] = name;
conf.servers = a; conf.servers = a;
......
...@@ -190,7 +190,7 @@ export type DNS_RR_A struct { ...@@ -190,7 +190,7 @@ export type DNS_RR_A struct {
// Packing and unpacking. // Packing and unpacking.
// //
// All the packers and unpackers take a (msg *[]byte, off int) // All the packers and unpackers take a (msg []byte, off int)
// and return (off1 int, ok bool). If they return ok==false, they // and return (off1 int, ok bool). If they return ok==false, they
// also return off1==len(msg), so that the next unpacker will // also return off1==len(msg), so that the next unpacker will
// also fail. This lets us avoid checks of ok until the end of a // also fail. This lets us avoid checks of ok until the end of a
...@@ -215,7 +215,7 @@ var rr_mk = map[int]*()DNS_RR { ...@@ -215,7 +215,7 @@ var rr_mk = map[int]*()DNS_RR {
// Pack a domain name s into msg[off:]. // Pack a domain name s into msg[off:].
// Domain names are a sequence of counted strings // Domain names are a sequence of counted strings
// split at the dots. They end with a zero-length string. // split at the dots. They end with a zero-length string.
func PackDomainName(s string, msg *[]byte, off int) (off1 int, ok bool) { func PackDomainName(s string, msg []byte, off int) (off1 int, ok bool) {
// Add trailing dot to canonicalize name. // Add trailing dot to canonicalize name.
if n := len(s); n == 0 || s[n-1] != '.' { if n := len(s); n == 0 || s[n-1] != '.' {
s += "."; s += ".";
...@@ -264,7 +264,7 @@ func PackDomainName(s string, msg *[]byte, off int) (off1 int, ok bool) { ...@@ -264,7 +264,7 @@ func PackDomainName(s string, msg *[]byte, off int) (off1 int, ok bool) {
// which is where the next record will start. // which is where the next record will start.
// In theory, the pointers are only allowed to jump backward. // In theory, the pointers are only allowed to jump backward.
// We let them jump anywhere and stop jumping after a while. // We let them jump anywhere and stop jumping after a while.
func UnpackDomainName(msg *[]byte, off int) (s string, off1 int, ok bool) { func UnpackDomainName(msg []byte, off int) (s string, off1 int, ok bool) {
s = ""; s = "";
ptr := 0; // number of pointers followed ptr := 0; // number of pointers followed
Loop: Loop:
...@@ -317,7 +317,7 @@ Loop: ...@@ -317,7 +317,7 @@ Loop:
// Pack a reflect.StructValue into msg. Struct members can only be uint16, uint32, string, // Pack a reflect.StructValue into msg. Struct members can only be uint16, uint32, string,
// and other (often anonymous) structs. // and other (often anonymous) structs.
func PackStructValue(val reflect.StructValue, msg *[]byte, off int) (off1 int, ok bool) { func PackStructValue(val reflect.StructValue, msg []byte, off int) (off1 int, ok bool) {
for i := 0; i < val.Len(); i++ { for i := 0; i < val.Len(); i++ {
fld := val.Field(i); fld := val.Field(i);
name, typ, tag, xxx := val.Type().(reflect.StructType).Field(i); name, typ, tag, xxx := val.Type().(reflect.StructType).Field(i);
...@@ -375,7 +375,7 @@ func PackStructValue(val reflect.StructValue, msg *[]byte, off int) (off1 int, o ...@@ -375,7 +375,7 @@ func PackStructValue(val reflect.StructValue, msg *[]byte, off int) (off1 int, o
return off, true return off, true
} }
func PackStruct(any interface{}, msg *[]byte, off int) (off1 int, ok bool) { func PackStruct(any interface{}, msg []byte, off int) (off1 int, ok bool) {
val := reflect.NewValue(any).(reflect.PtrValue).Sub().(reflect.StructValue); val := reflect.NewValue(any).(reflect.PtrValue).Sub().(reflect.StructValue);
off, ok = PackStructValue(val, msg, off); off, ok = PackStructValue(val, msg, off);
return off, ok return off, ok
...@@ -383,7 +383,7 @@ func PackStruct(any interface{}, msg *[]byte, off int) (off1 int, ok bool) { ...@@ -383,7 +383,7 @@ func PackStruct(any interface{}, msg *[]byte, off int) (off1 int, ok bool) {
// Unpack a reflect.StructValue from msg. // Unpack a reflect.StructValue from msg.
// Same restrictions as PackStructValue. // Same restrictions as PackStructValue.
func UnpackStructValue(val reflect.StructValue, msg *[]byte, off int) (off1 int, ok bool) { func UnpackStructValue(val reflect.StructValue, msg []byte, off int) (off1 int, ok bool) {
for i := 0; i < val.Len(); i++ { for i := 0; i < val.Len(); i++ {
name, typ, tag, xxx := val.Type().(reflect.StructType).Field(i); name, typ, tag, xxx := val.Type().(reflect.StructType).Field(i);
fld := val.Field(i); fld := val.Field(i);
...@@ -437,7 +437,7 @@ func UnpackStructValue(val reflect.StructValue, msg *[]byte, off int) (off1 int, ...@@ -437,7 +437,7 @@ func UnpackStructValue(val reflect.StructValue, msg *[]byte, off int) (off1 int,
return off, true return off, true
} }
func UnpackStruct(any interface{}, msg *[]byte, off int) (off1 int, ok bool) { func UnpackStruct(any interface{}, msg []byte, off int) (off1 int, ok bool) {
val := reflect.NewValue(any).(reflect.PtrValue).Sub().(reflect.StructValue); val := reflect.NewValue(any).(reflect.PtrValue).Sub().(reflect.StructValue);
off, ok = UnpackStructValue(val, msg, off); off, ok = UnpackStructValue(val, msg, off);
return off, ok return off, ok
...@@ -480,7 +480,7 @@ func PrintStruct(any interface{}) string { ...@@ -480,7 +480,7 @@ func PrintStruct(any interface{}) string {
} }
// Resource record packer. // Resource record packer.
func PackRR(rr DNS_RR, msg *[]byte, off int) (off2 int, ok bool) { func PackRR(rr DNS_RR, msg []byte, off int) (off2 int, ok bool) {
var off1 int; var off1 int;
// pack twice, once to find end of header // pack twice, once to find end of header
// and again to find end of packet. // and again to find end of packet.
...@@ -499,7 +499,7 @@ func PackRR(rr DNS_RR, msg *[]byte, off int) (off2 int, ok bool) { ...@@ -499,7 +499,7 @@ func PackRR(rr DNS_RR, msg *[]byte, off int) (off2 int, ok bool) {
} }
// Resource record unpacker. // Resource record unpacker.
func UnpackRR(msg *[]byte, off int) (rr DNS_RR, off1 int, ok bool) { func UnpackRR(msg []byte, off int) (rr DNS_RR, off1 int, ok bool) {
// unpack just the header, to find the rr type and length // unpack just the header, to find the rr type and length
var h DNS_RR_Header; var h DNS_RR_Header;
off0 := off; off0 := off;
...@@ -539,16 +539,15 @@ type DNS_Msg_Top struct { ...@@ -539,16 +539,15 @@ type DNS_Msg_Top struct {
export type DNS_Msg struct { export type DNS_Msg struct {
DNS_Msg_Top; DNS_Msg_Top;
question *[]DNS_Question; question []DNS_Question;
answer *[]DNS_RR; answer []DNS_RR;
ns *[]DNS_RR; ns []DNS_RR;
extra *[]DNS_RR; extra []DNS_RR;
} }
var no_questions = new([]DNS_Question, 0) var NIL []byte // TODO(rsc): remove
var no_rr = new([]DNS_RR, 0)
func (dns *DNS_Msg) Pack() (msg *[]byte, ok bool) { func (dns *DNS_Msg) Pack() (msg []byte, ok bool) {
var dh DNS_Header; var dh DNS_Header;
// Convert convenient DNS_Msg into wire-like DNS_Header. // Convert convenient DNS_Msg into wire-like DNS_Header.
...@@ -571,20 +570,8 @@ func (dns *DNS_Msg) Pack() (msg *[]byte, ok bool) { ...@@ -571,20 +570,8 @@ func (dns *DNS_Msg) Pack() (msg *[]byte, ok bool) {
} }
// Prepare variable sized arrays; paper over nils. // Prepare variable sized arrays; paper over nils.
var question *[]DNS_Question; var question []DNS_Question;
var answer, ns, extra *[]DNS_RR; var answer, ns, extra []DNS_RR;
if question = dns.question; question == nil {
question = no_questions
}
if answer = dns.answer; answer == nil {
answer = no_rr
}
if ns = dns.ns; ns == nil {
ns = no_rr
}
if extra = dns.extra; extra == nil {
extra = no_rr
}
dh.qdcount = uint16(len(question)); dh.qdcount = uint16(len(question));
dh.ancount = uint16(len(answer)); dh.ancount = uint16(len(answer));
...@@ -612,12 +599,12 @@ func (dns *DNS_Msg) Pack() (msg *[]byte, ok bool) { ...@@ -612,12 +599,12 @@ func (dns *DNS_Msg) Pack() (msg *[]byte, ok bool) {
off, ok = PackStruct(extra[i], msg, off); off, ok = PackStruct(extra[i], msg, off);
} }
if !ok { if !ok {
return nil, false return NIL, false
} }
return msg[0:off], true return msg[0:off], true
} }
func (dns *DNS_Msg) Unpack(msg *[]byte) bool { func (dns *DNS_Msg) Unpack(msg []byte) bool {
// Header. // Header.
var dh DNS_Header; var dh DNS_Header;
off := 0; off := 0;
...@@ -663,25 +650,25 @@ func (dns *DNS_Msg) Unpack(msg *[]byte) bool { ...@@ -663,25 +650,25 @@ func (dns *DNS_Msg) Unpack(msg *[]byte) bool {
func (dns *DNS_Msg) String() string { func (dns *DNS_Msg) String() string {
s := "DNS: "+PrintStruct(&dns.DNS_Msg_Top)+"\n"; s := "DNS: "+PrintStruct(&dns.DNS_Msg_Top)+"\n";
if dns.question != nil && len(dns.question) > 0 { if len(dns.question) > 0 {
s += "-- Questions\n"; s += "-- Questions\n";
for i := 0; i < len(dns.question); i++ { for i := 0; i < len(dns.question); i++ {
s += PrintStruct(&dns.question[i])+"\n"; s += PrintStruct(&dns.question[i])+"\n";
} }
} }
if dns.answer != nil && len(dns.answer) > 0 { if len(dns.answer) > 0 {
s += "-- Answers\n"; s += "-- Answers\n";
for i := 0; i < len(dns.answer); i++ { for i := 0; i < len(dns.answer); i++ {
s += PrintStruct(dns.answer[i])+"\n"; s += PrintStruct(dns.answer[i])+"\n";
} }
} }
if dns.ns != nil && len(dns.ns) > 0 { if len(dns.ns) > 0 {
s += "-- Name servers\n"; s += "-- Name servers\n";
for i := 0; i < len(dns.ns); i++ { for i := 0; i < len(dns.ns); i++ {
s += PrintStruct(dns.ns[i])+"\n"; s += PrintStruct(dns.ns[i])+"\n";
} }
} }
if dns.extra != nil && len(dns.extra) > 0 { if len(dns.extra) > 0 {
s += "-- Extra\n"; s += "-- Extra\n";
for i := 0; i < len(dns.extra); i++ { for i := 0; i < len(dns.extra); i++ {
s += PrintStruct(dns.extra[i])+"\n"; s += PrintStruct(dns.extra[i])+"\n";
......
...@@ -144,8 +144,8 @@ func (s *PollServer) Run() { ...@@ -144,8 +144,8 @@ func (s *PollServer) Run() {
} }
if fd == s.pr.fd { if fd == s.pr.fd {
// Drain our wakeup pipe. // Drain our wakeup pipe.
for nn, e := s.pr.Read(&scratch); nn > 0; { for nn, e := s.pr.Read(scratch); nn > 0; {
nn, e = s.pr.Read(&scratch) nn, e = s.pr.Read(scratch)
} }
// Read from channels // Read from channels
...@@ -178,7 +178,7 @@ func (s *PollServer) Run() { ...@@ -178,7 +178,7 @@ func (s *PollServer) Run() {
func (s *PollServer) Wakeup() { func (s *PollServer) Wakeup() {
var b [1]byte; var b [1]byte;
s.pw.Write(&b) s.pw.Write(b)
} }
func (s *PollServer) WaitRead(fd *FD) { func (s *PollServer) WaitRead(fd *FD) {
...@@ -232,7 +232,7 @@ func (fd *FD) Close() *os.Error { ...@@ -232,7 +232,7 @@ func (fd *FD) Close() *os.Error {
return e return e
} }
func (fd *FD) Read(p *[]byte) (n int, err *os.Error) { func (fd *FD) Read(p []byte) (n int, err *os.Error) {
if fd == nil || fd.osfd == nil { if fd == nil || fd.osfd == nil {
return -1, os.EINVAL return -1, os.EINVAL
} }
...@@ -244,7 +244,7 @@ func (fd *FD) Read(p *[]byte) (n int, err *os.Error) { ...@@ -244,7 +244,7 @@ func (fd *FD) Read(p *[]byte) (n int, err *os.Error) {
return n, err return n, err
} }
func (fd *FD) Write(p *[]byte) (n int, err *os.Error) { func (fd *FD) Write(p []byte) (n int, err *os.Error) {
if fd == nil || fd.osfd == nil { if fd == nil || fd.osfd == nil {
return -1, os.EINVAL return -1, os.EINVAL
} }
......
...@@ -15,16 +15,18 @@ import ( ...@@ -15,16 +15,18 @@ import (
export type Pollster struct { export type Pollster struct {
kq int64; kq int64;
eventbuf [10]syscall.Kevent; eventbuf [10]syscall.Kevent;
events *[]syscall.Kevent; events []syscall.Kevent;
} }
var NIL []syscall.Kevent; // TODO(rsc): remove
export func NewPollster() (p *Pollster, err *os.Error) { export func NewPollster() (p *Pollster, err *os.Error) {
p = new(Pollster); p = new(Pollster);
var e int64; var e int64;
if p.kq, e = syscall.kqueue(); e != 0 { if p.kq, e = syscall.kqueue(); e != 0 {
return nil, os.ErrnoToError(e) return nil, os.ErrnoToError(e)
} }
p.events = (&p.eventbuf)[0:0]; p.events = p.eventbuf[0:0];
return p, nil return p, nil
} }
...@@ -49,7 +51,7 @@ func (p *Pollster) AddFD(fd int64, mode int, repeat bool) *os.Error { ...@@ -49,7 +51,7 @@ func (p *Pollster) AddFD(fd int64, mode int, repeat bool) *os.Error {
ev.flags |= syscall.EV_ONESHOT 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 { if e != 0 {
return os.ErrnoToError(e) return os.ErrnoToError(e)
} }
...@@ -64,14 +66,14 @@ func (p *Pollster) AddFD(fd int64, mode int, repeat bool) *os.Error { ...@@ -64,14 +66,14 @@ func (p *Pollster) AddFD(fd int64, mode int, repeat bool) *os.Error {
func (p *Pollster) WaitFD() (fd int64, mode int, err *os.Error) { func (p *Pollster) WaitFD() (fd int64, mode int, err *os.Error) {
for len(p.events) == 0 { for len(p.events) == 0 {
nn, e := syscall.kevent(p.kq, nil, &p.eventbuf, nil); nn, e := syscall.kevent(p.kq, NIL, p.eventbuf, nil);
if e != 0 { if e != 0 {
if e == syscall.EAGAIN || e == syscall.EINTR { if e == syscall.EAGAIN || e == syscall.EINTR {
continue continue
} }
return -1, 0, os.ErrnoToError(e) return -1, 0, os.ErrnoToError(e)
} }
p.events = (&p.eventbuf)[0:nn] p.events = p.eventbuf[0:nn]
} }
ev := &p.events[0]; ev := &p.events[0];
p.events = p.events[1:len(p.events)]; p.events = p.events[1:len(p.events)];
......
...@@ -22,7 +22,7 @@ export const ( ...@@ -22,7 +22,7 @@ export const (
) )
// Make the 4 bytes into an IPv4 address (in IPv6 form) // Make the 4 bytes into an IPv4 address (in IPv6 form)
func MakeIPv4(a, b, c, d byte) *[]byte { func MakeIPv4(a, b, c, d byte) []byte {
p := new([]byte, IPv6len); p := new([]byte, IPv6len);
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
p[i] = 0 p[i] = 0
...@@ -37,7 +37,9 @@ func MakeIPv4(a, b, c, d byte) *[]byte { ...@@ -37,7 +37,9 @@ func MakeIPv4(a, b, c, d byte) *[]byte {
} }
// Well-known IP addresses // Well-known IP addresses
export var IPv4bcast, IPv4allsys, IPv4allrouter, IPv4prefix, IPallbits, IPnoaddr *[]byte export var IPv4bcast, IPv4allsys, IPv4allrouter, IPv4prefix, IPallbits, IPnoaddr []byte
var NIL []byte // TODO(rsc)
func init() { func init() {
IPv4bcast = MakeIPv4(0xff, 0xff, 0xff, 0xff); IPv4bcast = MakeIPv4(0xff, 0xff, 0xff, 0xff);
...@@ -52,7 +54,7 @@ func init() { ...@@ -52,7 +54,7 @@ func init() {
} }
// Is p all zeros? // Is p all zeros?
func IsZeros(p *[]byte) bool { func IsZeros(p []byte) bool {
for i := 0; i < len(p); i++ { for i := 0; i < len(p); i++ {
if p[i] != 0 { if p[i] != 0 {
return false return false
...@@ -63,7 +65,7 @@ func IsZeros(p *[]byte) bool { ...@@ -63,7 +65,7 @@ func IsZeros(p *[]byte) bool {
// Is p an IPv4 address (perhaps in IPv6 form)? // Is p an IPv4 address (perhaps in IPv6 form)?
// If so, return the 4-byte V4 array. // If so, return the 4-byte V4 array.
export func ToIPv4(p *[]byte) *[]byte { export func ToIPv4(p []byte) []byte {
if len(p) == IPv4len { if len(p) == IPv4len {
return p return p
} }
...@@ -73,18 +75,18 @@ export func ToIPv4(p *[]byte) *[]byte { ...@@ -73,18 +75,18 @@ export func ToIPv4(p *[]byte) *[]byte {
&& p[11] == 0xff { && p[11] == 0xff {
return p[12:16] return p[12:16]
} }
return nil return NIL
} }
// Convert p to IPv6 form. // Convert p to IPv6 form.
export func ToIPv6(p *[]byte) *[]byte { export func ToIPv6(p []byte) []byte {
if len(p) == IPv4len { if len(p) == IPv4len {
return MakeIPv4(p[0], p[1], p[2], p[3]) return MakeIPv4(p[0], p[1], p[2], p[3])
} }
if len(p) == IPv6len { if len(p) == IPv6len {
return p return p
} }
return nil return NIL
} }
// Default route masks for IPv4. // Default route masks for IPv4.
...@@ -94,9 +96,9 @@ export var ( ...@@ -94,9 +96,9 @@ export var (
ClassCMask = MakeIPv4(0xff, 0xff, 0xff, 0); ClassCMask = MakeIPv4(0xff, 0xff, 0xff, 0);
) )
export func DefaultMask(p *[]byte) *[]byte { export func DefaultMask(p []byte) []byte {
if p = ToIPv4(p); p == nil { if p = ToIPv4(p); len(p) == 0 {
return nil return NIL
} }
switch true { switch true {
case p[0] < 0x80: case p[0] < 0x80:
...@@ -106,14 +108,14 @@ export func DefaultMask(p *[]byte) *[]byte { ...@@ -106,14 +108,14 @@ export func DefaultMask(p *[]byte) *[]byte {
default: default:
return ClassCMask; return ClassCMask;
} }
return nil; // not reached return NIL; // not reached
} }
// Apply mask to ip, returning new address. // Apply mask to ip, returning new address.
export func Mask(ip *[]byte, mask *[]byte) *[]byte { export func Mask(ip []byte, mask []byte) []byte {
n := len(ip); n := len(ip);
if n != len(mask) { if n != len(mask) {
return nil return NIL
} }
out := new([]byte, n); out := new([]byte, n);
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
...@@ -136,8 +138,8 @@ func itod(i uint) string { ...@@ -136,8 +138,8 @@ func itod(i uint) string {
b[bp] = byte(i%10) + '0' b[bp] = byte(i%10) + '0'
} }
// return string(b[bp:len(b)]) return string(b[bp:len(b)])
return string((&b)[bp:len(b)]) // return string((&b)[bp:len(b)])
} }
// Convert i to hexadecimal string. // Convert i to hexadecimal string.
...@@ -154,14 +156,14 @@ func itox(i uint) string { ...@@ -154,14 +156,14 @@ func itox(i uint) string {
b[bp] = "0123456789abcdef"[byte(i%16)] b[bp] = "0123456789abcdef"[byte(i%16)]
} }
// return string(b[bp:len(b)]) return string(b[bp:len(b)])
return string((&b)[bp:len(b)]) // return string((&b)[bp:len(b)])
} }
// Convert IP address to string. // Convert IP address to string.
export func IPToString(p *[]byte) string { export func IPToString(p []byte) string {
// If IPv4, use dotted notation. // If IPv4, use dotted notation.
if p4 := ToIPv4(p); p4 != nil { if p4 := ToIPv4(p); len(p4) == 4 {
return itod(uint(p4[0]))+"." return itod(uint(p4[0]))+"."
+itod(uint(p4[1]))+"." +itod(uint(p4[1]))+"."
+itod(uint(p4[2]))+"." +itod(uint(p4[2]))+"."
...@@ -204,7 +206,7 @@ export func IPToString(p *[]byte) string { ...@@ -204,7 +206,7 @@ export func IPToString(p *[]byte) string {
// If mask is a sequence of 1 bits followed by 0 bits, // If mask is a sequence of 1 bits followed by 0 bits,
// return the number of 1 bits. // return the number of 1 bits.
func SimpleMaskLength(mask *[]byte) int { func SimpleMaskLength(mask []byte) int {
var i int; var i int;
for i = 0; i < len(mask); i++ { for i = 0; i < len(mask); i++ {
if mask[i] != 0xFF { if mask[i] != 0xFF {
...@@ -228,7 +230,7 @@ func SimpleMaskLength(mask *[]byte) int { ...@@ -228,7 +230,7 @@ func SimpleMaskLength(mask *[]byte) int {
return n return n
} }
export func MaskToString(mask *[]byte) string { export func MaskToString(mask []byte) string {
switch len(mask) { switch len(mask) {
case 4: case 4:
n := SimpleMaskLength(mask); n := SimpleMaskLength(mask);
...@@ -245,13 +247,13 @@ export func MaskToString(mask *[]byte) string { ...@@ -245,13 +247,13 @@ export func MaskToString(mask *[]byte) string {
} }
// Parse IPv4 address (d.d.d.d). // Parse IPv4 address (d.d.d.d).
func ParseIPv4(s string) *[]byte { func ParseIPv4(s string) []byte {
var p [IPv4len]byte; var p [IPv4len]byte;
i := 0; i := 0;
for j := 0; j < IPv4len; j++ { for j := 0; j < IPv4len; j++ {
if j > 0 { if j > 0 {
if s[i] != '.' { if s[i] != '.' {
return nil return NIL
} }
i++; i++;
} }
...@@ -261,12 +263,12 @@ func ParseIPv4(s string) *[]byte { ...@@ -261,12 +263,12 @@ func ParseIPv4(s string) *[]byte {
) )
n, i, ok = Dtoi(s, i); n, i, ok = Dtoi(s, i);
if !ok || n > 0xFF { if !ok || n > 0xFF {
return nil return NIL
} }
p[j] = byte(n) p[j] = byte(n)
} }
if i != len(s) { if i != len(s) {
return nil return NIL
} }
return MakeIPv4(p[0], p[1], p[2], p[3]) return MakeIPv4(p[0], p[1], p[2], p[3])
} }
...@@ -279,7 +281,7 @@ func ParseIPv4(s string) *[]byte { ...@@ -279,7 +281,7 @@ func ParseIPv4(s string) *[]byte {
// * A run of zeros can be replaced with "::". // * A run of zeros can be replaced with "::".
// * The last 32 bits can be in IPv4 form. // * The last 32 bits can be in IPv4 form.
// Thus, ::ffff:1.2.3.4 is the IPv4 address 1.2.3.4. // Thus, ::ffff:1.2.3.4 is the IPv4 address 1.2.3.4.
func ParseIPv6(s string) *[]byte { func ParseIPv6(s string) []byte {
p := new([]byte, 16); p := new([]byte, 16);
ellipsis := -1; // position of ellipsis in p ellipsis := -1; // position of ellipsis in p
i := 0; // index in string s i := 0; // index in string s
...@@ -300,22 +302,22 @@ L: for j < IPv6len { ...@@ -300,22 +302,22 @@ L: for j < IPv6len {
// Hex number. // Hex number.
n, i1, ok := Xtoi(s, i); n, i1, ok := Xtoi(s, i);
if !ok || n > 0xFFFF { if !ok || n > 0xFFFF {
return nil return NIL
} }
// If followed by dot, might be in trailing IPv4. // If followed by dot, might be in trailing IPv4.
if i1 < len(s) && s[i1] == '.' { if i1 < len(s) && s[i1] == '.' {
if ellipsis < 0 && j != IPv6len - IPv4len { if ellipsis < 0 && j != IPv6len - IPv4len {
// Not the right place. // Not the right place.
return nil return NIL
} }
if j+IPv4len > IPv6len { if j+IPv4len > IPv6len {
// Not enough room. // Not enough room.
return nil return NIL
} }
p4 := ParseIPv4(s[i:len(s)]); p4 := ParseIPv4(s[i:len(s)]);
if p4 == nil { if len(p4) == 0 {
return nil return NIL
} }
// BUG: p[j:j+4] = p4 // BUG: p[j:j+4] = p4
p[j] = p4[12]; p[j] = p4[12];
...@@ -340,14 +342,14 @@ L: for j < IPv6len { ...@@ -340,14 +342,14 @@ L: for j < IPv6len {
// Otherwise must be followed by colon and more. // Otherwise must be followed by colon and more.
if s[i] != ':' && i+1 == len(s) { if s[i] != ':' && i+1 == len(s) {
return nil return NIL
} }
i++; i++;
// Look for ellipsis. // Look for ellipsis.
if s[i] == ':' { if s[i] == ':' {
if ellipsis >= 0 { // already have one if ellipsis >= 0 { // already have one
return nil return NIL
} }
ellipsis = j; ellipsis = j;
if i++; i == len(s) { // can be at end if i++; i == len(s) { // can be at end
...@@ -358,13 +360,13 @@ L: for j < IPv6len { ...@@ -358,13 +360,13 @@ L: for j < IPv6len {
// Must have used entire string. // Must have used entire string.
if i != len(s) { if i != len(s) {
return nil return NIL
} }
// If didn't parse enough, expand ellipsis. // If didn't parse enough, expand ellipsis.
if j < IPv6len { if j < IPv6len {
if ellipsis < 0 { if ellipsis < 0 {
return nil return NIL
} }
n := IPv6len - j; n := IPv6len - j;
for k := j-1; k >= ellipsis; k-- { for k := j-1; k >= ellipsis; k-- {
...@@ -377,9 +379,9 @@ L: for j < IPv6len { ...@@ -377,9 +379,9 @@ L: for j < IPv6len {
return p return p
} }
export func ParseIP(s string) *[]byte { export func ParseIP(s string) []byte {
p := ParseIPv4(s); p := ParseIPv4(s);
if p != nil { if len(p) != 0 {
return p return p
} }
return ParseIPv6(s) return ParseIPv6(s)
......
...@@ -9,11 +9,11 @@ import ( ...@@ -9,11 +9,11 @@ import (
"testing" "testing"
) )
func IPv4(a, b, c, d byte) *[]byte { func IPv4(a, b, c, d byte) []byte {
return &[]byte{ 0,0,0,0, 0,0,0,0, 0,0,255,255, a,b,c,d } return []byte{ 0,0,0,0, 0,0,0,0, 0,0,255,255, a,b,c,d }
} }
func Equal(a *[]byte, b *[]byte) bool { func Equal(a []byte, b []byte) bool {
if a == b { if a == b {
return true return true
} }
...@@ -30,7 +30,7 @@ func Equal(a *[]byte, b *[]byte) bool { ...@@ -30,7 +30,7 @@ func Equal(a *[]byte, b *[]byte) bool {
type ParseIPTest struct { type ParseIPTest struct {
in string; in string;
out *[]byte; out []byte;
} }
var parseiptests = []ParseIPTest { var parseiptests = []ParseIPTest {
ParseIPTest{"127.0.1.2", IPv4(127, 0, 1, 2)}, ParseIPTest{"127.0.1.2", IPv4(127, 0, 1, 2)},
...@@ -39,7 +39,7 @@ var parseiptests = []ParseIPTest { ...@@ -39,7 +39,7 @@ var parseiptests = []ParseIPTest {
ParseIPTest{"abc", nil}, ParseIPTest{"abc", nil},
ParseIPTest{"::ffff:127.0.0.1", IPv4(127, 0, 0, 1)}, ParseIPTest{"::ffff:127.0.0.1", IPv4(127, 0, 0, 1)},
ParseIPTest{"2001:4860:0:2001::68", ParseIPTest{"2001:4860:0:2001::68",
&[]byte{0x20,0x01, 0x48,0x60, 0,0, 0x20,0x01, 0,0, 0,0, 0,0, 0x00,0x68}}, []byte{0x20,0x01, 0x48,0x60, 0,0, 0x20,0x01, 0,0, 0,0, 0,0, 0x00,0x68}},
ParseIPTest{"::ffff:4a7d:1363", IPv4(74, 125, 19, 99)}, ParseIPTest{"::ffff:4a7d:1363", IPv4(74, 125, 19, 99)},
} }
......
...@@ -21,7 +21,7 @@ export var ( ...@@ -21,7 +21,7 @@ export var (
UnknownSocketFamily = os.NewError("unknown socket family"); UnknownSocketFamily = os.NewError("unknown socket family");
) )
export func LookupHost(name string) (name1 string, addrs *[]string, err *os.Error) export func LookupHost(name string) (name1 string, addrs []string, err *os.Error)
// Split "host:port" into "host" and "port". // Split "host:port" into "host" and "port".
// Host cannot contain colons unless it is bracketed. // Host cannot contain colons unless it is bracketed.
...@@ -62,31 +62,33 @@ func JoinHostPort(host, port string) string { ...@@ -62,31 +62,33 @@ func JoinHostPort(host, port string) string {
return host + ":" + port return host + ":" + port
} }
var NIL []byte
// Convert "host:port" into IP address and port. // Convert "host:port" into IP address and port.
// For now, host and port must be numeric literals. // For now, host and port must be numeric literals.
// Eventually, we'll have name resolution. // Eventually, we'll have name resolution.
func HostPortToIP(net string, hostport string) (ip *[]byte, iport int, err *os.Error) { func HostPortToIP(net string, hostport string) (ip []byte, iport int, err *os.Error) {
var host, port string; var host, port string;
host, port, err = SplitHostPort(hostport); host, port, err = SplitHostPort(hostport);
if err != nil { if err != nil {
return nil, 0, err return NIL, 0, err
} }
// Try as an IP address. // Try as an IP address.
addr := ParseIP(host); addr := ParseIP(host);
if addr == nil { if len(addr) == 0 {
// Not an IP address. Try as a DNS name. // Not an IP address. Try as a DNS name.
hostname, addrs, err := LookupHost(host); hostname, addrs, err := LookupHost(host);
if err != nil { if err != nil {
return nil, 0, err return NIL, 0, err
} }
if len(addrs) == 0 { if len(addrs) == 0 {
return nil, 0, UnknownHost return NIL, 0, UnknownHost
} }
addr = ParseIP(addrs[0]); addr = ParseIP(addrs[0]);
if addr == nil { if len(addr) == 0 {
// should not happen // should not happen
return nil, 0, BadAddress return NIL, 0, BadAddress
} }
} }
...@@ -94,11 +96,11 @@ func HostPortToIP(net string, hostport string) (ip *[]byte, iport int, err *os.E ...@@ -94,11 +96,11 @@ func HostPortToIP(net string, hostport string) (ip *[]byte, iport int, err *os.E
if !ok || i != len(port) { if !ok || i != len(port) {
p, ok = LookupPort(net, port); p, ok = LookupPort(net, port);
if !ok { if !ok {
return nil, 0, UnknownPort return NIL, 0, UnknownPort
} }
} }
if p < 0 || p > 0xFFFF { if p < 0 || p > 0xFFFF {
return nil, 0, BadAddress return NIL, 0, BadAddress
} }
return addr, p, nil return addr, p, nil
...@@ -178,17 +180,17 @@ func (c *ConnBase) FD() int64 { ...@@ -178,17 +180,17 @@ func (c *ConnBase) FD() int64 {
return c.fd.fd return c.fd.fd
} }
func (c *ConnBase) Read(b *[]byte) (n int, err *os.Error) { func (c *ConnBase) Read(b []byte) (n int, err *os.Error) {
n, err = c.fd.Read(b); n, err = c.fd.Read(b);
return n, err return n, err
} }
func (c *ConnBase) Write(b *[]byte) (n int, err *os.Error) { func (c *ConnBase) Write(b []byte) (n int, err *os.Error) {
n, err = c.fd.Write(b); n, err = c.fd.Write(b);
return n, err return n, err
} }
func (c *ConnBase) ReadFrom(b *[]byte) (n int, raddr string, err *os.Error) { func (c *ConnBase) ReadFrom(b []byte) (n int, raddr string, err *os.Error) {
if c == nil { if c == nil {
return -1, "", os.EINVAL return -1, "", os.EINVAL
} }
...@@ -196,7 +198,7 @@ func (c *ConnBase) ReadFrom(b *[]byte) (n int, raddr string, err *os.Error) { ...@@ -196,7 +198,7 @@ func (c *ConnBase) ReadFrom(b *[]byte) (n int, raddr string, err *os.Error) {
return n, c.raddr, err return n, c.raddr, err
} }
func (c *ConnBase) WriteTo(raddr string, b *[]byte) (n int, err *os.Error) { func (c *ConnBase) WriteTo(raddr string, b []byte) (n int, err *os.Error) {
if c == nil { if c == nil {
return -1, os.EINVAL return -1, os.EINVAL
} }
...@@ -281,7 +283,7 @@ const PreferIPv4 = false ...@@ -281,7 +283,7 @@ const PreferIPv4 = false
func InternetSocket(net, laddr, raddr string, proto int64) (fd *FD, err *os.Error) { func InternetSocket(net, laddr, raddr string, proto int64) (fd *FD, err *os.Error) {
// Parse addresses (unless they are empty). // Parse addresses (unless they are empty).
var lip, rip *[]byte; var lip, rip []byte;
var lport, rport int; var lport, rport int;
var lerr, rerr *os.Error; var lerr, rerr *os.Error;
...@@ -309,16 +311,14 @@ func InternetSocket(net, laddr, raddr string, proto int64) (fd *FD, err *os.Erro ...@@ -309,16 +311,14 @@ func InternetSocket(net, laddr, raddr string, proto int64) (fd *FD, err *os.Erro
default: default:
// Otherwise, guess. // Otherwise, guess.
// If the addresses are IPv4 and we prefer IPv4, use 4; else 6. // If the addresses are IPv4 and we prefer IPv4, use 4; else 6.
if PreferIPv4 if PreferIPv4 && len(ToIPv4(lip)) != 0 && len(ToIPv4(rip)) != 0 {
&& (lip == nil || ToIPv4(lip) != nil)
&& (rip == nil || ToIPv4(rip) != nil) {
vers = 4 vers = 4
} else { } else {
vers = 6 vers = 6
} }
} }
var cvt *(addr *[]byte, port int) (sa *syscall.Sockaddr, err *os.Error); var cvt *(addr []byte, port int) (sa *syscall.Sockaddr, err *os.Error);
var family int64; var family int64;
if vers == 4 { if vers == 4 {
cvt = &IPv4ToSockaddr; cvt = &IPv4ToSockaddr;
...@@ -329,13 +329,13 @@ func InternetSocket(net, laddr, raddr string, proto int64) (fd *FD, err *os.Erro ...@@ -329,13 +329,13 @@ func InternetSocket(net, laddr, raddr string, proto int64) (fd *FD, err *os.Erro
} }
var la, ra *syscall.Sockaddr; var la, ra *syscall.Sockaddr;
if lip != nil { if len(lip) != 0 {
la, lerr = cvt(lip, lport); la, lerr = cvt(lip, lport);
if lerr != nil { if lerr != nil {
return nil, lerr return nil, lerr
} }
} }
if rip != nil { if len(rip) != 0 {
ra, rerr = cvt(rip, rport); ra, rerr = cvt(rip, rport);
if rerr != nil { if rerr != nil {
return nil, rerr return nil, rerr
...@@ -414,10 +414,10 @@ export func DialUDP(net, laddr, raddr string) (c *ConnUDP, err *os.Error) { ...@@ -414,10 +414,10 @@ export func DialUDP(net, laddr, raddr string) (c *ConnUDP, err *os.Error) {
export type Conn interface { export type Conn interface {
Read(b *[]byte) (n int, err *os.Error); Read(b []byte) (n int, err *os.Error);
Write(b *[]byte) (n int, err *os.Error); Write(b []byte) (n int, err *os.Error);
ReadFrom(b *[]byte) (n int, addr string, err *os.Error); ReadFrom(b []byte) (n int, addr string, err *os.Error);
WriteTo(addr string, b *[]byte) (n int, err *os.Error); WriteTo(addr string, b []byte) (n int, err *os.Error);
Close() *os.Error; Close() *os.Error;
SetReadBuffer(bytes int) *os.Error; SetReadBuffer(bytes int) *os.Error;
SetWriteBuffer(bytes int) *os.Error; SetWriteBuffer(bytes int) *os.Error;
......
...@@ -11,9 +11,9 @@ import ( ...@@ -11,9 +11,9 @@ import (
"unsafe"; "unsafe";
) )
export func IPv4ToSockaddr(p *[]byte, port int) (sa1 *syscall.Sockaddr, err *os.Error) { export func IPv4ToSockaddr(p []byte, port int) (sa1 *syscall.Sockaddr, err *os.Error) {
p = ToIPv4(p); p = ToIPv4(p);
if p == nil || port < 0 || port > 0xFFFF { if len(p) == 0 || port < 0 || port > 0xFFFF {
return nil, os.EINVAL return nil, os.EINVAL
} }
sa := new(syscall.SockaddrInet4); sa := new(syscall.SockaddrInet4);
...@@ -27,9 +27,9 @@ export func IPv4ToSockaddr(p *[]byte, port int) (sa1 *syscall.Sockaddr, err *os. ...@@ -27,9 +27,9 @@ export func IPv4ToSockaddr(p *[]byte, port int) (sa1 *syscall.Sockaddr, err *os.
return unsafe.pointer(sa).(*syscall.Sockaddr), nil return unsafe.pointer(sa).(*syscall.Sockaddr), nil
} }
export func IPv6ToSockaddr(p *[]byte, port int) (sa1 *syscall.Sockaddr, err *os.Error) { export func IPv6ToSockaddr(p []byte, port int) (sa1 *syscall.Sockaddr, err *os.Error) {
p = ToIPv6(p); p = ToIPv6(p);
if p == nil || port < 0 || port > 0xFFFF { if len(p) == 0 || port < 0 || port > 0xFFFF {
return nil, os.EINVAL return nil, os.EINVAL
} }
sa := new(syscall.SockaddrInet6); sa := new(syscall.SockaddrInet6);
...@@ -43,26 +43,28 @@ export func IPv6ToSockaddr(p *[]byte, port int) (sa1 *syscall.Sockaddr, err *os. ...@@ -43,26 +43,28 @@ export func IPv6ToSockaddr(p *[]byte, port int) (sa1 *syscall.Sockaddr, err *os.
return unsafe.pointer(sa).(*syscall.Sockaddr), nil return unsafe.pointer(sa).(*syscall.Sockaddr), nil
} }
export func SockaddrToIP(sa1 *syscall.Sockaddr) (p *[]byte, port int, err *os.Error) { var NIL []byte // TODO(rsc)
export func SockaddrToIP(sa1 *syscall.Sockaddr) (p []byte, port int, err *os.Error) {
switch sa1.family { switch sa1.family {
case syscall.AF_INET: case syscall.AF_INET:
sa := unsafe.pointer(sa1).(*syscall.SockaddrInet4); sa := unsafe.pointer(sa1).(*syscall.SockaddrInet4);
a := ToIPv6(&sa.addr); a := ToIPv6(sa.addr);
if a == nil { if len(a) == 0 {
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 := unsafe.pointer(sa1).(*syscall.SockaddrInet6); sa := unsafe.pointer(sa1).(*syscall.SockaddrInet6);
a := ToIPv6(&sa.addr); a := ToIPv6(sa.addr);
if a == nil { if len(a) == 0 {
return nil, 0, os.EINVAL return NIL, 0, os.EINVAL
} }
return a, int(sa.port[0])<<8 + int(sa.port[1]), nil; return NIL, int(sa.port[0])<<8 + int(sa.port[1]), nil;
default: default:
return nil, 0, os.EINVAL return NIL, 0, os.EINVAL
} }
return nil, 0, nil // not reached return NIL, 0, nil // not reached
} }
export func ListenBacklog() int64 { export func ListenBacklog() int64 {
......
...@@ -11,7 +11,7 @@ import ( ...@@ -11,7 +11,7 @@ import (
"unsafe"; "unsafe";
) )
export func IPv4ToSockaddr(p *[]byte, port int) (sa1 *syscall.Sockaddr, err *os.Error) { export func IPv4ToSockaddr(p []byte, port int) (sa1 *syscall.Sockaddr, err *os.Error) {
p = ToIPv4(p); p = ToIPv4(p);
if p == nil || port < 0 || port > 0xFFFF { if p == nil || port < 0 || port > 0xFFFF {
return nil, os.EINVAL return nil, os.EINVAL
...@@ -28,7 +28,7 @@ export func IPv4ToSockaddr(p *[]byte, port int) (sa1 *syscall.Sockaddr, err *os. ...@@ -28,7 +28,7 @@ export func IPv4ToSockaddr(p *[]byte, port int) (sa1 *syscall.Sockaddr, err *os.
var IPv6zero [16]byte; var IPv6zero [16]byte;
export func IPv6ToSockaddr(p *[]byte, port int) (sa1 *syscall.Sockaddr, err *os.Error) { export func IPv6ToSockaddr(p []byte, port int) (sa1 *syscall.Sockaddr, err *os.Error) {
p = ToIPv6(p); p = ToIPv6(p);
if p == nil || port < 0 || port > 0xFFFF { if p == nil || port < 0 || port > 0xFFFF {
return nil, os.EINVAL return nil, os.EINVAL
...@@ -51,7 +51,7 @@ export func IPv6ToSockaddr(p *[]byte, port int) (sa1 *syscall.Sockaddr, err *os. ...@@ -51,7 +51,7 @@ export func IPv6ToSockaddr(p *[]byte, port int) (sa1 *syscall.Sockaddr, err *os.
return unsafe.pointer(sa).(*syscall.Sockaddr), nil return unsafe.pointer(sa).(*syscall.Sockaddr), nil
} }
export func SockaddrToIP(sa1 *syscall.Sockaddr) (p *[]byte, port int, err *os.Error) { export func SockaddrToIP(sa1 *syscall.Sockaddr) (p []byte, port int, err *os.Error) {
switch sa1.family { switch sa1.family {
case syscall.AF_INET: case syscall.AF_INET:
sa := unsafe.pointer(sa1).(*syscall.SockaddrInet4); sa := unsafe.pointer(sa1).(*syscall.SockaddrInet4);
......
...@@ -14,7 +14,7 @@ import ( ...@@ -14,7 +14,7 @@ import (
package type File struct { package type File struct {
fd *os.FD; fd *os.FD;
data *[]byte; data []byte;
} }
func (f *File) Close() { func (f *File) Close() {
...@@ -84,7 +84,7 @@ package func CountAnyByte(s string, t string) int { ...@@ -84,7 +84,7 @@ package func CountAnyByte(s string, t string) int {
} }
// Split s at any bytes in t. // Split s at any bytes in t.
package func SplitAtBytes(s string, t string) *[]string { package func SplitAtBytes(s string, t string) []string {
a := new([]string, 1+CountAnyByte(s, t)); a := new([]string, 1+CountAnyByte(s, t));
n := 0; n := 0;
last := 0; last := 0;
...@@ -104,7 +104,7 @@ package func SplitAtBytes(s string, t string) *[]string { ...@@ -104,7 +104,7 @@ package func SplitAtBytes(s string, t string) *[]string {
return a[0:n]; return a[0:n];
} }
package func GetFields(s string) *[]string { package func GetFields(s string) []string {
return SplitAtBytes(s, " \r\t\n"); return SplitAtBytes(s, " \r\t\n");
} }
......
...@@ -15,11 +15,11 @@ func Echo(fd io.ReadWrite, done *chan<- int) { ...@@ -15,11 +15,11 @@ func Echo(fd io.ReadWrite, done *chan<- int) {
var buf [1024]byte; var buf [1024]byte;
for { for {
n, err := fd.Read(&buf); n, err := fd.Read(buf);
if err != nil || n == 0 { if err != nil || n == 0 {
break; break;
} }
fd.Write((&buf)[0:n]) fd.Write(buf[0:n])
} }
done <- 1 done <- 1
} }
...@@ -58,7 +58,7 @@ func Connect(t *testing.T, network, addr string) { ...@@ -58,7 +58,7 @@ func Connect(t *testing.T, network, addr string) {
t.Fatalf("fd.Write(%q) = %d, %v", b, n, errno); t.Fatalf("fd.Write(%q) = %d, %v", b, n, errno);
} }
n, errno = fd.Read(&b1); n, errno = fd.Read(b1);
if n != len(b) { if n != len(b) {
t.Fatalf("fd.Read() = %d, %v", n, errno); t.Fatalf("fd.Read() = %d, %v", n, errno);
} }
......
...@@ -53,7 +53,7 @@ func (fd *FD) Close() *Error { ...@@ -53,7 +53,7 @@ func (fd *FD) Close() *Error {
return ErrnoToError(e) return ErrnoToError(e)
} }
func (fd *FD) Read(b *[]byte) (ret int, err *Error) { func (fd *FD) Read(b []byte) (ret int, err *Error) {
if fd == nil { if fd == nil {
return 0, EINVAL return 0, EINVAL
} }
...@@ -67,7 +67,7 @@ func (fd *FD) Read(b *[]byte) (ret int, err *Error) { ...@@ -67,7 +67,7 @@ func (fd *FD) Read(b *[]byte) (ret int, err *Error) {
return int(r), ErrnoToError(e) return int(r), ErrnoToError(e)
} }
func (fd *FD) Write(b *[]byte) (ret int, err *Error) { func (fd *FD) Write(b []byte) (ret int, err *Error) {
if fd == nil { if fd == nil {
return 0, EINVAL return 0, EINVAL
} }
......
...@@ -164,7 +164,7 @@ frand() float ...@@ -164,7 +164,7 @@ frand() float
} }
export func export func
perm(n int) *[]int perm(n int) []int
{ {
m := new([]int, n); m := new([]int, n);
for i:=0; i<n; i++ { for i:=0; i<n; i++ {
......
...@@ -177,23 +177,23 @@ export func TestAll(tt *testing.T) { // TODO(r): wrap up better ...@@ -177,23 +177,23 @@ export func TestAll(tt *testing.T) { // TODO(r): wrap up better
value := reflect.NewValue(tmp); value := reflect.NewValue(tmp);
assert(reflect.ValueToString(value), "*reflect.C·all_test(@)"); assert(reflect.ValueToString(value), "*reflect.C·all_test(@)");
} }
{ // {
type A [10]int; // type A [10]int;
var tmp A = A{1,2,3,4,5,6,7,8,9,10}; // var tmp A = A{1,2,3,4,5,6,7,8,9,10};
value := reflect.NewValue(&tmp); // value := reflect.NewValue(&tmp);
assert(reflect.ValueToString(value.(reflect.PtrValue).Sub()), "reflect.A·all_test{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}"); // assert(reflect.ValueToString(value.(reflect.PtrValue).Sub()), "reflect.A·all_test{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}");
value.(reflect.PtrValue).Sub().(reflect.ArrayValue).Elem(4).(reflect.IntValue).Set(123); // value.(reflect.PtrValue).Sub().(reflect.ArrayValue).Elem(4).(reflect.IntValue).Set(123);
assert(reflect.ValueToString(value.(reflect.PtrValue).Sub()), "reflect.A·all_test{1, 2, 3, 4, 123, 6, 7, 8, 9, 10}"); // assert(reflect.ValueToString(value.(reflect.PtrValue).Sub()), "reflect.A·all_test{1, 2, 3, 4, 123, 6, 7, 8, 9, 10}");
} // }
{ // {
type AA []int; // type AA []int;
tmp1 := [10]int{1,2,3,4,5,6,7,8,9,10}; // TODO: should not be necessary to use tmp1 // tmp1 := [10]int{1,2,3,4,5,6,7,8,9,10}; // TODO: should not be necessary to use tmp1
var tmp *AA = &tmp1; // var tmp *AA = &tmp1;
value := reflect.NewValue(tmp); // value := reflect.NewValue(tmp);
assert(reflect.ValueToString(value.(reflect.PtrValue).Sub()), "reflect.AA·all_test{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}"); // assert(reflect.ValueToString(value.(reflect.PtrValue).Sub()), "reflect.AA·all_test{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}");
value.(reflect.PtrValue).Sub().(reflect.ArrayValue).Elem(4).(reflect.IntValue).Set(123); // value.(reflect.PtrValue).Sub().(reflect.ArrayValue).Elem(4).(reflect.IntValue).Set(123);
assert(reflect.ValueToString(value.(reflect.PtrValue).Sub()), "reflect.AA·all_test{1, 2, 3, 4, 123, 6, 7, 8, 9, 10}"); // assert(reflect.ValueToString(value.(reflect.PtrValue).Sub()), "reflect.AA·all_test{1, 2, 3, 4, 123, 6, 7, 8, 9, 10}");
} // }
{ {
var ip *int32; var ip *int32;
...@@ -264,18 +264,19 @@ export func TestAll(tt *testing.T) { // TODO(r): wrap up better ...@@ -264,18 +264,19 @@ export func TestAll(tt *testing.T) { // TODO(r): wrap up better
assert(ct.Elem().String(), "string"); assert(ct.Elem().String(), "string");
// make sure tag strings are not part of element type // make sure tag strings are not part of element type
t = reflect.ParseTypeString("", "struct{d *[]uint32 \"TAG\"}"); t = reflect.ParseTypeString("", "struct{d []uint32 \"TAG\"}");
st = t.(reflect.StructType); st = t.(reflect.StructType);
name, typ, tag, offset = st.Field(0); name, typ, tag, offset = st.Field(0);
assert(typ.String(), "*[]uint32"); assert(typ.String(), "[]uint32");
t = reflect.ParseTypeString("", "[]int32"); t = reflect.ParseTypeString("", "[]int32");
v := reflect.NewOpenArrayValue(t, 5, 10); v := reflect.NewOpenArrayValue(t, 5, 10);
t1 := reflect.ParseTypeString("", "*[]int32"); t1 := reflect.ParseTypeString("", "*[]int32");
v1 := reflect.NewInitValue(t1); v1 := reflect.NewInitValue(t1);
if v1 == nil { panic("V1 is nil"); }
v1.(reflect.PtrValue).SetSub(v); v1.(reflect.PtrValue).SetSub(v);
a := v1.Interface().(*[]int32); a := v1.Interface().(*[]int32);
println(a, len(a), cap(a)); println(&a, len(a), cap(a));
for i := 0; i < len(a); i++ { for i := 0; i < len(a); i++ {
v.Elem(i).(reflect.Int32Value).Set(int32(i)); v.Elem(i).(reflect.Int32Value).Set(int32(i));
} }
...@@ -296,33 +297,35 @@ export func TestInterfaceGet(t *testing.T) { ...@@ -296,33 +297,35 @@ export func TestInterfaceGet(t *testing.T) {
} }
export func TestCopyArray(t *testing.T) { export func TestCopyArray(t *testing.T) {
a := &[]int{ 1, 2, 3, 4, 10, 9, 8, 7 }; a := []int{ 1, 2, 3, 4, 10, 9, 8, 7 };
b := &[]int{ 11, 22, 33, 44, 1010, 99, 88, 77, 66, 55, 44 }; b := []int{ 11, 22, 33, 44, 1010, 99, 88, 77, 66, 55, 44 };
c := &[]int{ 11, 22, 33, 44, 1010, 99, 88, 77, 66, 55, 44 }; c := []int{ 11, 22, 33, 44, 1010, 99, 88, 77, 66, 55, 44 };
va := NewValue(a); va := NewValue(&a);
vb := NewValue(b); vb := NewValue(&b);
for i := 0; i < len(b); i++ { for i := 0; i < len(b); i++ {
if b[i] != c[i] { if b[i] != c[i] {
t.Fatalf("b != c before test"); t.Fatalf("b != c before test");
} }
} }
for tocopy := 5; tocopy <= 6; tocopy++ { for tocopy := 1; tocopy <= 7; tocopy++ {
CopyArray(vb.(PtrValue).Sub(), va.(PtrValue).Sub(), tocopy); CopyArray(vb.(PtrValue).Sub(), va.(PtrValue).Sub(), tocopy);
for i := 0; i < tocopy; i++ { for i := 0; i < tocopy; i++ {
if a[i] != b[i] { if a[i] != b[i] {
t.Errorf("tocopy=%d a[%d]=%d, b[%d]=%d", t.Errorf("1 tocopy=%d a[%d]=%d, b[%d]=%d",
tocopy, i, a[i], i, b[i]); tocopy, i, a[i], i, b[i]);
} }
} }
for i := tocopy; i < len(b); i++ { for i := tocopy; i < len(b); i++ {
if b[i] != c[i] { if b[i] != c[i] {
if i < len(a) { if i < len(a) {
t.Errorf("tocopy=%d a[%d]=%d, b[%d]=%d, c[%d]=%d", t.Errorf("2 tocopy=%d a[%d]=%d, b[%d]=%d, c[%d]=%d",
tocopy, i, a[i], i, b[i], i, c[i]); tocopy, i, a[i], i, b[i], i, c[i]);
} else { } else {
t.Errorf("tocopy=%d b[%d]=%d, c[%d]=%d", t.Errorf("3 tocopy=%d b[%d]=%d, c[%d]=%d",
tocopy, i, b[i], i, c[i]); tocopy, i, b[i], i, c[i]);
} }
} else {
t.Logf("tocopy=%d elem %d is okay\n", tocopy, i);
} }
} }
} }
......
...@@ -124,6 +124,7 @@ type StubType struct { ...@@ -124,6 +124,7 @@ type StubType struct {
} }
func NewStubType(name string, typ Type) *StubType { func NewStubType(name string, typ Type) *StubType {
if typ == nil && len(name) > 0 && name[0] == '*' { panicln("NewStubType", name, typ) }
return &StubType{name, typ} return &StubType{name, typ}
} }
...@@ -275,10 +276,10 @@ type Field struct { ...@@ -275,10 +276,10 @@ type Field struct {
type StructTypeStruct struct { type StructTypeStruct struct {
Common; Common;
field *[]Field; field []Field;
} }
func NewStructTypeStruct(name, typestring string, field *[]Field) *StructTypeStruct { func NewStructTypeStruct(name, typestring string, field []Field) *StructTypeStruct {
return &StructTypeStruct{ Common{StructKind, typestring, name, 0}, field} return &StructTypeStruct{ Common{StructKind, typestring, name, 0}, field}
} }
...@@ -327,10 +328,10 @@ export type InterfaceType interface { ...@@ -327,10 +328,10 @@ export type InterfaceType interface {
type InterfaceTypeStruct struct { type InterfaceTypeStruct struct {
Common; Common;
field *[]Field; field []Field;
} }
func NewInterfaceTypeStruct(name, typestring string, field *[]Field) *InterfaceTypeStruct { func NewInterfaceTypeStruct(name, typestring string, field []Field) *InterfaceTypeStruct {
return &InterfaceTypeStruct{ Common{InterfaceKind, typestring, name, interfacesize}, field } return &InterfaceTypeStruct{ Common{InterfaceKind, typestring, name, interfacesize}, field }
} }
...@@ -683,7 +684,7 @@ func (p *Parser) Chan(name string, tokstart, dir int) *StubType { ...@@ -683,7 +684,7 @@ func (p *Parser) Chan(name string, tokstart, dir int) *StubType {
} }
// Parse array of fields for struct, interface, and func arguments // Parse array of fields for struct, interface, and func arguments
func (p *Parser) Fields(sep, term string) *[]Field { func (p *Parser) Fields(sep, term string) []Field {
a := new([]Field, 10); a := new([]Field, 10);
nf := 0; nf := 0;
for p.token != "" && p.token != term { for p.token != "" && p.token != term {
...@@ -715,7 +716,7 @@ func (p *Parser) Fields(sep, term string) *[]Field { ...@@ -715,7 +716,7 @@ func (p *Parser) Fields(sep, term string) *[]Field {
} }
// A single type packaged as a field for a function return // A single type packaged as a field for a function return
func (p *Parser) OneField() *[]Field { func (p *Parser) OneField() []Field {
a := new([]Field, 1); a := new([]Field, 1);
a[0].name = ""; a[0].name = "";
a[0].typ = p.Type(""); a[0].typ = p.Type("");
......
...@@ -693,7 +693,7 @@ export type StructValue interface { ...@@ -693,7 +693,7 @@ export type StructValue interface {
type StructValueStruct struct { type StructValueStruct struct {
Common; Common;
field *[]Value; field []Value;
} }
func (v *StructValueStruct) Len() int { func (v *StructValueStruct) Len() int {
...@@ -850,7 +850,7 @@ export func CopyArray(dst ArrayValue, src ArrayValue, n int) { ...@@ -850,7 +850,7 @@ export func CopyArray(dst ArrayValue, src ArrayValue, n int) {
dstp := uintptr(dst.Elem(0).Addr()); dstp := uintptr(dst.Elem(0).Addr());
srcp := uintptr(src.Elem(0).Addr()); srcp := uintptr(src.Elem(0).Addr());
end := uintptr(n)*uintptr(dt.Size()); end := uintptr(n)*uintptr(dt.Size());
if dst.Type().Size() % 8 == 0 { if end % 8 == 0 {
for i := uintptr(0); i < end; i += 8{ for i := uintptr(0); i < end; i += 8{
di := Addr(dstp + i); di := Addr(dstp + i);
si := Addr(srcp + i); si := Addr(srcp + i);
......
...@@ -49,7 +49,7 @@ var bad_re = []StringError{ ...@@ -49,7 +49,7 @@ var bad_re = []StringError{
StringError{ `\x`, regexp.ErrBadBackslash }, StringError{ `\x`, regexp.ErrBadBackslash },
} }
type Vec [20]int; type Vec []int;
type Tester struct { type Tester struct {
re string; re string;
...@@ -57,33 +57,31 @@ type Tester struct { ...@@ -57,33 +57,31 @@ type Tester struct {
match Vec; match Vec;
} }
const END = -1000
var matches = []Tester { var matches = []Tester {
Tester{ ``, "", Vec{0,0, END} }, Tester{ ``, "", Vec{0,0} },
Tester{ `a`, "a", Vec{0,1, END} }, Tester{ `a`, "a", Vec{0,1} },
Tester{ `b`, "abc", Vec{1,2, END} }, Tester{ `b`, "abc", Vec{1,2} },
Tester{ `.`, "a", Vec{0,1, END} }, Tester{ `.`, "a", Vec{0,1} },
Tester{ `.*`, "abcdef", Vec{0,6, END} }, Tester{ `.*`, "abcdef", Vec{0,6} },
Tester{ `^abcd$`, "abcd", Vec{0,4, END} }, Tester{ `^abcd$`, "abcd", Vec{0,4} },
Tester{ `^bcd'`, "abcdef", Vec{END} }, Tester{ `^bcd'`, "abcdef", Vec{} },
Tester{ `^abcd$`, "abcde", Vec{END} }, Tester{ `^abcd$`, "abcde", Vec{} },
Tester{ `a+`, "baaab", Vec{1,4, END} }, Tester{ `a+`, "baaab", Vec{1,4} },
Tester{ `a*`, "baaab", Vec{0,0, END} }, Tester{ `a*`, "baaab", Vec{0,0} },
Tester{ `[a-z]+`, "abcd", Vec{0,4, END} }, Tester{ `[a-z]+`, "abcd", Vec{0,4} },
Tester{ `[^a-z]+`, "ab1234cd", Vec{2,6, END} }, Tester{ `[^a-z]+`, "ab1234cd", Vec{2,6} },
Tester{ `[a\-\]z]+`, "az]-bcz", Vec{0,4, END} }, Tester{ `[a\-\]z]+`, "az]-bcz", Vec{0,4} },
Tester{ `[日本語]+`, "日本語日本語", Vec{0,18, END} }, Tester{ `[日本語]+`, "日本語日本語", Vec{0,18} },
Tester{ `()`, "", Vec{0,0, 0,0, END} }, Tester{ `()`, "", Vec{0,0, 0,0} },
Tester{ `(a)`, "a", Vec{0,1, 0,1, END} }, Tester{ `(a)`, "a", Vec{0,1, 0,1} },
Tester{ `(.)(.)`, "日a", Vec{0,4, 0,3, 3,4, END} }, Tester{ `(.)(.)`, "日a", Vec{0,4, 0,3, 3,4} },
Tester{ `(.*)`, "", Vec{0,0, 0,0, END} }, Tester{ `(.*)`, "", Vec{0,0, 0,0} },
Tester{ `(.*)`, "abcd", Vec{0,4, 0,4, END} }, Tester{ `(.*)`, "abcd", Vec{0,4, 0,4} },
Tester{ `(..)(..)`, "abcd", Vec{0,4, 0,2, 2,4, END} }, Tester{ `(..)(..)`, "abcd", Vec{0,4, 0,2, 2,4} },
Tester{ `(([^xyz]*)(d))`, "abcd", Vec{0,4, 0,4, 0,3, 3,4, END} }, Tester{ `(([^xyz]*)(d))`, "abcd", Vec{0,4, 0,4, 0,3, 3,4} },
Tester{ `((a|b|c)*(d))`, "abcd", Vec{0,4, 0,4, 2,3, 3,4, END} }, Tester{ `((a|b|c)*(d))`, "abcd", Vec{0,4, 0,4, 2,3, 3,4} },
Tester{ `(((a|b|c)*)(d))`, "abcd", Vec{0,4, 0,4, 0,3, 2,3, 3,4, END} }, Tester{ `(((a|b|c)*)(d))`, "abcd", Vec{0,4, 0,4, 0,3, 2,3, 3,4} },
Tester{ `a*(|(b))c*`, "aacc", Vec{0,4, 2,2, -1,-1, END} }, Tester{ `a*(|(b))c*`, "aacc", Vec{0,4, 2,2, -1,-1} },
} }
func CompileTest(t *testing.T, expr string, error *os.Error) regexp.Regexp { func CompileTest(t *testing.T, expr string, error *os.Error) regexp.Regexp {
...@@ -94,30 +92,20 @@ func CompileTest(t *testing.T, expr string, error *os.Error) regexp.Regexp { ...@@ -94,30 +92,20 @@ func CompileTest(t *testing.T, expr string, error *os.Error) regexp.Regexp {
return re return re
} }
func MarkedLen(m *[] int) int { func PrintVec(t *testing.T, m [] int) {
if m == nil { l := len(m);
return 0
}
var i int;
for i = 0; i < len(m) && m[i] != END; i = i+2 {
}
return i
}
func PrintVec(t *testing.T, m *[] int) {
l := MarkedLen(m);
if l == 0 { if l == 0 {
t.Log("\t<no match>"); t.Log("\t<no match>");
} else { } else {
for i := 0; i < l && m[i] != END; i = i+2 { for i := 0; i < l; i = i+2 {
t.Log("\t", m[i], ",", m[i+1]) t.Log("\t", m[i], ",", m[i+1])
} }
} }
} }
func Equal(m1, m2 *[]int) bool { func Equal(m1, m2 []int) bool {
l := MarkedLen(m1); l := len(m1);
if l != MarkedLen(m2) { if l != len(m2) {
return false return false
} }
for i := 0; i < l; i++ { for i := 0; i < l; i++ {
...@@ -128,7 +116,7 @@ func Equal(m1, m2 *[]int) bool { ...@@ -128,7 +116,7 @@ func Equal(m1, m2 *[]int) bool {
return true return true
} }
func MatchTest(t *testing.T, expr string, str string, match *[]int) { func MatchTest(t *testing.T, expr string, str string, match []int) {
re := CompileTest(t, expr, nil); re := CompileTest(t, expr, nil);
if re == nil { if re == nil {
return return
...@@ -157,6 +145,6 @@ export func TestBadCompile(t *testing.T) { ...@@ -157,6 +145,6 @@ export func TestBadCompile(t *testing.T) {
export func TestMatch(t *testing.T) { export func TestMatch(t *testing.T) {
for i := 0; i < len(matches); i++ { for i := 0; i < len(matches); i++ {
test := &matches[i]; test := &matches[i];
MatchTest(t, test.re, test.text, &test.match) MatchTest(t, test.re, test.text, test.match)
} }
} }
...@@ -582,7 +582,7 @@ func Compiler(str string, ch *chan *RE) { ...@@ -582,7 +582,7 @@ func Compiler(str string, ch *chan *RE) {
// Public interface has only execute functionality (not yet implemented) // Public interface has only execute functionality (not yet implemented)
export type Regexp interface { export type Regexp interface {
Execute(s string) *[]int Execute(s string) []int
} }
// Compile in separate goroutine; wait for result // Compile in separate goroutine; wait for result
...@@ -595,12 +595,12 @@ export func Compile(str string) (regexp Regexp, error *os.Error) { ...@@ -595,12 +595,12 @@ export func Compile(str string) (regexp Regexp, error *os.Error) {
type State struct { type State struct {
inst Inst; // next instruction to execute inst Inst; // next instruction to execute
match *[]int; // pairs of bracketing submatches. 0th is start,end match []int; // pairs of bracketing submatches. 0th is start,end
} }
// Append new state to to-do list. Leftmost-longest wins so avoid // Append new state to to-do list. Leftmost-longest wins so avoid
// adding a state that's already active. // adding a state that's already active.
func AddState(s *[]State, inst Inst, match *[]int) *[]State { func AddState(s []State, inst Inst, match []int) []State {
index := inst.Index(); index := inst.Index();
l := len(s); l := len(s);
pos := match[0]; pos := match[0];
...@@ -625,8 +625,8 @@ func AddState(s *[]State, inst Inst, match *[]int) *[]State { ...@@ -625,8 +625,8 @@ func AddState(s *[]State, inst Inst, match *[]int) *[]State {
return s; return s;
} }
func (re *RE) DoExecute(str string, pos int) *[]int { func (re *RE) DoExecute(str string, pos int) []int {
var s [2]*[]State; // TODO: use a vector when State values (not ptrs) can be vector elements var s [2][]State; // TODO: use a vector when State values (not ptrs) can be vector elements
s[0] = new([]State, 10)[0:0]; s[0] = new([]State, 10)[0:0];
s[1] = new([]State, 10)[0:0]; s[1] = new([]State, 10)[0:0];
in, out := 0, 1; in, out := 0, 1;
...@@ -708,13 +708,10 @@ func (re *RE) DoExecute(str string, pos int) *[]int { ...@@ -708,13 +708,10 @@ func (re *RE) DoExecute(str string, pos int) *[]int {
} }
pos += charwidth; pos += charwidth;
} }
if !found {
return nil
}
return final.match; return final.match;
} }
func (re *RE) Execute(s string) *[]int { func (re *RE) Execute(s string) []int {
return re.DoExecute(s, 0) return re.DoExecute(s, 0)
} }
...@@ -136,7 +136,7 @@ export func IsSorted(data SortInterface) bool { ...@@ -136,7 +136,7 @@ export func IsSorted(data SortInterface) bool {
// Convenience types for common cases // Convenience types for common cases
export type IntArray struct { export type IntArray struct {
data *[]int; data []int;
} }
func (p *IntArray) Len() int { return len(p.data); } func (p *IntArray) Len() int { return len(p.data); }
...@@ -145,7 +145,7 @@ func (p *IntArray) Swap(i, j int) { p.data[i], p.data[j] = p.data[j], p.da ...@@ -145,7 +145,7 @@ func (p *IntArray) Swap(i, j int) { p.data[i], p.data[j] = p.data[j], p.da
export type FloatArray struct { export type FloatArray struct {
data *[]float; data []float;
} }
func (p *FloatArray) Len() int { return len(p.data); } func (p *FloatArray) Len() int { return len(p.data); }
...@@ -154,7 +154,7 @@ func (p *FloatArray) Swap(i, j int) { p.data[i], p.data[j] = p.data[j], p. ...@@ -154,7 +154,7 @@ func (p *FloatArray) Swap(i, j int) { p.data[i], p.data[j] = p.data[j], p.
export type StringArray struct { export type StringArray struct {
data *[]string; data []string;
} }
func (p *StringArray) Len() int { return len(p.data); } func (p *StringArray) Len() int { return len(p.data); }
...@@ -164,11 +164,11 @@ func (p *StringArray) Swap(i, j int) { p.data[i], p.data[j] = p.data[j], p ...@@ -164,11 +164,11 @@ func (p *StringArray) Swap(i, j int) { p.data[i], p.data[j] = p.data[j], p
// Convenience wrappers for common cases // Convenience wrappers for common cases
export func SortInts(a *[]int) { Sort(&IntArray{a}); } export func SortInts(a []int) { Sort(&IntArray{a}); }
export func SortFloats(a *[]float) { Sort(&FloatArray{a}); } export func SortFloats(a []float) { Sort(&FloatArray{a}); }
export func SortStrings(a *[]string) { Sort(&StringArray{a}); } export func SortStrings(a []string) { Sort(&StringArray{a}); }
export func IntsAreSorted(a *[]int) bool { return IsSorted(&IntArray{a}); } export func IntsAreSorted(a []int) bool { return IsSorted(&IntArray{a}); }
export func FloatsAreSorted(a *[]float) bool { return IsSorted(&FloatArray{a}); } export func FloatsAreSorted(a []float) bool { return IsSorted(&FloatArray{a}); }
export func StringsAreSorted(a *[]string) bool { return IsSorted(&StringArray{a}); } export func StringsAreSorted(a []string) bool { return IsSorted(&StringArray{a}); }
...@@ -20,7 +20,7 @@ var strings = []string{"", "Hello", "foo", "bar", "foo", "f00", "%*&^*&^&", "*** ...@@ -20,7 +20,7 @@ var strings = []string{"", "Hello", "foo", "bar", "foo", "f00", "%*&^*&^&", "***
export func TestSortIntArray(t *testing.T) { export func TestSortIntArray(t *testing.T) {
data := ints; data := ints;
a := sort.IntArray{&data}; a := sort.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);
...@@ -30,7 +30,7 @@ export func TestSortIntArray(t *testing.T) { ...@@ -30,7 +30,7 @@ export func TestSortIntArray(t *testing.T) {
export func TestSortFloatArray(t *testing.T) { export func TestSortFloatArray(t *testing.T) {
data := floats; data := floats;
a := sort.FloatArray{&data}; a := sort.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);
...@@ -40,7 +40,7 @@ export func TestSortFloatArray(t *testing.T) { ...@@ -40,7 +40,7 @@ export func TestSortFloatArray(t *testing.T) {
export func TestSortStringArray(t *testing.T) { export func TestSortStringArray(t *testing.T) {
data := strings; data := strings;
a := sort.StringArray{&data}; a := sort.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);
...@@ -50,8 +50,8 @@ export func TestSortStringArray(t *testing.T) { ...@@ -50,8 +50,8 @@ export func TestSortStringArray(t *testing.T) {
export func TestSortInts(t *testing.T) { export func TestSortInts(t *testing.T) {
data := ints; data := ints;
sort.SortInts(&data); sort.SortInts(data);
if !sort.IntsAreSorted(&data) { if !sort.IntsAreSorted(data) {
t.Errorf("sorted %v", ints); t.Errorf("sorted %v", ints);
t.Errorf(" got %v", data); t.Errorf(" got %v", data);
} }
...@@ -59,8 +59,8 @@ export func TestSortInts(t *testing.T) { ...@@ -59,8 +59,8 @@ export func TestSortInts(t *testing.T) {
export func TestSortFloats(t *testing.T) { export func TestSortFloats(t *testing.T) {
data := floats; data := floats;
sort.SortFloats(&data); sort.SortFloats(data);
if !sort.FloatsAreSorted(&data) { if !sort.FloatsAreSorted(data) {
t.Errorf("sorted %v", floats); t.Errorf("sorted %v", floats);
t.Errorf(" got %v", data); t.Errorf(" got %v", data);
} }
...@@ -68,8 +68,8 @@ export func TestSortFloats(t *testing.T) { ...@@ -68,8 +68,8 @@ export func TestSortFloats(t *testing.T) {
export func TestSortStrings(t *testing.T) { export func TestSortStrings(t *testing.T) {
data := strings; data := strings;
sort.SortStrings(&data); sort.SortStrings(data);
if !sort.StringsAreSorted(&data) { if !sort.StringsAreSorted(data) {
t.Errorf("sorted %v", strings); t.Errorf("sorted %v", strings);
t.Errorf(" got %v", data); t.Errorf(" got %v", data);
} }
...@@ -111,7 +111,7 @@ const ( ...@@ -111,7 +111,7 @@ const (
type TestingData struct { type TestingData struct {
desc string; desc string;
t *testing.T; t *testing.T;
data *[]int; data []int;
maxswap int; // number of swaps allowed maxswap int; // number of swaps allowed
nswap int; nswap int;
} }
...@@ -153,7 +153,7 @@ export func TestBentleyMcIlroy(t *testing.T) { ...@@ -153,7 +153,7 @@ export func TestBentleyMcIlroy(t *testing.T) {
for dist := 0; dist < NDist; dist++ { for dist := 0; dist < NDist; dist++ {
j := 0; j := 0;
k := 1; k := 1;
data := (&tmp1)[0:n]; data := tmp1[0:n];
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
switch dist { switch dist {
case Sawtooth: case Sawtooth:
...@@ -175,7 +175,7 @@ export func TestBentleyMcIlroy(t *testing.T) { ...@@ -175,7 +175,7 @@ export func TestBentleyMcIlroy(t *testing.T) {
} }
} }
mdata := (&tmp2)[0:n]; mdata := tmp2[0:n];
for mode := 0; mode < NMode; mode++ { for mode := 0; mode < NMode; mode++ {
switch mode { switch mode {
case Copy: case Copy:
......
...@@ -27,8 +27,8 @@ func (a *Decimal) RoundDown(nd int) *Decimal; ...@@ -27,8 +27,8 @@ func (a *Decimal) RoundDown(nd int) *Decimal;
func (a *Decimal) RoundedInteger() uint64; func (a *Decimal) RoundedInteger() uint64;
func Copy(dst *[]byte, src *[]byte) int; func Copy(dst []byte, src []byte) int;
func DigitZero(dst *[]byte) int; func DigitZero(dst []byte) int;
func (a *Decimal) String() string { func (a *Decimal) String() string {
n := 10 + a.nd; n := 10 + a.nd;
...@@ -52,31 +52,31 @@ func (a *Decimal) String() string { ...@@ -52,31 +52,31 @@ func (a *Decimal) String() string {
buf[w] = '.'; buf[w] = '.';
w++; w++;
w += DigitZero(buf[w:w+-a.dp]); w += DigitZero(buf[w:w+-a.dp]);
w += Copy(buf[w:w+a.nd], (&a.d)[0:a.nd]); w += Copy(buf[w:w+a.nd], a.d[0:a.nd]);
case a.dp < a.nd: case a.dp < a.nd:
// decimal point in middle of digits // decimal point in middle of digits
w += Copy(buf[w:w+a.dp], (&a.d)[0:a.dp]); w += Copy(buf[w:w+a.dp], a.d[0:a.dp]);
buf[w] = '.'; buf[w] = '.';
w++; w++;
w += Copy(buf[w:w+a.nd-a.dp], (&a.d)[a.dp:a.nd]); w += Copy(buf[w:w+a.nd-a.dp], a.d[a.dp:a.nd]);
default: default:
// zeros fill space between digits and decimal point // zeros fill space between digits and decimal point
w += Copy(buf[w:w+a.nd], (&a.d)[0:a.nd]); w += Copy(buf[w:w+a.nd], a.d[0:a.nd]);
w += DigitZero(buf[w:w+a.dp-a.nd]); w += DigitZero(buf[w:w+a.dp-a.nd]);
} }
return string(buf[0:w]); return string(buf[0:w]);
} }
func Copy(dst *[]byte, src *[]byte) int { func Copy(dst []byte, src []byte) int {
for i := 0; i < len(dst); i++ { for i := 0; i < len(dst); i++ {
dst[i] = src[i]; dst[i] = src[i];
} }
return len(dst); return len(dst);
} }
func DigitZero(dst *[]byte) int { func DigitZero(dst []byte) int {
for i := 0; i < len(dst); i++ { for i := 0; i < len(dst); i++ {
dst[i] = '0'; dst[i] = '0';
} }
...@@ -236,7 +236,7 @@ var leftcheat = []LeftCheat { ...@@ -236,7 +236,7 @@ var leftcheat = []LeftCheat {
} }
// Is the leading prefix of b lexicographically less than s? // Is the leading prefix of b lexicographically less than s?
func PrefixIsLessThan(b *[]byte, s string) bool { func PrefixIsLessThan(b []byte, s string) bool {
for i := 0; i < len(s); i++ { for i := 0; i < len(s); i++ {
if i >= len(b) { if i >= len(b) {
return true; return true;
...@@ -251,7 +251,7 @@ func PrefixIsLessThan(b *[]byte, s string) bool { ...@@ -251,7 +251,7 @@ func PrefixIsLessThan(b *[]byte, s string) bool {
// Binary shift left (/ 2) by k bits. k <= MaxShift to avoid overflow. // Binary shift left (/ 2) by k bits. k <= MaxShift to avoid overflow.
func LeftShift(a *Decimal, k uint) { func LeftShift(a *Decimal, k uint) {
delta := leftcheat[k].delta; delta := leftcheat[k].delta;
if PrefixIsLessThan((&a.d)[0:a.nd], leftcheat[k].cutoff) { if PrefixIsLessThan(a.d[0:a.nd], leftcheat[k].cutoff) {
delta--; delta--;
} }
......
...@@ -380,7 +380,7 @@ func FmtB(neg bool, mant uint64, exp int, flt *FloatInfo) string { ...@@ -380,7 +380,7 @@ func FmtB(neg bool, mant uint64, exp int, flt *FloatInfo) string {
w--; w--;
buf[w] = '-'; buf[w] = '-';
} }
return string((&buf)[w:len(buf)]); return string(buf[w:len(buf)]);
} }
func Max(a, b int) int { func Max(a, b int) int {
......
...@@ -28,8 +28,8 @@ export func itoa64(i int64) string { ...@@ -28,8 +28,8 @@ export func itoa64(i int64) string {
b[bp] = '-' b[bp] = '-'
} }
// BUG return string(b[bp:len(b)]) return string(b[bp:len(b)])
return string((&b)[bp:len(b)]) //return string((&b)[bp:len(b)])
} }
export func itoa(i int) string { export func itoa(i int) string {
......
...@@ -7,7 +7,7 @@ package strings ...@@ -7,7 +7,7 @@ package strings
import "utf8" import "utf8"
// Split string into array of UTF-8 sequences (still strings) // Split string into array of UTF-8 sequences (still strings)
export func explode(s string) *[]string { export func explode(s string) []string {
a := new([]string, utf8.RuneCountInString(s, 0, len(s))); a := new([]string, utf8.RuneCountInString(s, 0, len(s)));
j := 0; j := 0;
var size, rune int; var size, rune int;
...@@ -50,7 +50,7 @@ export func index(s, sep string) int { ...@@ -50,7 +50,7 @@ export func index(s, sep string) int {
} }
// Split string into list of strings at separators // Split string into list of strings at separators
export func split(s, sep string) *[]string { export func split(s, sep string) []string {
if sep == "" { if sep == "" {
return explode(s) return explode(s)
} }
...@@ -72,7 +72,7 @@ export func split(s, sep string) *[]string { ...@@ -72,7 +72,7 @@ export func split(s, sep string) *[]string {
} }
// Join list of strings with separators between them. // Join list of strings with separators between them.
export func join(a *[]string, sep string) string { export func join(a []string, sep string) string {
if len(a) == 0 { if len(a) == 0 {
return "" return ""
} }
......
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
"testing"; "testing";
) )
func eq(a, b *[]string) bool { func eq(a, b []string) bool {
if len(a) != len(b) { if len(a) != len(b) {
return false; return false;
} }
...@@ -28,11 +28,11 @@ var dots = "1....2....3....4"; ...@@ -28,11 +28,11 @@ var dots = "1....2....3....4";
type ExplodeTest struct { type ExplodeTest struct {
s string; s string;
a *[]string; a []string;
} }
var explodetests = []ExplodeTest { var explodetests = []ExplodeTest {
ExplodeTest{ abcd, &[]string{"a", "b", "c", "d"} }, ExplodeTest{ abcd, []string{"a", "b", "c", "d"} },
ExplodeTest{ faces, &[]string{"☺", "☻", "☹" } }, ExplodeTest{ faces, []string{"☺", "☻", "☹" } },
} }
export func TestExplode(t *testing.T) { export func TestExplode(t *testing.T) {
for i := 0; i < len(explodetests); i++ { for i := 0; i < len(explodetests); i++ {
...@@ -52,17 +52,17 @@ export func TestExplode(t *testing.T) { ...@@ -52,17 +52,17 @@ export func TestExplode(t *testing.T) {
type SplitTest struct { type SplitTest struct {
s string; s string;
sep string; sep string;
a *[]string; a []string;
} }
var splittests = []SplitTest { var splittests = []SplitTest {
SplitTest{ abcd, "a", &[]string{"", "bcd"} }, SplitTest{ abcd, "a", []string{"", "bcd"} },
SplitTest{ abcd, "z", &[]string{"abcd"} }, SplitTest{ abcd, "z", []string{"abcd"} },
SplitTest{ abcd, "", &[]string{"a", "b", "c", "d"} }, SplitTest{ abcd, "", []string{"a", "b", "c", "d"} },
SplitTest{ commas, ",", &[]string{"1", "2", "3", "4"} }, SplitTest{ commas, ",", []string{"1", "2", "3", "4"} },
SplitTest{ dots, "...", &[]string{"1", ".2", ".3", ".4"} }, SplitTest{ dots, "...", []string{"1", ".2", ".3", ".4"} },
SplitTest{ faces, "☹", &[]string{"☺☻", ""} }, SplitTest{ faces, "☹", []string{"☺☻", ""} },
SplitTest{ faces, "~", &[]string{faces} }, SplitTest{ faces, "~", []string{faces} },
SplitTest{ faces, "", &[]string{"☺", "☻", "☹"} }, SplitTest{ faces, "", []string{"☺", "☻", "☹"} },
} }
export func TestSplit(t *testing.T) { export func TestSplit(t *testing.T) {
for i := 0; i < len(splittests); i++ { for i := 0; i < len(splittests); i++ {
......
...@@ -15,7 +15,7 @@ const NameBufsize = 512 ...@@ -15,7 +15,7 @@ const NameBufsize = 512
export func open(name string, mode int64, perm int64) (ret int64, errno int64) { export func open(name string, mode int64, perm int64) (ret int64, errno int64) {
var namebuf [NameBufsize]byte; var namebuf [NameBufsize]byte;
if !StringToBytes(&namebuf, name) { if !StringToBytes(namebuf, name) {
return -1, ENAMETOOLONG return -1, ENAMETOOLONG
} }
r1, r2, err := Syscall(SYS_OPEN, int64(uintptr(unsafe.pointer(&namebuf[0]))), mode, perm); r1, r2, err := Syscall(SYS_OPEN, int64(uintptr(unsafe.pointer(&namebuf[0]))), mode, perm);
...@@ -24,7 +24,7 @@ export func open(name string, mode int64, perm int64) (ret int64, errno int64) { ...@@ -24,7 +24,7 @@ export func open(name string, mode int64, perm int64) (ret int64, errno int64) {
export func creat(name string, perm int64) (ret int64, errno int64) { export func creat(name string, perm int64) (ret int64, errno int64) {
var namebuf [NameBufsize]byte; var namebuf [NameBufsize]byte;
if !StringToBytes(&namebuf, name) { if !StringToBytes(namebuf, name) {
return -1, ENAMETOOLONG return -1, ENAMETOOLONG
} }
r1, r2, err := Syscall(SYS_OPEN, int64(uintptr(unsafe.pointer(&namebuf[0]))), O_CREAT|O_WRONLY|O_TRUNC, perm); r1, r2, err := Syscall(SYS_OPEN, int64(uintptr(unsafe.pointer(&namebuf[0]))), O_CREAT|O_WRONLY|O_TRUNC, perm);
...@@ -58,7 +58,7 @@ export func pipe(fds *[2]int64) (ret int64, errno int64) { ...@@ -58,7 +58,7 @@ export func pipe(fds *[2]int64) (ret int64, errno int64) {
export func stat(name string, buf *Stat) (ret int64, errno int64) { export func stat(name string, buf *Stat) (ret int64, errno int64) {
var namebuf [NameBufsize]byte; var namebuf [NameBufsize]byte;
if !StringToBytes(&namebuf, name) { if !StringToBytes(namebuf, name) {
return -1, ENAMETOOLONG return -1, ENAMETOOLONG
} }
r1, r2, err := Syscall(SYS_STAT64, int64(uintptr(unsafe.pointer(&namebuf[0]))), int64(uintptr(unsafe.pointer(buf))), 0); r1, r2, err := Syscall(SYS_STAT64, int64(uintptr(unsafe.pointer(&namebuf[0]))), int64(uintptr(unsafe.pointer(buf))), 0);
...@@ -77,7 +77,7 @@ export func fstat(fd int64, buf *Stat) (ret int64, errno int64) { ...@@ -77,7 +77,7 @@ export func fstat(fd int64, buf *Stat) (ret int64, errno int64) {
export func unlink(name string) (ret int64, errno int64) { export func unlink(name string) (ret int64, errno int64) {
var namebuf [NameBufsize]byte; var namebuf [NameBufsize]byte;
if !StringToBytes(&namebuf, name) { if !StringToBytes(namebuf, name) {
return -1, ENAMETOOLONG return -1, ENAMETOOLONG
} }
r1, r2, err := Syscall(SYS_UNLINK, int64(uintptr(unsafe.pointer(&namebuf[0]))), 0, 0); r1, r2, err := Syscall(SYS_UNLINK, int64(uintptr(unsafe.pointer(&namebuf[0]))), 0, 0);
...@@ -91,7 +91,7 @@ export func fcntl(fd, cmd, arg int64) (ret int64, errno int64) { ...@@ -91,7 +91,7 @@ export func fcntl(fd, cmd, arg int64) (ret int64, errno int64) {
export func mkdir(name string, perm int64) (ret int64, errno int64) { export func mkdir(name string, perm int64) (ret int64, errno int64) {
var namebuf [NameBufsize]byte; var namebuf [NameBufsize]byte;
if !StringToBytes(&namebuf, name) { if !StringToBytes(namebuf, name) {
return -1, ENAMETOOLONG return -1, ENAMETOOLONG
} }
r1, r2, err := Syscall(SYS_MKDIR, int64(uintptr(unsafe.pointer(&namebuf[0]))), perm, 0); r1, r2, err := Syscall(SYS_MKDIR, int64(uintptr(unsafe.pointer(&namebuf[0]))), perm, 0);
......
...@@ -91,17 +91,17 @@ export func kqueue() (ret int64, errno int64) { ...@@ -91,17 +91,17 @@ export func kqueue() (ret int64, errno int64) {
return r1, err return r1, err
} }
export func kevent(kq int64, changes, events *[]Kevent, timeout *Timespec) (ret int64, errno int64) { export func kevent(kq int64, changes, events []Kevent, timeout *Timespec) (ret int64, errno int64) {
var nchange, changeptr, nevent, eventptr int64; var nchange, changeptr, nevent, eventptr int64;
nchange = 0; nchange = 0;
changeptr = 0; changeptr = 0;
nevent = 0; nevent = 0;
eventptr = 0; eventptr = 0;
if changes != nil && len(changes) > 0 { if len(changes) > 0 {
changeptr = int64(uintptr(unsafe.pointer(&changes[0]))); changeptr = int64(uintptr(unsafe.pointer(&changes[0])));
nchange = int64(len(changes)) nchange = int64(len(changes))
} }
if events != nil && len(events) > 0 { if len(events) > 0 {
eventptr = int64(uintptr(unsafe.pointer(&events[0]))); eventptr = int64(uintptr(unsafe.pointer(&events[0])));
nevent = int64(len(events)) nevent = int64(len(events))
} }
......
...@@ -108,7 +108,7 @@ export func epoll_ctl(epfd, op, fd int64, ev *EpollEvent) int64 { ...@@ -108,7 +108,7 @@ export func epoll_ctl(epfd, op, fd int64, ev *EpollEvent) int64 {
return err return err
} }
export func epoll_wait(epfd int64, ev *[]EpollEvent, msec int64) (ret int64, err int64) { export func epoll_wait(epfd int64, ev []EpollEvent, msec int64) (ret int64, err int64) {
var evptr, nev int64; var evptr, nev int64;
if ev != nil && len(ev) > 0 { if ev != nil && len(ev) > 0 {
nev = int64(len(ev)); nev = int64(len(ev));
......
...@@ -16,7 +16,7 @@ export func RawSyscall(trap int64, a1, a2, a3 int64) (r1, r2, err int64); ...@@ -16,7 +16,7 @@ export func RawSyscall(trap int64, a1, a2, a3 int64) (r1, r2, err int64);
* Used to convert file names to byte arrays for passing to kernel, * Used to convert file names to byte arrays for passing to kernel,
* but useful elsewhere too. * but useful elsewhere too.
*/ */
export func StringToBytes(b *[]byte, s string) bool { export func StringToBytes(b []byte, s string) bool {
if len(s) >= len(b) { if len(s) >= len(b) {
return false return false
} }
......
...@@ -16,7 +16,7 @@ import ( ...@@ -16,7 +16,7 @@ import (
// Basic ByteArray support // Basic ByteArray support
type ByteArray struct { type ByteArray struct {
a *[]byte; a []byte;
} }
...@@ -35,12 +35,12 @@ func (b *ByteArray) Clear() { ...@@ -35,12 +35,12 @@ func (b *ByteArray) Clear() {
} }
func (b *ByteArray) Slice(i, j int) *[]byte { func (b *ByteArray) Slice(i, j int) []byte {
return b.a[i : j]; // BUG should really be &b.a[i : j] return b.a[i : j]; // BUG should really be &b.a[i : j]
} }
func (b *ByteArray) Append(s *[]byte) { func (b *ByteArray) Append(s []byte) {
a := b.a; a := b.a;
n := len(a); n := len(a);
m := n + len(s); m := n + len(s);
...@@ -194,7 +194,7 @@ func (b *Writer) Dump() { ...@@ -194,7 +194,7 @@ func (b *Writer) Dump() {
} }
func (b *Writer) Write0(buf *[]byte) *os.Error { func (b *Writer) Write0(buf []byte) *os.Error {
n, err := b.writer.Write(buf); n, err := b.writer.Write(buf);
if n != len(buf) && err == nil { if n != len(buf) && err == nil {
err = os.EIO; err = os.EIO;
...@@ -203,7 +203,7 @@ func (b *Writer) Write0(buf *[]byte) *os.Error { ...@@ -203,7 +203,7 @@ func (b *Writer) Write0(buf *[]byte) *os.Error {
} }
var Newline = &[]byte{'\n'} var Newline = []byte{'\n'}
func (b *Writer) WritePadding(textw, cellw int) (err *os.Error) { func (b *Writer) WritePadding(textw, cellw int) (err *os.Error) {
if b.padbytes[0] == '\t' { if b.padbytes[0] == '\t' {
...@@ -221,13 +221,13 @@ func (b *Writer) WritePadding(textw, cellw int) (err *os.Error) { ...@@ -221,13 +221,13 @@ func (b *Writer) WritePadding(textw, cellw int) (err *os.Error) {
} }
for n > len(b.padbytes) { for n > len(b.padbytes) {
err = b.Write0(&b.padbytes); err = b.Write0(b.padbytes);
if err != nil { if err != nil {
goto exit; goto exit;
} }
n -= len(b.padbytes); n -= len(b.padbytes);
} }
err = b.Write0((&b.padbytes)[0 : n]); // BUG 6g should not require ()'s err = b.Write0(b.padbytes[0 : n]);
exit: exit:
return err; return err;
...@@ -353,7 +353,7 @@ exit: ...@@ -353,7 +353,7 @@ exit:
} }
func UnicodeLen(buf *[]byte) int { func UnicodeLen(buf []byte) int {
l := 0; l := 0;
for i := 0; i < len(buf); { for i := 0; i < len(buf); {
if buf[i] < utf8.RuneSelf { if buf[i] < utf8.RuneSelf {
...@@ -368,13 +368,13 @@ func UnicodeLen(buf *[]byte) int { ...@@ -368,13 +368,13 @@ func UnicodeLen(buf *[]byte) int {
} }
func (b *Writer) Append(buf *[]byte) { func (b *Writer) Append(buf []byte) {
b.buf.Append(buf); b.buf.Append(buf);
b.size += len(buf); b.size += len(buf);
} }
/* export */ func (b *Writer) Write(buf *[]byte) (written int, err *os.Error) { /* export */ func (b *Writer) Write(buf []byte) (written int, err *os.Error) {
i0, n := 0, len(buf); i0, n := 0, len(buf);
// split text into cells // split text into cells
......
...@@ -13,7 +13,7 @@ import ( ...@@ -13,7 +13,7 @@ import (
type Buffer struct { type Buffer struct {
a *[]byte; a []byte;
} }
...@@ -27,7 +27,7 @@ func (b *Buffer) Clear() { ...@@ -27,7 +27,7 @@ func (b *Buffer) Clear() {
} }
func (b *Buffer) Write(buf *[]byte) (written int, err *os.Error) { func (b *Buffer) Write(buf []byte) (written int, err *os.Error) {
n := len(b.a); n := len(b.a);
m := len(buf); m := len(buf);
if n + m <= cap(b.a) { if n + m <= cap(b.a) {
......
...@@ -82,7 +82,7 @@ func TRunner(t *T, test *Test) { ...@@ -82,7 +82,7 @@ func TRunner(t *T, test *Test) {
t.ch <- t; t.ch <- t;
} }
export func Main(tests *[]Test) { export func Main(tests []Test) {
flag.Parse(); flag.Parse();
ok := true; ok := true;
if len(tests) == 0 { if len(tests) == 0 {
......
...@@ -53,13 +53,11 @@ var LeapMonths = []int{ ...@@ -53,13 +53,11 @@ var LeapMonths = []int{
31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
} }
func Months(year int64) *[]int { func Months(year int64) []int {
if year%4 == 0 && (year%100 != 0 || year%400 == 0) { if year%4 == 0 && (year%100 != 0 || year%400 == 0) {
return &LeapMonths return LeapMonths
} else {
return &RegularMonths
} }
return nil // not reached return RegularMonths
} }
const ( const (
...@@ -258,13 +256,13 @@ var ShortMonthNames = []string{ ...@@ -258,13 +256,13 @@ var ShortMonthNames = []string{
"Dec" "Dec"
} }
func Copy(dst *[]byte, s string) { func Copy(dst []byte, s string) {
for i := 0; i < len(s); i++ { for i := 0; i < len(s); i++ {
dst[i] = s[i] dst[i] = s[i]
} }
} }
func Decimal(dst *[]byte, n int) { func Decimal(dst []byte, n int) {
if n < 0 { if n < 0 {
n = 0 n = 0
} }
...@@ -274,7 +272,7 @@ func Decimal(dst *[]byte, n int) { ...@@ -274,7 +272,7 @@ func Decimal(dst *[]byte, n int) {
} }
} }
func AddString(buf *[]byte, bp int, s string) int { func AddString(buf []byte, bp int, s string) int {
n := len(s); n := len(s);
Copy(buf[bp:bp+n], s); Copy(buf[bp:bp+n], s);
return bp+n return bp+n
......
...@@ -26,13 +26,17 @@ export var ( ...@@ -26,13 +26,17 @@ export var (
// Simple I/O interface to binary blob of data. // Simple I/O interface to binary blob of data.
type Data struct { type Data struct {
p *[]byte p []byte;
error bool;
} }
func (d *Data) Read(n int) *[]byte { var NIL []byte // TODO(rsc)
if d.p == nil || len(d.p) < n {
d.p = nil; func (d *Data) Read(n int) []byte {
return nil if len(d.p) < n {
d.p = NIL;
d.error = true;
return NIL;
} }
p := d.p[0:n]; p := d.p[0:n];
d.p = d.p[n:len(d.p)]; d.p = d.p[n:len(d.p)];
...@@ -41,7 +45,8 @@ func (d *Data) Read(n int) *[]byte { ...@@ -41,7 +45,8 @@ func (d *Data) Read(n int) *[]byte {
func (d *Data) Big4() (n uint32, ok bool) { func (d *Data) Big4() (n uint32, ok bool) {
p := d.Read(4); p := d.Read(4);
if p == nil { if len(p) < 4 {
d.error = true;
return 0, false return 0, false
} }
return uint32(p[0]) << 24 | uint32(p[1]) << 16 | uint32(p[2]) << 8 | uint32(p[3]), true return uint32(p[0]) << 24 | uint32(p[1]) << 16 | uint32(p[2]) << 8 | uint32(p[3]), true
...@@ -49,7 +54,8 @@ func (d *Data) Big4() (n uint32, ok bool) { ...@@ -49,7 +54,8 @@ func (d *Data) Big4() (n uint32, ok bool) {
func (d *Data) Byte() (n byte, ok bool) { func (d *Data) Byte() (n byte, ok bool) {
p := d.Read(1); p := d.Read(1);
if p == nil { if len(p) < 1 {
d.error = true;
return 0, false return 0, false
} }
return p[0], true return p[0], true
...@@ -57,7 +63,7 @@ func (d *Data) Byte() (n byte, ok bool) { ...@@ -57,7 +63,7 @@ func (d *Data) Byte() (n byte, ok bool) {
// Make a string by stopping at the first NUL // Make a string by stopping at the first NUL
func ByteString(p *[]byte) string { func ByteString(p []byte) string {
for i := 0; i < len(p); i++ { for i := 0; i < len(p); i++ {
if p[i] == 0 { if p[i] == 0 {
return string(p[0:i]) return string(p[0:i])
...@@ -70,7 +76,7 @@ func ByteString(p *[]byte) string { ...@@ -70,7 +76,7 @@ func ByteString(p *[]byte) string {
type Zone struct { type Zone struct {
utcoff int; utcoff int;
isdst bool; isdst bool;
name string name string;
} }
type Zonetime struct { type Zonetime struct {
...@@ -79,19 +85,21 @@ type Zonetime struct { ...@@ -79,19 +85,21 @@ type Zonetime struct {
isstd, isutc bool; // ignored - no idea what these mean isstd, isutc bool; // ignored - no idea what these mean
} }
func ParseZoneinfo(bytes *[]byte) (zt *[]Zonetime, err *os.Error) { func ParseZoneinfo(bytes []byte) (zt []Zonetime, err *os.Error) {
data1 := Data{bytes}; var NIL []Zonetime; // TODO(rsc)
data1 := Data{bytes, false};
data := &data1; data := &data1;
// 4-byte magic "TZif" // 4-byte magic "TZif"
if magic := data.Read(4); magic == nil || string(magic) != "TZif" { if magic := data.Read(4); string(magic) != "TZif" {
return nil, BadZoneinfo return NIL, BadZoneinfo
} }
// 1-byte version, then 15 bytes of padding // 1-byte version, then 15 bytes of padding
var p *[]byte; var p []byte;
if p = data.Read(16); p == nil || p[0] != 0 && p[0] != '2' { if p = data.Read(16); len(p) != 16 || p[0] != 0 && p[0] != '2' {
return nil, BadZoneinfo return NIL, BadZoneinfo
} }
vers := p[0]; vers := p[0];
...@@ -114,27 +122,27 @@ func ParseZoneinfo(bytes *[]byte) (zt *[]Zonetime, err *os.Error) { ...@@ -114,27 +122,27 @@ func ParseZoneinfo(bytes *[]byte) (zt *[]Zonetime, err *os.Error) {
for i := 0; i < 6; i++ { for i := 0; i < 6; i++ {
nn, ok := data.Big4(); nn, ok := data.Big4();
if !ok { if !ok {
return nil, BadZoneinfo return NIL, BadZoneinfo
} }
n[i] = int(nn); n[i] = int(nn);
} }
// Transition times. // Transition times.
txtimes1 := Data{data.Read(n[NTime]*4)}; txtimes1 := Data{data.Read(n[NTime]*4), false};
txtimes := &txtimes1; txtimes := &txtimes1;
// Time zone indices for transition times. // Time zone indices for transition times.
txzones := data.Read(n[NTime]); txzones := data.Read(n[NTime]);
// Zone info structures // Zone info structures
zonedata1 := Data{data.Read(n[NZone]*6)}; zonedata1 := Data{data.Read(n[NZone]*6), false};
zonedata := &zonedata1; zonedata := &zonedata1;
// Time zone abbreviations. // Time zone abbreviations.
abbrev := data.Read(n[NChar]); abbrev := data.Read(n[NChar]);
// Leap-second time pairs // Leap-second time pairs
leapdata1 := Data{data.Read(n[NLeap]*8)}; leapdata1 := Data{data.Read(n[NLeap]*8), false};
leapdata := &leapdata1; leapdata := &leapdata1;
// Whether tx times associated with local time types // Whether tx times associated with local time types
...@@ -145,8 +153,8 @@ func ParseZoneinfo(bytes *[]byte) (zt *[]Zonetime, err *os.Error) { ...@@ -145,8 +153,8 @@ func ParseZoneinfo(bytes *[]byte) (zt *[]Zonetime, err *os.Error) {
// are specified as UTC or local time. // are specified as UTC or local time.
isutc := data.Read(n[NUTCLocal]); isutc := data.Read(n[NUTCLocal]);
if data.p == nil { // ran out of data if data.error { // ran out of data
return nil, BadZoneinfo return NIL, BadZoneinfo
} }
// If version == 2, the entire file repeats, this time using // If version == 2, the entire file repeats, this time using
...@@ -161,16 +169,16 @@ func ParseZoneinfo(bytes *[]byte) (zt *[]Zonetime, err *os.Error) { ...@@ -161,16 +169,16 @@ func ParseZoneinfo(bytes *[]byte) (zt *[]Zonetime, err *os.Error) {
var ok bool; var ok bool;
var n uint32; var n uint32;
if n, ok = zonedata.Big4(); !ok { if n, ok = zonedata.Big4(); !ok {
return nil, BadZoneinfo return NIL, BadZoneinfo
} }
zone[i].utcoff = int(n); zone[i].utcoff = int(n);
var b byte; var b byte;
if b, ok = zonedata.Byte(); !ok { if b, ok = zonedata.Byte(); !ok {
return nil, BadZoneinfo return NIL, BadZoneinfo
} }
zone[i].isdst = b != 0; zone[i].isdst = b != 0;
if b, ok = zonedata.Byte(); !ok || int(b) >= len(abbrev) { if b, ok = zonedata.Byte(); !ok || int(b) >= len(abbrev) {
return nil, BadZoneinfo return NIL, BadZoneinfo
} }
zone[i].name = ByteString(abbrev[b:len(abbrev)]) zone[i].name = ByteString(abbrev[b:len(abbrev)])
} }
...@@ -181,11 +189,11 @@ func ParseZoneinfo(bytes *[]byte) (zt *[]Zonetime, err *os.Error) { ...@@ -181,11 +189,11 @@ func ParseZoneinfo(bytes *[]byte) (zt *[]Zonetime, err *os.Error) {
var ok bool; var ok bool;
var n uint32; var n uint32;
if n, ok = txtimes.Big4(); !ok { if n, ok = txtimes.Big4(); !ok {
return nil, BadZoneinfo return NIL, BadZoneinfo
} }
zt[i].time = int32(n); zt[i].time = int32(n);
if int(txzones[i]) >= len(zone) { if int(txzones[i]) >= len(zone) {
return nil, BadZoneinfo return NIL, BadZoneinfo
} }
zt[i].zone = &zone[txzones[i]]; zt[i].zone = &zone[txzones[i]];
if i < len(isstd) { if i < len(isstd) {
...@@ -198,10 +206,11 @@ func ParseZoneinfo(bytes *[]byte) (zt *[]Zonetime, err *os.Error) { ...@@ -198,10 +206,11 @@ func ParseZoneinfo(bytes *[]byte) (zt *[]Zonetime, err *os.Error) {
return zt, nil return zt, nil
} }
func ReadFile(name string, max int) (p *[]byte, err *os.Error) { func ReadFile(name string, max int) (p []byte, err *os.Error) {
var NIL []byte; // TODO(rsc)
fd, e := os.Open(name, os.O_RDONLY, 0); fd, e := os.Open(name, os.O_RDONLY, 0);
if e != nil { if e != nil {
return nil, e return NIL, e
} }
p = new([]byte, max+1)[0:0]; p = new([]byte, max+1)[0:0];
n := 0; n := 0;
...@@ -209,7 +218,7 @@ func ReadFile(name string, max int) (p *[]byte, err *os.Error) { ...@@ -209,7 +218,7 @@ func ReadFile(name string, max int) (p *[]byte, err *os.Error) {
nn, e := fd.Read(p[n:cap(p)]); nn, e := fd.Read(p[n:cap(p)]);
if e != nil { if e != nil {
fd.Close(); fd.Close();
return nil, e return NIL, e
} }
if nn == 0 { if nn == 0 {
fd.Close(); fd.Close();
...@@ -218,20 +227,21 @@ func ReadFile(name string, max int) (p *[]byte, err *os.Error) { ...@@ -218,20 +227,21 @@ func ReadFile(name string, max int) (p *[]byte, err *os.Error) {
p = p[0:n+nn] p = p[0:n+nn]
} }
fd.Close(); fd.Close();
return nil, BadZoneinfo // too long return NIL, BadZoneinfo // too long
} }
func ReadZoneinfoFile(name string) (tx *[]Zonetime, err *os.Error) { func ReadZoneinfoFile(name string) (tx []Zonetime, err *os.Error) {
var NIL []Zonetime; // TODO(rsc)
data, e := ReadFile(name, MaxFileSize); data, e := ReadFile(name, MaxFileSize);
if e != nil { if e != nil {
return nil, e return NIL, e
} }
tx, err = ParseZoneinfo(data); tx, err = ParseZoneinfo(data);
return tx, err return tx, err
} }
var zones *[]Zonetime var zones []Zonetime
var zoneerr *os.Error var zoneerr *os.Error
func SetupZone() { func SetupZone() {
...@@ -245,7 +255,7 @@ func SetupZone() { ...@@ -245,7 +255,7 @@ func SetupZone() {
export func LookupTimezone(sec int64) (zone string, offset int, err *os.Error) { export func LookupTimezone(sec int64) (zone string, offset int, err *os.Error) {
once.Do(&SetupZone); once.Do(&SetupZone);
if zoneerr != nil || zones == nil || len(zones) == 0 { if zoneerr != nil || len(zones) == 0 {
return "GMT", 0, zoneerr return "GMT", 0, zoneerr
} }
......
...@@ -32,7 +32,7 @@ const ( ...@@ -32,7 +32,7 @@ const (
Rune4Max = 1<<21 - 1; Rune4Max = 1<<21 - 1;
) )
func DecodeRuneInternal(p *[]byte) (rune, size int, short bool) { func DecodeRuneInternal(p []byte) (rune, size int, short bool) {
n := len(p); n := len(p);
if n < 1 { if n < 1 {
return RuneError, 0, true; return RuneError, 0, true;
...@@ -181,7 +181,7 @@ func DecodeRuneInStringInternal(s string, i int, n int) (rune, size int, short b ...@@ -181,7 +181,7 @@ func DecodeRuneInStringInternal(s string, i int, n int) (rune, size int, short b
return RuneError, 1, false return RuneError, 1, false
} }
export func FullRune(p *[]byte) bool { export func FullRune(p []byte) bool {
rune, size, short := DecodeRuneInternal(p); rune, size, short := DecodeRuneInternal(p);
return !short return !short
} }
...@@ -191,7 +191,7 @@ export func FullRuneInString(s string, i int) bool { ...@@ -191,7 +191,7 @@ export func FullRuneInString(s string, i int) bool {
return !short return !short
} }
export func DecodeRune(p *[]byte) (rune, size int) { export func DecodeRune(p []byte) (rune, size int) {
var short bool; var short bool;
rune, size, short = DecodeRuneInternal(p); rune, size, short = DecodeRuneInternal(p);
return; return;
...@@ -217,7 +217,7 @@ export func RuneLen(rune int) int { ...@@ -217,7 +217,7 @@ export func RuneLen(rune int) int {
return -1; return -1;
} }
export func EncodeRune(rune int, p *[]byte) int { export func EncodeRune(rune int, p []byte) int {
if rune <= Rune1Max { if rune <= Rune1Max {
p[0] = byte(rune); p[0] = byte(rune);
return 1; return 1;
...@@ -247,7 +247,7 @@ export func EncodeRune(rune int, p *[]byte) int { ...@@ -247,7 +247,7 @@ export func EncodeRune(rune int, p *[]byte) int {
return 4; return 4;
} }
export func RuneCount(p *[]byte) int { export func RuneCount(p []byte) int {
i := 0; i := 0;
var n int; var n int;
for n = 0; i < len(p); n++ { for n = 0; i < len(p); n++ {
......
...@@ -44,7 +44,7 @@ var utf8map = []Utf8Map { ...@@ -44,7 +44,7 @@ var utf8map = []Utf8Map {
Utf8Map{ 0x10ffff, "\xf4\x8f\xbf\xbf" }, Utf8Map{ 0x10ffff, "\xf4\x8f\xbf\xbf" },
} }
func Bytes(s string) *[]byte { func Bytes(s string) []byte {
b := new([]byte, len(s)+1); b := new([]byte, len(s)+1);
if !syscall.StringToBytes(b, s) { if !syscall.StringToBytes(b, s) {
panic("StringToBytes failed"); panic("StringToBytes failed");
...@@ -74,7 +74,7 @@ export func TestFullRune(t *testing.T) { ...@@ -74,7 +74,7 @@ export func TestFullRune(t *testing.T) {
} }
} }
func EqualBytes(a, b *[]byte) bool { func EqualBytes(a, b []byte) bool {
if len(a) != len(b) { if len(a) != len(b) {
return false; return false;
} }
...@@ -91,8 +91,8 @@ export func TestEncodeRune(t *testing.T) { ...@@ -91,8 +91,8 @@ export func TestEncodeRune(t *testing.T) {
m := utf8map[i]; m := utf8map[i];
b := Bytes(m.str); b := Bytes(m.str);
var buf [10]byte; var buf [10]byte;
n := utf8.EncodeRune(m.rune, &buf); n := utf8.EncodeRune(m.rune, buf);
b1 := (&buf)[0:n]; b1 := buf[0:n];
if !EqualBytes(b, b1) { if !EqualBytes(b, b1) {
t.Errorf("EncodeRune(0x%04x) = %q want %q", m.rune, b1, b); t.Errorf("EncodeRune(0x%04x) = %q want %q", m.rune, b1, b);
} }
......
...@@ -26,15 +26,16 @@ maketest() { ...@@ -26,15 +26,16 @@ maketest() {
maketest \ maketest \
lib/fmt\ lib/fmt\
lib/hash\ lib/hash\
lib/json\
lib/math\ lib/math\
lib/net\
lib/reflect\ lib/reflect\
lib/regexp\ lib/regexp\
lib/strconv\ lib/strconv\
lib/tabwriter\ lib/tabwriter\
lib/time\ lib/time\
# lib/json\
# lib/net\
# all of these are subtly different # all of these are subtly different
# from what maketest does. # from what maketest does.
......
...@@ -179,10 +179,10 @@ sys·byteastring(byte *a, int32 l, string s) ...@@ -179,10 +179,10 @@ sys·byteastring(byte *a, int32 l, string s)
} }
void void
sys·arraystring(Array *b, string s) sys·arraystring(Array b, string s)
{ {
s = mal(sizeof(s->len)+b->nel); s = mal(sizeof(s->len)+b.nel);
s->len = b->nel; s->len = b.nel;
mcpy(s->str, b->array, s->len); mcpy(s->str, b.array, s->len);
FLUSH(&s); FLUSH(&s);
} }
...@@ -20,7 +20,7 @@ func M(f uint64) (in, out *T) { ...@@ -20,7 +20,7 @@ func M(f uint64) (in, out *T) {
} }
func min(xs *[]uint64) uint64 { func min(xs []uint64) uint64 {
m := xs[0]; m := xs[0];
for i := 1; i < len(xs); i++ { for i := 1; i < len(xs); i++ {
if xs[i] < m { if xs[i] < m {
...@@ -33,7 +33,7 @@ func min(xs *[]uint64) uint64 { ...@@ -33,7 +33,7 @@ func min(xs *[]uint64) uint64 {
func main() { func main() {
F := []uint64{2, 3, 5}; F := []uint64{2, 3, 5};
const n = len(F); var n = len(F);
OUT := []uint64{ OUT := []uint64{
2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, 18, 20, 24, 25, 27, 30, 32, 36, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, 18, 20, 24, 25, 27, 30, 32, 36,
40, 45, 48, 50, 54, 60, 64, 72, 75, 80, 81, 90, 96, 100, 108, 120, 125, 40, 45, 48, 50, 54, 60, 64, 72, 75, 80, 81, 90, 96, 100, 108, 120, 125,
......
...@@ -124,7 +124,7 @@ func get(in *dch) *rat { ...@@ -124,7 +124,7 @@ func get(in *dch) *rat {
// Get one item from each of n demand channels // Get one item from each of n demand channels
func getn(in *[]*dch, n int) *[]item { func getn(in []*dch, n int) []item {
// BUG n:=len(in); // BUG n:=len(in);
if n != 2 { panic("bad n in getn") }; if n != 2 { panic("bad n in getn") };
req := new([2] *chan int); req := new([2] *chan int);
...@@ -159,7 +159,7 @@ func getn(in *[]*dch, n int) *[]item { ...@@ -159,7 +159,7 @@ func getn(in *[]*dch, n int) *[]item {
// Get one item from each of 2 demand channels // Get one item from each of 2 demand channels
func get2(in0 *dch, in1 *dch) *[]item { func get2(in0 *dch, in1 *dch) []item {
x := new([2] *dch); x := new([2] *dch);
x[0] = in0; x[0] = in0;
x[1] = in1; x[1] = in1;
...@@ -325,7 +325,7 @@ func Split(U PS) *dch2{ ...@@ -325,7 +325,7 @@ func Split(U PS) *dch2{
func Add(U, V PS) PS{ func Add(U, V PS) PS{
Z := mkPS(); Z := mkPS();
go func(U, V, Z PS){ go func(U, V, Z PS){
var uv *[] *rat; var uv [] *rat;
for { for {
<-Z.req; <-Z.req;
uv = get2(U,V); uv = get2(U,V);
...@@ -625,7 +625,7 @@ func check(U PS, c *rat, count int, str string) { ...@@ -625,7 +625,7 @@ func check(U PS, c *rat, count int, str string) {
} }
const N=10 const N=10
func checka(U PS, a *[]*rat, str string) { func checka(U PS, a []*rat, str string) {
for i := 0; i < N; i++ { for i := 0; i < N; i++ {
check(U, a[i], 1, str); check(U, a[i], 1, str);
} }
......
...@@ -129,7 +129,7 @@ func get(in *dch) *rat { ...@@ -129,7 +129,7 @@ func get(in *dch) *rat {
// Get one item from each of n demand channels // Get one item from each of n demand channels
func getn(in *[]*dch, n int) *[]item { func getn(in []*dch, n int) []item {
// BUG n:=len(in); // BUG n:=len(in);
if n != 2 { panic("bad n in getn") }; if n != 2 { panic("bad n in getn") };
req := new([2] *chan int); req := new([2] *chan int);
...@@ -164,7 +164,7 @@ func getn(in *[]*dch, n int) *[]item { ...@@ -164,7 +164,7 @@ func getn(in *[]*dch, n int) *[]item {
// Get one item from each of 2 demand channels // Get one item from each of 2 demand channels
func get2(in0 *dch, in1 *dch) *[]item { func get2(in0 *dch, in1 *dch) []item {
x := new([2] *dch); x := new([2] *dch);
x[0] = in0; x[0] = in0;
x[1] = in1; x[1] = in1;
...@@ -330,7 +330,7 @@ func Split(U PS) *dch2{ ...@@ -330,7 +330,7 @@ func Split(U PS) *dch2{
func Add(U, V PS) PS{ func Add(U, V PS) PS{
Z := mkPS(); Z := mkPS();
go func(U, V, Z PS){ go func(U, V, Z PS){
var uv *[] item; var uv [] item;
for { for {
<-Z.req; <-Z.req;
uv = get2(U,V); uv = get2(U,V);
...@@ -630,7 +630,7 @@ func check(U PS, c *rat, count int, str string) { ...@@ -630,7 +630,7 @@ func check(U PS, c *rat, count int, str string) {
} }
const N=10 const N=10
func checka(U PS, a *[]*rat, str string) { func checka(U PS, a []*rat, str string) {
for i := 0; i < N; i++ { for i := 0; i < N; i++ {
check(U, a[i], 1, str); check(U, a[i], 1, str);
} }
......
...@@ -16,7 +16,7 @@ func itor(a int) *R { ...@@ -16,7 +16,7 @@ func itor(a int) *R {
return r; return r;
} }
func eq(a *[]*R) { func eq(a []*R) {
for i := 0; i < len(a); i++ { for i := 0; i < len(a); i++ {
if a[i].num != i { panic("bad") } if a[i].num != i { panic("bad") }
} }
...@@ -41,7 +41,7 @@ func main() { ...@@ -41,7 +41,7 @@ func main() {
//a3 := [10]int{1,2,3,}; // BUG: trailing commas not allowed //a3 := [10]int{1,2,3,}; // BUG: trailing commas not allowed
//if len(a3) != 10 || a2[3] != 0 { panic("a3") } //if len(a3) != 10 || a2[3] != 0 { panic("a3") }
var oai *[]int; var oai []int;
oai = &[]int{1,2,3}; oai = &[]int{1,2,3};
if len(oai) != 3 { panic("oai") } if len(oai) != 3 { panic("oai") }
......
...@@ -11,7 +11,7 @@ type Element interface { ...@@ -11,7 +11,7 @@ type Element interface {
type Vector struct { type Vector struct {
nelem int; nelem int;
elem *[]Element; elem []Element;
} }
func New() *Vector { func New() *Vector {
......
...@@ -11,7 +11,7 @@ type T struct { ...@@ -11,7 +11,7 @@ type T struct {
} }
func main() { func main() {
var ta *[]*T; var ta []*T;
ta = new([1]*T); ta = new([1]*T);
ta[0] = nil; ta[0] = nil;
......
...@@ -10,7 +10,7 @@ type Element interface { ...@@ -10,7 +10,7 @@ type Element interface {
} }
type Vector struct { type Vector struct {
elem *[]Element; elem []Element;
} }
func (v *Vector) At(i int) Element { func (v *Vector) At(i int) Element {
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
package main package main
func P(a *[]string) string { func P(a []string) string {
s := "{"; s := "{";
for i := 0; i < 2; i++ { for i := 0; i < 2; i++ {
if i > 0 { if i > 0 {
...@@ -19,7 +19,7 @@ func P(a *[]string) string { ...@@ -19,7 +19,7 @@ func P(a *[]string) string {
} }
func main() { func main() {
m := new(map[string] *[]string); m := new(map[string] []string);
as := new([2]string); as := new([2]string);
as[0] = "0"; as[0] = "0";
as[1] = "1"; as[1] = "1";
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
package main package main
func foo(a *[]int) int { func foo(a []int) int {
return (*a)[0] // this seesm to do the wrong thing return (*a)[0] // this seesm to do the wrong thing
} }
......
...@@ -15,7 +15,7 @@ func f1(t1, t2, t3); ...@@ -15,7 +15,7 @@ func f1(t1, t2, t3);
func f2(t1, t2, t3 bool); func f2(t1, t2, t3 bool);
func f3(t1, t2, x t3); func f3(t1, t2, x t3);
func f4(t1, *t3); func f4(t1, *t3);
func (x *t1) f5(y *[]t2) (t1, *t3); func (x *t1) f5(y []t2) (t1, *t3);
func f6() (int, *string); func f6() (int, *string);
func f7(*t2, t3); func f7(*t2, t3);
func f8(os int) int; func f8(os int) int;
......
...@@ -29,7 +29,7 @@ var ( ...@@ -29,7 +29,7 @@ var (
type Matrix struct { type Matrix struct {
n, m int; n, m int;
a *[]*Big.Rational; a []*Big.Rational;
} }
......
...@@ -11,7 +11,7 @@ type Inst interface { ...@@ -11,7 +11,7 @@ type Inst interface {
} }
type Regexp struct { type Regexp struct {
code *[]Inst; code []Inst;
start Inst; start Inst;
} }
......
...@@ -10,7 +10,7 @@ import fmt "fmt" ...@@ -10,7 +10,7 @@ import fmt "fmt"
const arraylen = 2; // BUG: shouldn't need this const arraylen = 2; // BUG: shouldn't need this
func P(a *[]string) string { func P(a []string) string {
s := "{"; s := "{";
for i := 0; i < len(a); i++ { for i := 0; i < len(a); i++ {
if i > 0 { if i > 0 {
...@@ -34,7 +34,7 @@ func main() { ...@@ -34,7 +34,7 @@ func main() {
msi := new(map[string] int); msi := new(map[string] int);
mis := new(map[int] string); mis := new(map[int] string);
mss := new(map[string] string); mss := new(map[string] string);
mspa := new(map[string] *[]string); mspa := new(map[string] []string);
// BUG need an interface map both ways too // BUG need an interface map both ways too
type T struct { type T struct {
......
...@@ -21,7 +21,7 @@ func main() { ...@@ -21,7 +21,7 @@ func main() {
var c *chan int; var c *chan int;
var t *T; var t *T;
var in IN; var in IN;
var ta *[]IN; var ta []IN;
i = nil; i = nil;
f = nil; f = nil;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment