mirror of
https://github.com/golang/go
synced 2024-11-21 17:54:39 -07:00
change *map to map; *chan to chan; new(T) to new(*T)
fix bugs left over from *[] to [] conversion. TBR=r OCL=21576 CL=21581
This commit is contained in:
parent
d47d888ba6
commit
08ca30bbfa
@ -41,7 +41,7 @@ done
|
||||
set -e
|
||||
|
||||
# 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
|
||||
echo 'package main'
|
||||
|
@ -164,9 +164,9 @@ func (x *Natural) Add(y *Natural) *Natural {
|
||||
if n < m {
|
||||
return y.Add(x);
|
||||
}
|
||||
|
||||
|
||||
c := Digit(0);
|
||||
z := new(Natural, n + 1);
|
||||
z := new(*Natural, n + 1);
|
||||
i := 0;
|
||||
for i < m {
|
||||
t := c + x[i] + y[i];
|
||||
@ -193,9 +193,9 @@ func (x *Natural) Sub(y *Natural) *Natural {
|
||||
if n < m {
|
||||
panic("underflow")
|
||||
}
|
||||
|
||||
|
||||
c := Digit(0);
|
||||
z := new(Natural, n);
|
||||
z := new(*Natural, n);
|
||||
i := 0;
|
||||
for i < m {
|
||||
t := c + x[i] - y[i];
|
||||
@ -253,7 +253,7 @@ func (x *Natural) Mul(y *Natural) *Natural {
|
||||
n := len(x);
|
||||
m := len(y);
|
||||
|
||||
z := new(Natural, n + m);
|
||||
z := new(*Natural, n + m);
|
||||
for j := 0; j < m; j++ {
|
||||
d := y[j];
|
||||
if d != 0 {
|
||||
@ -296,7 +296,7 @@ func Unpack(x *Natural) []Digit2 {
|
||||
|
||||
func Pack(x []Digit2) *Natural {
|
||||
n := (len(x) + 1) / 2;
|
||||
z := new(Natural, n);
|
||||
z := new(*Natural, n);
|
||||
if len(x) & 1 == 1 {
|
||||
// handle odd len(x)
|
||||
n--;
|
||||
@ -376,7 +376,7 @@ func DivMod(x, y []Digit2) ([]Digit2, []Digit2) {
|
||||
} else {
|
||||
// general case
|
||||
assert(2 <= m && m <= n);
|
||||
|
||||
|
||||
// normalize x and y
|
||||
// TODO Instead of multiplying, it would be sufficient to
|
||||
// shift y such that the normalization condition is
|
||||
@ -472,7 +472,7 @@ func Shl(z, x []Digit, s uint) Digit {
|
||||
func (x *Natural) Shl(s uint) *Natural {
|
||||
n := uint(len(x));
|
||||
m := n + s/W;
|
||||
z := new(Natural, m+1);
|
||||
z := new(*Natural, m+1);
|
||||
|
||||
z[m] = Shl(z[m-n : m], x, s%W);
|
||||
|
||||
@ -497,7 +497,7 @@ func (x *Natural) Shr(s uint) *Natural {
|
||||
if m > n { // check for underflow
|
||||
m = 0;
|
||||
}
|
||||
z := new(Natural, m);
|
||||
z := new(*Natural, m);
|
||||
|
||||
Shr(z, x[n-m : n], s%W);
|
||||
|
||||
@ -512,7 +512,7 @@ func (x *Natural) And(y *Natural) *Natural {
|
||||
return y.And(x);
|
||||
}
|
||||
|
||||
z := new(Natural, m);
|
||||
z := new(*Natural, m);
|
||||
for i := 0; i < m; i++ {
|
||||
z[i] = x[i] & y[i];
|
||||
}
|
||||
@ -536,7 +536,7 @@ func (x *Natural) Or(y *Natural) *Natural {
|
||||
return y.Or(x);
|
||||
}
|
||||
|
||||
z := new(Natural, n);
|
||||
z := new(*Natural, n);
|
||||
for i := 0; i < m; i++ {
|
||||
z[i] = x[i] | y[i];
|
||||
}
|
||||
@ -553,7 +553,7 @@ func (x *Natural) Xor(y *Natural) *Natural {
|
||||
return y.Xor(x);
|
||||
}
|
||||
|
||||
z := new(Natural, n);
|
||||
z := new(*Natural, n);
|
||||
for i := 0; i < m; i++ {
|
||||
z[i] = x[i] ^ y[i];
|
||||
}
|
||||
@ -630,7 +630,7 @@ func (x *Natural) ToString(base uint) string {
|
||||
s := new([]byte, n);
|
||||
|
||||
// don't destroy x
|
||||
t := new(Natural, len(x));
|
||||
t := new(*Natural, len(x));
|
||||
Copy(t, x);
|
||||
|
||||
// convert
|
||||
@ -682,7 +682,7 @@ func HexValue(ch byte) uint {
|
||||
func MulAdd1(x *Natural, d, c Digit) *Natural {
|
||||
assert(IsSmall(d-1) && IsSmall(c));
|
||||
n := len(x);
|
||||
z := new(Natural, n + 1);
|
||||
z := new(*Natural, n + 1);
|
||||
|
||||
for i := 0; i < n; i++ {
|
||||
t := c + x[i]*d;
|
||||
@ -1088,7 +1088,7 @@ func (x *Integer) ToString(base uint) string {
|
||||
return s + x.mant.ToString(base);
|
||||
}
|
||||
|
||||
|
||||
|
||||
func (x *Integer) String() string {
|
||||
return x.ToString(10);
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ export func NewBufReadSize(rd io.Read, size int) (b *BufRead, err *os.Error) {
|
||||
if size <= 0 {
|
||||
return nil, BadBufSize
|
||||
}
|
||||
b = new(BufRead);
|
||||
b = new(*BufRead);
|
||||
b.buf = new([]byte, size);
|
||||
b.rd = rd;
|
||||
return b, nil
|
||||
@ -191,11 +191,9 @@ func (b *BufRead) Buffered() int {
|
||||
// For internal (or advanced) use only.
|
||||
// Use ReadLineString or ReadLineBytes instead.
|
||||
|
||||
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 {
|
||||
return NIL, b.err
|
||||
return nil, b.err
|
||||
}
|
||||
|
||||
// Look in buffer.
|
||||
@ -210,7 +208,7 @@ func (b *BufRead) ReadLineSlice(delim byte) (line []byte, err *os.Error) {
|
||||
n := b.Buffered();
|
||||
b.Fill();
|
||||
if b.err != nil {
|
||||
return NIL, b.err
|
||||
return nil, b.err
|
||||
}
|
||||
if b.Buffered() == n { // no data added; end of file
|
||||
line := b.buf[b.r:b.w];
|
||||
@ -227,12 +225,12 @@ func (b *BufRead) ReadLineSlice(delim byte) (line []byte, err *os.Error) {
|
||||
|
||||
// Buffer is full?
|
||||
if b.Buffered() >= len(b.buf) {
|
||||
return NIL, BufferFull
|
||||
return nil, BufferFull
|
||||
}
|
||||
}
|
||||
|
||||
// BUG 6g bug100
|
||||
return NIL, nil
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// Read until the first occurrence of delim in the input,
|
||||
@ -242,7 +240,7 @@ func (b *BufRead) ReadLineSlice(delim byte) (line []byte, err *os.Error) {
|
||||
// we might have read more than the buffer size.)
|
||||
func (b *BufRead) ReadLineBytes(delim byte) (line []byte, err *os.Error) {
|
||||
if b.err != nil {
|
||||
return NIL, b.err
|
||||
return nil, b.err
|
||||
}
|
||||
|
||||
// Use ReadLineSlice to look for array,
|
||||
@ -279,7 +277,7 @@ func (b *BufRead) ReadLineBytes(delim byte) (line []byte, err *os.Error) {
|
||||
}
|
||||
|
||||
// Grow list if needed.
|
||||
if len(full) == 0 {
|
||||
if full == nil {
|
||||
full = new([][]byte, 16);
|
||||
} else if nfull >= len(full) {
|
||||
newfull := new([][]byte, len(full)*2);
|
||||
@ -313,26 +311,18 @@ func (b *BufRead) ReadLineBytes(delim byte) (line []byte, err *os.Error) {
|
||||
return buf, err
|
||||
}
|
||||
|
||||
// BUG(bugs/bug102.go): string(empty bytes array) throws error
|
||||
func ToString(p []byte) string {
|
||||
if len(p) == 0 {
|
||||
return ""
|
||||
}
|
||||
return string(p)
|
||||
}
|
||||
|
||||
// Read until the first occurrence of delim in the input,
|
||||
// returning a new string containing the line.
|
||||
// If savedelim, keep delim in the result; otherwise chop it off.
|
||||
func (b *BufRead) ReadLineString(delim byte, savedelim bool) (line string, err *os.Error) {
|
||||
bytes, e := b.ReadLineBytes(delim);
|
||||
if e != nil {
|
||||
return ToString(bytes), e
|
||||
return string(bytes), e
|
||||
}
|
||||
if !savedelim {
|
||||
bytes = bytes[0:len(bytes)-1]
|
||||
}
|
||||
return ToString(bytes), nil
|
||||
return string(bytes), nil
|
||||
}
|
||||
|
||||
|
||||
@ -349,7 +339,7 @@ export func NewBufWriteSize(wr io.Write, size int) (b *BufWrite, err *os.Error)
|
||||
if size <= 0 {
|
||||
return nil, BadBufSize
|
||||
}
|
||||
b = new(BufWrite);
|
||||
b = new(*BufWrite);
|
||||
b.buf = new([]byte, size);
|
||||
b.wr = wr;
|
||||
return b, nil
|
||||
|
@ -34,7 +34,7 @@ type ByteReader struct {
|
||||
}
|
||||
|
||||
func NewByteReader(p []byte) io.Read {
|
||||
b := new(ByteReader);
|
||||
b := new(*ByteReader);
|
||||
b.p = p;
|
||||
return b
|
||||
}
|
||||
@ -56,7 +56,7 @@ type HalfByteReader struct {
|
||||
}
|
||||
|
||||
func NewHalfByteReader(p []byte) io.Read {
|
||||
b := new(HalfByteReader);
|
||||
b := new(*HalfByteReader);
|
||||
b.p = p;
|
||||
return b
|
||||
}
|
||||
@ -80,7 +80,7 @@ type Rot13Reader struct {
|
||||
}
|
||||
|
||||
func NewRot13Reader(r io.Read) *Rot13Reader {
|
||||
r13 := new(Rot13Reader);
|
||||
r13 := new(*Rot13Reader);
|
||||
r13.r = r;
|
||||
return r13
|
||||
}
|
||||
@ -238,7 +238,7 @@ type ByteWriter struct {
|
||||
}
|
||||
|
||||
func NewByteWriter() WriteBuffer {
|
||||
return new(ByteWriter)
|
||||
return new(*ByteWriter)
|
||||
}
|
||||
|
||||
func (w *ByteWriter) Write(p []byte) (int, *os.Error) {
|
||||
@ -266,7 +266,7 @@ type HalfByteWriter struct {
|
||||
}
|
||||
|
||||
func NewHalfByteWriter() WriteBuffer {
|
||||
w := new(HalfByteWriter);
|
||||
w := new(*HalfByteWriter);
|
||||
w.bw = NewByteWriter();
|
||||
return w
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ func (p *Array) Init(initial_len int) *Array {
|
||||
|
||||
|
||||
export func New(len int) *Array {
|
||||
return new(Array).Init(len)
|
||||
return new(*Array).Init(len)
|
||||
}
|
||||
|
||||
|
||||
|
@ -19,7 +19,7 @@ func (p *IntArray) Init(len int) *IntArray {
|
||||
|
||||
|
||||
export func NewIntArray(len int) *IntArray {
|
||||
return new(IntArray).Init(len)
|
||||
return new(*IntArray).Init(len)
|
||||
}
|
||||
|
||||
|
||||
|
@ -289,8 +289,8 @@ export type Flag struct {
|
||||
}
|
||||
|
||||
type Flags struct {
|
||||
actual *map[string] *Flag;
|
||||
formal *map[string] *Flag;
|
||||
actual map[string] *Flag;
|
||||
formal map[string] *Flag;
|
||||
first_arg int;
|
||||
flag_list *Flag; // BUG: remove when we can iterate over maps
|
||||
}
|
||||
@ -318,7 +318,7 @@ func (f *Flag) SVal() string {
|
||||
}
|
||||
|
||||
func New() *Flags {
|
||||
f := new(Flags);
|
||||
f := new(*Flags);
|
||||
f.first_arg = 1; // 0 is the program name, 1 is first arg
|
||||
f.actual = new(map[string] *Flag);
|
||||
f.formal = new(map[string] *Flag);
|
||||
@ -361,7 +361,7 @@ export func NArg() int {
|
||||
}
|
||||
|
||||
func Add(name string, value Value, usage string) *Flag {
|
||||
f := new(Flag);
|
||||
f := new(*Flag);
|
||||
f.name = name;
|
||||
f.usage = usage;
|
||||
f.value = value;
|
||||
|
@ -2,7 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Adler-32 checksum.
|
||||
// Adler-32 checksum.
|
||||
// Defined in RFC 1950:
|
||||
// Adler-32 is composed of two sums accumulated per byte: s1 is
|
||||
// the sum of all bytes, s2 is the sum of all s1 values. Both sums
|
||||
|
@ -25,7 +25,7 @@ export const (
|
||||
Koopman = 0xeb31d82e;
|
||||
)
|
||||
|
||||
// TODO(rsc): Change to [256]uint32
|
||||
// TODO(rsc): Change to [256]uint32 once 6g can handle it.
|
||||
export type Table []uint32
|
||||
|
||||
export func MakeTable(poly uint32) Table {
|
||||
|
@ -27,7 +27,7 @@ export type Digest struct {
|
||||
}
|
||||
|
||||
export func NewDigest() *Digest {
|
||||
d := new(Digest);
|
||||
d := new(*Digest);
|
||||
d.s[0] = A;
|
||||
d.s[1] = B;
|
||||
d.s[2] = C;
|
||||
|
@ -28,7 +28,7 @@ export type Digest struct {
|
||||
}
|
||||
|
||||
export func NewDigest() *Digest {
|
||||
d := new(Digest);
|
||||
d := new(*Digest);
|
||||
d.h[0] = H0;
|
||||
d.h[1] = H1;
|
||||
d.h[2] = H2;
|
||||
|
@ -22,7 +22,7 @@ export type Conn struct {
|
||||
|
||||
// Create new connection from rwc.
|
||||
export func NewConn(rwc io.ReadWriteClose) (c *Conn, err *os.Error) {
|
||||
c = new(Conn);
|
||||
c = new(*Conn);
|
||||
c.rwc = rwc;
|
||||
if c.br, err = bufio.NewBufRead(rwc); err != nil {
|
||||
return nil, err
|
||||
|
@ -37,7 +37,7 @@ export type Request struct {
|
||||
pmajor int; // 1
|
||||
pminor int; // 0
|
||||
|
||||
header *map[string] string;
|
||||
header map[string] string;
|
||||
|
||||
close bool;
|
||||
host string;
|
||||
@ -45,18 +45,16 @@ export type Request struct {
|
||||
useragent string;
|
||||
}
|
||||
|
||||
var NIL []byte // TODO(rsc)
|
||||
|
||||
// Read a line of bytes (up to \n) from b.
|
||||
// Give up if the line exceeds MaxLineLength.
|
||||
// The returned bytes are a pointer into storage in
|
||||
// the bufio, so they are only valid until the next bufio read.
|
||||
func ReadLineBytes(b *bufio.BufRead) (p []byte, err *os.Error) {
|
||||
if p, err = b.ReadLineSlice('\n'); err != nil {
|
||||
return NIL, err
|
||||
return nil, err
|
||||
}
|
||||
if len(p) >= MaxLineLength {
|
||||
return NIL, LineTooLong
|
||||
return nil, LineTooLong
|
||||
}
|
||||
|
||||
// Chop off trailing white space.
|
||||
@ -183,7 +181,7 @@ func ParseHTTPVersion(vers string) (int, int, bool) {
|
||||
|
||||
// Read and parse a request from b.
|
||||
export func ReadRequest(b *bufio.BufRead) (req *Request, err *os.Error) {
|
||||
req = new(Request);
|
||||
req = new(*Request);
|
||||
|
||||
// First line: GET /index.html HTTP/1.0
|
||||
var s string;
|
||||
|
@ -131,7 +131,7 @@ export func ParseURL(rawurl string) (url *URL, err *os.Error) {
|
||||
if rawurl == "" {
|
||||
return nil, BadURL
|
||||
}
|
||||
url = new(URL);
|
||||
url = new(*URL);
|
||||
url.raw = rawurl;
|
||||
|
||||
// Split off possible leading "http:", "mailto:", etc.
|
||||
|
@ -81,7 +81,7 @@ func (b *ByteBuffer) Data() []byte {
|
||||
|
||||
|
||||
export func NewByteBufferFromArray(buf []byte) *ByteBuffer {
|
||||
b := new(ByteBuffer);
|
||||
b := new(*ByteBuffer);
|
||||
b.buf = buf;
|
||||
b.off = 0;
|
||||
b.len = len(buf);
|
||||
|
@ -99,7 +99,7 @@ func (j *Bool) String() string {
|
||||
return "false"
|
||||
}
|
||||
|
||||
type Map struct { m *map[string]Json; Null }
|
||||
type Map struct { m map[string]Json; Null }
|
||||
func (j *Map) Kind() int { return MapKind }
|
||||
func (j *Map) Get(s string) Json {
|
||||
if j.m == nil {
|
||||
@ -212,7 +212,7 @@ type JsonBuilder struct {
|
||||
i int;
|
||||
|
||||
// or to m[k] (can't set ptr = &m[k])
|
||||
m *map[string] Json;
|
||||
m map[string] Json;
|
||||
k string;
|
||||
}
|
||||
|
||||
@ -273,7 +273,7 @@ func (b *JsonBuilder) Map() {
|
||||
}
|
||||
|
||||
func (b *JsonBuilder) Elem(i int) Builder {
|
||||
bb := new(JsonBuilder);
|
||||
bb := new(*JsonBuilder);
|
||||
bb.a = b.Get().(*Array).a;
|
||||
bb.i = i;
|
||||
for i >= bb.a.Len() {
|
||||
@ -283,7 +283,7 @@ func (b *JsonBuilder) Elem(i int) Builder {
|
||||
}
|
||||
|
||||
func (b *JsonBuilder) Key(k string) Builder {
|
||||
bb := new(JsonBuilder);
|
||||
bb := new(*JsonBuilder);
|
||||
bb.m = b.Get().(*Map).m;
|
||||
bb.k = k;
|
||||
bb.m[k] = null;
|
||||
@ -293,7 +293,7 @@ func (b *JsonBuilder) Key(k string) Builder {
|
||||
export func StringToJson(s string) (json Json, ok bool, errtok string) {
|
||||
var errindx int;
|
||||
var j Json;
|
||||
b := new(JsonBuilder);
|
||||
b := new(*JsonBuilder);
|
||||
b.ptr = &j;
|
||||
ok, errindx, errtok = Parse(s, b);
|
||||
if !ok {
|
||||
|
@ -120,7 +120,7 @@ export func Unquote(s string) (t string, ok bool) {
|
||||
export func Quote(s string) string {
|
||||
chr := new([]byte, utf8.UTFMax);
|
||||
chr0 := chr[0:1];
|
||||
b := new(io.ByteBuffer);
|
||||
b := new(*io.ByteBuffer);
|
||||
chr[0] = '"';
|
||||
b.Write(chr0);
|
||||
for i := 0; i < len(s); i++ {
|
||||
@ -387,7 +387,7 @@ Switch:
|
||||
}
|
||||
|
||||
export func Parse(s string, build Builder) (ok bool, errindx int, errtok string) {
|
||||
lex := new(Lexer);
|
||||
lex := new(*Lexer);
|
||||
lex.s = s;
|
||||
lex.Next();
|
||||
if ParseValue(lex, build) {
|
||||
|
@ -26,7 +26,7 @@ type MyStruct struct {
|
||||
fl float;
|
||||
fl32 float32;
|
||||
fl64 float64;
|
||||
a []string;
|
||||
a *[]string; // TODO(rsc): Should be able to use []string.
|
||||
my *MyStruct;
|
||||
};
|
||||
|
||||
@ -69,7 +69,7 @@ export func TestUnmarshal(t *testing.T) {
|
||||
Check(t, m.fl==11.5, "fl", m.fl);
|
||||
Check(t, m.fl32==12.25, "fl32", m.fl32);
|
||||
Check(t, m.fl64==13.75, "fl64", m.fl64);
|
||||
// Check(t, m.a!=nil, "a", m.a); // TODO(rsc): uncomment once []string as interface works
|
||||
Check(t, m.a!=nil, "a", m.a);
|
||||
if m.a != nil {
|
||||
Check(t, m.a[0]=="x", "a[0]", m.a[0]);
|
||||
Check(t, m.a[1]=="y", "a[1]", m.a[1]);
|
||||
|
@ -22,7 +22,7 @@ func FetchGoogle(t *testing.T, fd net.Conn, network, addr string) {
|
||||
req := io.StringBytes("GET / HTTP/1.0\r\nHost: www.google.com\r\n\r\n");
|
||||
n, errno := fd.Write(req);
|
||||
|
||||
buf := new([1000]byte);
|
||||
buf := new([]byte, 1000);
|
||||
n, errno = io.Readn(fd, buf);
|
||||
|
||||
if n < 1000 {
|
||||
|
@ -44,7 +44,7 @@ func Exchange(cfg *DNS_Config, c Conn, name string) (m *DNS_Msg, err *os.Error)
|
||||
if len(name) >= 256 {
|
||||
return nil, DNS_NameTooLong
|
||||
}
|
||||
out := new(DNS_Msg);
|
||||
out := new(*DNS_Msg);
|
||||
out.id = 0x1234;
|
||||
out.question = []DNS_Question{
|
||||
DNS_Question{ name, DNS_TypeA, DNS_ClassINET }
|
||||
@ -71,7 +71,7 @@ func Exchange(cfg *DNS_Config, c Conn, name string) (m *DNS_Msg, err *os.Error)
|
||||
continue
|
||||
}
|
||||
buf = buf[0:n];
|
||||
in := new(DNS_Msg);
|
||||
in := new(*DNS_Msg);
|
||||
if !in.Unpack(buf) || in.id != out.id {
|
||||
continue
|
||||
}
|
||||
@ -80,24 +80,22 @@ func Exchange(cfg *DNS_Config, c Conn, name string) (m *DNS_Msg, err *os.Error)
|
||||
return nil, DNS_NoAnswer
|
||||
}
|
||||
|
||||
var NIL []string // TODO(rsc)
|
||||
|
||||
|
||||
// Find answer for name in dns message.
|
||||
// On return, if err == nil, addrs != nil.
|
||||
// TODO(rsc): Maybe return [][]byte (==[]IPAddr) instead?
|
||||
func Answer(name string, dns *DNS_Msg) (addrs []string, err *os.Error) {
|
||||
addrs = new([]string, len(dns.answer))[0:0];
|
||||
addrs = new([]string, 0, len(dns.answer));
|
||||
|
||||
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 {
|
||||
// None of the error codes make sense
|
||||
// for the query we sent. If we didn't get
|
||||
// a name error and we didn't get success,
|
||||
// the server is behaving incorrectly.
|
||||
return NIL, DNS_ServerFailure
|
||||
return nil, DNS_ServerFailure
|
||||
}
|
||||
|
||||
// Look for the name.
|
||||
@ -126,13 +124,13 @@ Cname:
|
||||
}
|
||||
}
|
||||
if len(addrs) == 0 {
|
||||
return NIL, DNS_NameNotFound
|
||||
return nil, DNS_NameNotFound
|
||||
}
|
||||
return addrs, nil
|
||||
}
|
||||
|
||||
// Too many redirects
|
||||
return NIL, DNS_RedirectLoop
|
||||
return nil, DNS_RedirectLoop
|
||||
}
|
||||
|
||||
// Do a lookup for a single name, which must be rooted
|
||||
|
@ -31,7 +31,7 @@ export func DNS_ReadConfig() *DNS_Config {
|
||||
if file == nil {
|
||||
return nil
|
||||
}
|
||||
conf := new(DNS_Config);
|
||||
conf := new(*DNS_Config);
|
||||
conf.servers = new([]string, 3)[0:0]; // small, but the standard limit
|
||||
conf.search = new([]string, 0);
|
||||
conf.ndots = 1;
|
||||
|
@ -198,18 +198,18 @@ export type DNS_RR_A struct {
|
||||
|
||||
// Map of constructors for each RR wire type.
|
||||
var rr_mk = map[int]*()DNS_RR {
|
||||
DNS_TypeCNAME: func() DNS_RR { return new(DNS_RR_CNAME) },
|
||||
DNS_TypeHINFO: func() DNS_RR { return new(DNS_RR_HINFO) },
|
||||
DNS_TypeMB: func() DNS_RR { return new(DNS_RR_MB) },
|
||||
DNS_TypeMG: func() DNS_RR { return new(DNS_RR_MG) },
|
||||
DNS_TypeMINFO: func() DNS_RR { return new(DNS_RR_MINFO) },
|
||||
DNS_TypeMR: func() DNS_RR { return new(DNS_RR_MR) },
|
||||
DNS_TypeMX: func() DNS_RR { return new(DNS_RR_MX) },
|
||||
DNS_TypeNS: func() DNS_RR { return new(DNS_RR_NS) },
|
||||
DNS_TypePTR: func() DNS_RR { return new(DNS_RR_PTR) },
|
||||
DNS_TypeSOA: func() DNS_RR { return new(DNS_RR_SOA) },
|
||||
DNS_TypeTXT: func() DNS_RR { return new(DNS_RR_TXT) },
|
||||
DNS_TypeA: func() DNS_RR { return new(DNS_RR_A) },
|
||||
DNS_TypeCNAME: func() DNS_RR { return new(*DNS_RR_CNAME) },
|
||||
DNS_TypeHINFO: func() DNS_RR { return new(*DNS_RR_HINFO) },
|
||||
DNS_TypeMB: func() DNS_RR { return new(*DNS_RR_MB) },
|
||||
DNS_TypeMG: func() DNS_RR { return new(*DNS_RR_MG) },
|
||||
DNS_TypeMINFO: func() DNS_RR { return new(*DNS_RR_MINFO) },
|
||||
DNS_TypeMR: func() DNS_RR { return new(*DNS_RR_MR) },
|
||||
DNS_TypeMX: func() DNS_RR { return new(*DNS_RR_MX) },
|
||||
DNS_TypeNS: func() DNS_RR { return new(*DNS_RR_NS) },
|
||||
DNS_TypePTR: func() DNS_RR { return new(*DNS_RR_PTR) },
|
||||
DNS_TypeSOA: func() DNS_RR { return new(*DNS_RR_SOA) },
|
||||
DNS_TypeTXT: func() DNS_RR { return new(*DNS_RR_TXT) },
|
||||
DNS_TypeA: func() DNS_RR { return new(*DNS_RR_A) },
|
||||
}
|
||||
|
||||
// Pack a domain name s into msg[off:].
|
||||
@ -545,7 +545,6 @@ export type DNS_Msg struct {
|
||||
extra []DNS_RR;
|
||||
}
|
||||
|
||||
var NIL []byte // TODO(rsc): remove
|
||||
|
||||
func (dns *DNS_Msg) Pack() (msg []byte, ok bool) {
|
||||
var dh DNS_Header;
|
||||
@ -569,9 +568,11 @@ func (dns *DNS_Msg) Pack() (msg []byte, ok bool) {
|
||||
dh.bits |= QR;
|
||||
}
|
||||
|
||||
// Prepare variable sized arrays; paper over nils.
|
||||
var question []DNS_Question;
|
||||
var answer, ns, extra []DNS_RR;
|
||||
// Prepare variable sized arrays.
|
||||
question := dns.question;
|
||||
answer := dns.answer;
|
||||
ns := dns.ns;
|
||||
extra := dns.extra;
|
||||
|
||||
dh.qdcount = uint16(len(question));
|
||||
dh.ancount = uint16(len(answer));
|
||||
@ -599,7 +600,7 @@ func (dns *DNS_Msg) Pack() (msg []byte, ok bool) {
|
||||
off, ok = PackStruct(extra[i], msg, off);
|
||||
}
|
||||
if !ok {
|
||||
return NIL, false
|
||||
return nil, false
|
||||
}
|
||||
return msg[0:off], true
|
||||
}
|
||||
|
@ -19,8 +19,8 @@ export type FD struct {
|
||||
// immutable until Close
|
||||
fd int64;
|
||||
osfd *os.FD;
|
||||
cr *chan *FD;
|
||||
cw *chan *FD;
|
||||
cr chan *FD;
|
||||
cw chan *FD;
|
||||
|
||||
// owned by fd wait server
|
||||
ncr, ncw int;
|
||||
@ -70,15 +70,15 @@ func SetNonblock(fd int64) *os.Error {
|
||||
// might help batch requests.
|
||||
|
||||
type PollServer struct {
|
||||
cr, cw *chan *FD; // buffered >= 1
|
||||
cr, cw chan *FD; // buffered >= 1
|
||||
pr, pw *os.FD;
|
||||
pending *map[int64] *FD;
|
||||
pending map[int64] *FD;
|
||||
poll *Pollster; // low-level OS hooks
|
||||
}
|
||||
func (s *PollServer) Run();
|
||||
|
||||
func NewPollServer() (s *PollServer, err *os.Error) {
|
||||
s = new(PollServer);
|
||||
s = new(*PollServer);
|
||||
s.cr = new(chan *FD, 1);
|
||||
s.cw = new(chan *FD, 1);
|
||||
if s.pr, s.pw, err = os.Pipe(); err != nil {
|
||||
@ -214,7 +214,7 @@ export func NewFD(fd int64) (f *FD, err *os.Error) {
|
||||
if err = SetNonblock(fd); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
f = new(FD);
|
||||
f = new(*FD);
|
||||
f.fd = fd;
|
||||
f.osfd = os.NewFD(fd);
|
||||
f.cr = new(chan *FD, 1);
|
||||
|
@ -18,10 +18,8 @@ export type Pollster struct {
|
||||
events []syscall.Kevent;
|
||||
}
|
||||
|
||||
var NIL []syscall.Kevent; // TODO(rsc): remove
|
||||
|
||||
export func NewPollster() (p *Pollster, err *os.Error) {
|
||||
p = new(Pollster);
|
||||
p = new(*Pollster);
|
||||
var e int64;
|
||||
if p.kq, e = syscall.kqueue(); e != 0 {
|
||||
return nil, os.ErrnoToError(e)
|
||||
@ -66,7 +64,7 @@ func (p *Pollster) AddFD(fd int64, mode int, repeat bool) *os.Error {
|
||||
|
||||
func (p *Pollster) WaitFD() (fd int64, mode int, err *os.Error) {
|
||||
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 == syscall.EAGAIN || e == syscall.EINTR {
|
||||
continue
|
||||
|
@ -21,11 +21,11 @@ export type Pollster struct {
|
||||
epfd int64;
|
||||
|
||||
// Events we're already waiting for
|
||||
events *map[int64] uint32;
|
||||
events map[int64] uint32;
|
||||
}
|
||||
|
||||
export func NewPollster() (p *Pollster, err *os.Error) {
|
||||
p = new(Pollster);
|
||||
p = new(*Pollster);
|
||||
var e int64;
|
||||
|
||||
// The arg to epoll_create is a hint to the kernel
|
||||
@ -102,9 +102,9 @@ func (p *Pollster) WaitFD() (fd int64, mode int, err *os.Error) {
|
||||
// Get an event.
|
||||
var evarray [1]syscall.EpollEvent;
|
||||
ev := &evarray[0];
|
||||
n, e := syscall.epoll_wait(p.epfd, &evarray, -1);
|
||||
n, e := syscall.epoll_wait(p.epfd, evarray, -1);
|
||||
for e == syscall.EAGAIN || e == syscall.EINTR {
|
||||
n, e = syscall.epoll_wait(p.epfd, &evarray, -1)
|
||||
n, e = syscall.epoll_wait(p.epfd, evarray, -1)
|
||||
}
|
||||
if e != 0 {
|
||||
return -1, 0, os.ErrnoToError(e)
|
||||
|
@ -39,8 +39,6 @@ func MakeIPv4(a, b, c, d byte) []byte {
|
||||
// Well-known IP addresses
|
||||
export var IPv4bcast, IPv4allsys, IPv4allrouter, IPv4prefix, IPallbits, IPnoaddr []byte
|
||||
|
||||
var NIL []byte // TODO(rsc)
|
||||
|
||||
func init() {
|
||||
IPv4bcast = MakeIPv4(0xff, 0xff, 0xff, 0xff);
|
||||
IPv4allsys = MakeIPv4(0xe0, 0x00, 0x00, 0x01);
|
||||
@ -75,7 +73,7 @@ export func ToIPv4(p []byte) []byte {
|
||||
&& p[11] == 0xff {
|
||||
return p[12:16]
|
||||
}
|
||||
return NIL
|
||||
return nil
|
||||
}
|
||||
|
||||
// Convert p to IPv6 form.
|
||||
@ -86,7 +84,7 @@ export func ToIPv6(p []byte) []byte {
|
||||
if len(p) == IPv6len {
|
||||
return p
|
||||
}
|
||||
return NIL
|
||||
return nil
|
||||
}
|
||||
|
||||
// Default route masks for IPv4.
|
||||
@ -97,8 +95,8 @@ export var (
|
||||
)
|
||||
|
||||
export func DefaultMask(p []byte) []byte {
|
||||
if p = ToIPv4(p); len(p) == 0 {
|
||||
return NIL
|
||||
if p = ToIPv4(p); p == nil {
|
||||
return nil
|
||||
}
|
||||
switch true {
|
||||
case p[0] < 0x80:
|
||||
@ -108,14 +106,14 @@ export func DefaultMask(p []byte) []byte {
|
||||
default:
|
||||
return ClassCMask;
|
||||
}
|
||||
return NIL; // not reached
|
||||
return nil; // not reached
|
||||
}
|
||||
|
||||
// Apply mask to ip, returning new address.
|
||||
export func Mask(ip []byte, mask []byte) []byte {
|
||||
n := len(ip);
|
||||
if n != len(mask) {
|
||||
return NIL
|
||||
return nil
|
||||
}
|
||||
out := new([]byte, n);
|
||||
for i := 0; i < n; i++ {
|
||||
@ -253,7 +251,7 @@ func ParseIPv4(s string) []byte {
|
||||
for j := 0; j < IPv4len; j++ {
|
||||
if j > 0 {
|
||||
if s[i] != '.' {
|
||||
return NIL
|
||||
return nil
|
||||
}
|
||||
i++;
|
||||
}
|
||||
@ -263,12 +261,12 @@ func ParseIPv4(s string) []byte {
|
||||
)
|
||||
n, i, ok = Dtoi(s, i);
|
||||
if !ok || n > 0xFF {
|
||||
return NIL
|
||||
return nil
|
||||
}
|
||||
p[j] = byte(n)
|
||||
}
|
||||
if i != len(s) {
|
||||
return NIL
|
||||
return nil
|
||||
}
|
||||
return MakeIPv4(p[0], p[1], p[2], p[3])
|
||||
}
|
||||
@ -302,22 +300,22 @@ L: for j < IPv6len {
|
||||
// Hex number.
|
||||
n, i1, ok := Xtoi(s, i);
|
||||
if !ok || n > 0xFFFF {
|
||||
return NIL
|
||||
return nil
|
||||
}
|
||||
|
||||
// If followed by dot, might be in trailing IPv4.
|
||||
if i1 < len(s) && s[i1] == '.' {
|
||||
if ellipsis < 0 && j != IPv6len - IPv4len {
|
||||
// Not the right place.
|
||||
return NIL
|
||||
return nil
|
||||
}
|
||||
if j+IPv4len > IPv6len {
|
||||
// Not enough room.
|
||||
return NIL
|
||||
return nil
|
||||
}
|
||||
p4 := ParseIPv4(s[i:len(s)]);
|
||||
if len(p4) == 0 {
|
||||
return NIL
|
||||
if p4 == nil {
|
||||
return nil
|
||||
}
|
||||
// BUG: p[j:j+4] = p4
|
||||
p[j] = p4[12];
|
||||
@ -342,14 +340,14 @@ L: for j < IPv6len {
|
||||
|
||||
// Otherwise must be followed by colon and more.
|
||||
if s[i] != ':' && i+1 == len(s) {
|
||||
return NIL
|
||||
return nil
|
||||
}
|
||||
i++;
|
||||
|
||||
// Look for ellipsis.
|
||||
if s[i] == ':' {
|
||||
if ellipsis >= 0 { // already have one
|
||||
return NIL
|
||||
return nil
|
||||
}
|
||||
ellipsis = j;
|
||||
if i++; i == len(s) { // can be at end
|
||||
@ -360,13 +358,13 @@ L: for j < IPv6len {
|
||||
|
||||
// Must have used entire string.
|
||||
if i != len(s) {
|
||||
return NIL
|
||||
return nil
|
||||
}
|
||||
|
||||
// If didn't parse enough, expand ellipsis.
|
||||
if j < IPv6len {
|
||||
if ellipsis < 0 {
|
||||
return NIL
|
||||
return nil
|
||||
}
|
||||
n := IPv6len - j;
|
||||
for k := j-1; k >= ellipsis; k-- {
|
||||
@ -381,7 +379,7 @@ L: for j < IPv6len {
|
||||
|
||||
export func ParseIP(s string) []byte {
|
||||
p := ParseIPv4(s);
|
||||
if len(p) != 0 {
|
||||
if p != nil {
|
||||
return p
|
||||
}
|
||||
return ParseIPv6(s)
|
||||
|
@ -62,8 +62,6 @@ func JoinHostPort(host, port string) string {
|
||||
return host + ":" + port
|
||||
}
|
||||
|
||||
var NIL []byte
|
||||
|
||||
// Convert "host:port" into IP address and port.
|
||||
// For now, host and port must be numeric literals.
|
||||
// Eventually, we'll have name resolution.
|
||||
@ -71,24 +69,24 @@ func HostPortToIP(net string, hostport string) (ip []byte, iport int, err *os.Er
|
||||
var host, port string;
|
||||
host, port, err = SplitHostPort(hostport);
|
||||
if err != nil {
|
||||
return NIL, 0, err
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
// Try as an IP address.
|
||||
addr := ParseIP(host);
|
||||
if len(addr) == 0 {
|
||||
if addr == nil {
|
||||
// Not an IP address. Try as a DNS name.
|
||||
hostname, addrs, err := LookupHost(host);
|
||||
if err != nil {
|
||||
return NIL, 0, err
|
||||
return nil, 0, err
|
||||
}
|
||||
if len(addrs) == 0 {
|
||||
return NIL, 0, UnknownHost
|
||||
return nil, 0, UnknownHost
|
||||
}
|
||||
addr = ParseIP(addrs[0]);
|
||||
if len(addr) == 0 {
|
||||
if addr == nil {
|
||||
// should not happen
|
||||
return NIL, 0, BadAddress
|
||||
return nil, 0, BadAddress
|
||||
}
|
||||
}
|
||||
|
||||
@ -96,11 +94,11 @@ func HostPortToIP(net string, hostport string) (ip []byte, iport int, err *os.Er
|
||||
if !ok || i != len(port) {
|
||||
p, ok = LookupPort(net, port);
|
||||
if !ok {
|
||||
return NIL, 0, UnknownPort
|
||||
return nil, 0, UnknownPort
|
||||
}
|
||||
}
|
||||
if p < 0 || p > 0xFFFF {
|
||||
return NIL, 0, BadAddress
|
||||
return nil, 0, BadAddress
|
||||
}
|
||||
|
||||
return addr, p, nil
|
||||
@ -311,7 +309,7 @@ func InternetSocket(net, laddr, raddr string, proto int64) (fd *FD, err *os.Erro
|
||||
default:
|
||||
// Otherwise, guess.
|
||||
// If the addresses are IPv4 and we prefer IPv4, use 4; else 6.
|
||||
if PreferIPv4 && len(ToIPv4(lip)) != 0 && len(ToIPv4(rip)) != 0 {
|
||||
if PreferIPv4 && ToIPv4(lip) != nil && ToIPv4(rip) != nil {
|
||||
vers = 4
|
||||
} else {
|
||||
vers = 6
|
||||
@ -329,13 +327,13 @@ func InternetSocket(net, laddr, raddr string, proto int64) (fd *FD, err *os.Erro
|
||||
}
|
||||
|
||||
var la, ra *syscall.Sockaddr;
|
||||
if len(lip) != 0 {
|
||||
if lip != nil {
|
||||
la, lerr = cvt(lip, lport);
|
||||
if lerr != nil {
|
||||
return nil, lerr
|
||||
}
|
||||
}
|
||||
if len(rip) != 0 {
|
||||
if rip != nil {
|
||||
ra, rerr = cvt(rip, rport);
|
||||
if rerr != nil {
|
||||
return nil, rerr
|
||||
@ -361,7 +359,7 @@ func (c *ConnTCP) SetNoDelay(nodelay bool) *os.Error {
|
||||
}
|
||||
|
||||
func NewConnTCP(fd *FD, raddr string) *ConnTCP {
|
||||
c := new(ConnTCP);
|
||||
c := new(*ConnTCP);
|
||||
c.fd = fd;
|
||||
c.raddr = raddr;
|
||||
c.SetNoDelay(true);
|
||||
@ -389,7 +387,7 @@ export type ConnUDP struct {
|
||||
}
|
||||
|
||||
func NewConnUDP(fd *FD, raddr string) *ConnUDP {
|
||||
c := new(ConnUDP);
|
||||
c := new(*ConnUDP);
|
||||
c.fd = fd;
|
||||
c.raddr = raddr;
|
||||
return c
|
||||
@ -488,7 +486,7 @@ export func ListenTCP(net, laddr string) (l *ListenerTCP, err *os.Error) {
|
||||
syscall.close(fd.fd);
|
||||
return nil, os.ErrnoToError(e1)
|
||||
}
|
||||
l = new(ListenerTCP);
|
||||
l = new(*ListenerTCP);
|
||||
l.fd = fd;
|
||||
return l, nil
|
||||
}
|
||||
|
@ -13,10 +13,10 @@ import (
|
||||
|
||||
export func IPv4ToSockaddr(p []byte, port int) (sa1 *syscall.Sockaddr, err *os.Error) {
|
||||
p = ToIPv4(p);
|
||||
if len(p) == 0 || port < 0 || port > 0xFFFF {
|
||||
if p == nil || port < 0 || port > 0xFFFF {
|
||||
return nil, os.EINVAL
|
||||
}
|
||||
sa := new(syscall.SockaddrInet4);
|
||||
sa := new(*syscall.SockaddrInet4);
|
||||
sa.len = syscall.SizeofSockaddrInet4;
|
||||
sa.family = syscall.AF_INET;
|
||||
sa.port[0] = byte(port>>8);
|
||||
@ -29,10 +29,10 @@ export func IPv4ToSockaddr(p []byte, port int) (sa1 *syscall.Sockaddr, err *os.E
|
||||
|
||||
export func IPv6ToSockaddr(p []byte, port int) (sa1 *syscall.Sockaddr, err *os.Error) {
|
||||
p = ToIPv6(p);
|
||||
if len(p) == 0 || port < 0 || port > 0xFFFF {
|
||||
if p == nil || port < 0 || port > 0xFFFF {
|
||||
return nil, os.EINVAL
|
||||
}
|
||||
sa := new(syscall.SockaddrInet6);
|
||||
sa := new(*syscall.SockaddrInet6);
|
||||
sa.len = syscall.SizeofSockaddrInet6;
|
||||
sa.family = syscall.AF_INET6;
|
||||
sa.port[0] = byte(port>>8);
|
||||
@ -43,28 +43,27 @@ export func IPv6ToSockaddr(p []byte, port int) (sa1 *syscall.Sockaddr, err *os.E
|
||||
return unsafe.pointer(sa).(*syscall.Sockaddr), nil
|
||||
}
|
||||
|
||||
var NIL []byte // TODO(rsc)
|
||||
|
||||
export func SockaddrToIP(sa1 *syscall.Sockaddr) (p []byte, port int, err *os.Error) {
|
||||
switch sa1.family {
|
||||
case syscall.AF_INET:
|
||||
sa := unsafe.pointer(sa1).(*syscall.SockaddrInet4);
|
||||
a := ToIPv6(sa.addr);
|
||||
if len(a) == 0 {
|
||||
return NIL, 0, os.EINVAL
|
||||
if a == nil {
|
||||
return nil, 0, os.EINVAL
|
||||
}
|
||||
return a, int(sa.port[0])<<8 + int(sa.port[1]), nil;
|
||||
case syscall.AF_INET6:
|
||||
sa := unsafe.pointer(sa1).(*syscall.SockaddrInet6);
|
||||
a := ToIPv6(sa.addr);
|
||||
if len(a) == 0 {
|
||||
return NIL, 0, os.EINVAL
|
||||
if a == nil {
|
||||
return nil, 0, os.EINVAL
|
||||
}
|
||||
return NIL, int(sa.port[0])<<8 + int(sa.port[1]), nil;
|
||||
return nil, int(sa.port[0])<<8 + int(sa.port[1]), nil;
|
||||
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 {
|
||||
|
@ -16,7 +16,7 @@ export func IPv4ToSockaddr(p []byte, port int) (sa1 *syscall.Sockaddr, err *os.E
|
||||
if p == nil || port < 0 || port > 0xFFFF {
|
||||
return nil, os.EINVAL
|
||||
}
|
||||
sa := new(syscall.SockaddrInet4);
|
||||
sa := new(*syscall.SockaddrInet4);
|
||||
sa.family = syscall.AF_INET;
|
||||
sa.port[0] = byte(port>>8);
|
||||
sa.port[1] = byte(port);
|
||||
@ -38,10 +38,10 @@ export func IPv6ToSockaddr(p []byte, port int) (sa1 *syscall.Sockaddr, err *os.E
|
||||
// In IPv6 mode, Linux treats that as meaning "announce on 0.0.0.0",
|
||||
// which it refuses to do. Rewrite to the IPv6 all zeros.
|
||||
if p4 := ToIPv4(p); p4 != nil && p4[0] == 0 && p4[1] == 0 && p4[2] == 0 && p4[3] == 0 {
|
||||
p = &IPv6zero;
|
||||
p = IPv6zero;
|
||||
}
|
||||
|
||||
sa := new(syscall.SockaddrInet6);
|
||||
sa := new(*syscall.SockaddrInet6);
|
||||
sa.family = syscall.AF_INET6;
|
||||
sa.port[0] = byte(port>>8);
|
||||
sa.port[1] = byte(port);
|
||||
@ -55,14 +55,14 @@ export func SockaddrToIP(sa1 *syscall.Sockaddr) (p []byte, port int, err *os.Err
|
||||
switch sa1.family {
|
||||
case syscall.AF_INET:
|
||||
sa := unsafe.pointer(sa1).(*syscall.SockaddrInet4);
|
||||
a := ToIPv6(&sa.addr);
|
||||
a := ToIPv6(sa.addr);
|
||||
if a == nil {
|
||||
return nil, 0, os.EINVAL
|
||||
}
|
||||
return a, int(sa.port[0])<<8 + int(sa.port[1]), nil;
|
||||
case syscall.AF_INET6:
|
||||
sa := unsafe.pointer(sa1).(*syscall.SockaddrInet6);
|
||||
a := ToIPv6(&sa.addr);
|
||||
a := ToIPv6(sa.addr);
|
||||
if a == nil {
|
||||
return nil, 0, os.EINVAL
|
||||
}
|
||||
|
@ -14,10 +14,10 @@ import (
|
||||
"strconv";
|
||||
)
|
||||
|
||||
var services *map[string] *map[string] int
|
||||
var services map[string] map[string] int
|
||||
|
||||
func ReadServices() {
|
||||
services = new(map[string] *map[string] int);
|
||||
services = new(map[string] map[string] int);
|
||||
file := Open("/etc/services");
|
||||
for line, ok := file.ReadLine(); ok; line, ok = file.ReadLine() {
|
||||
// "http 80/tcp www www-http # World Wide Web HTTP"
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
"testing";
|
||||
)
|
||||
|
||||
func Echo(fd io.ReadWrite, done *chan<- int) {
|
||||
func Echo(fd io.ReadWrite, done chan<- int) {
|
||||
var buf [1024]byte;
|
||||
|
||||
for {
|
||||
@ -24,7 +24,7 @@ func Echo(fd io.ReadWrite, done *chan<- int) {
|
||||
done <- 1
|
||||
}
|
||||
|
||||
func Serve(t *testing.T, network, addr string, listening, done *chan<- int) {
|
||||
func Serve(t *testing.T, network, addr string, listening, done chan<- int) {
|
||||
l, err := net.Listen(network, addr);
|
||||
if err != nil {
|
||||
t.Fatalf("net.Listen(%q, %q) = _, %v", network, addr, err);
|
||||
@ -76,9 +76,9 @@ func DoTest(t *testing.T, network, listenaddr, dialaddr string) {
|
||||
}
|
||||
|
||||
export func TestTcpServer(t *testing.T) {
|
||||
DoTest(t, "tcp", "0.0.0.0:9999", "127.0.0.1:9999");
|
||||
DoTest(t, "tcp", "[::]:9999", "[::ffff:127.0.0.1]:9999");
|
||||
DoTest(t, "tcp", "[::]:9999", "127.0.0.1:9999");
|
||||
DoTest(t, "tcp", "0.0.0.0:9999", "[::ffff:127.0.0.1]:9999");
|
||||
DoTest(t, "tcp", "0.0.0.0:9997", "127.0.0.1:9997");
|
||||
DoTest(t, "tcp", "[::]:9997", "[::ffff:127.0.0.1]:9997");
|
||||
DoTest(t, "tcp", "[::]:9997", "127.0.0.1:9997");
|
||||
DoTest(t, "tcp", "0.0.0.0:9997", "[::ffff:127.0.0.1]:9997");
|
||||
}
|
||||
|
||||
|
@ -13,12 +13,12 @@ package once
|
||||
|
||||
type Job struct {
|
||||
done bool;
|
||||
doit *chan bool; // buffer of 1
|
||||
doit chan bool; // buffer of 1
|
||||
}
|
||||
|
||||
type Request struct {
|
||||
f *();
|
||||
reply *chan *Job
|
||||
reply chan *Job
|
||||
}
|
||||
|
||||
// TODO: Would like to use chan Request but 6g rejects it.
|
||||
@ -34,7 +34,7 @@ func Server() {
|
||||
req := <-service;
|
||||
job, present := jobmap[req.f];
|
||||
if !present {
|
||||
job = new(Job);
|
||||
job = new(*Job);
|
||||
job.doit = new(chan bool, 1);
|
||||
job.doit <- true;
|
||||
jobmap[req.f] = job
|
||||
|
@ -48,7 +48,7 @@ func (c *Common) SetIndex(i int) { c.index = i }
|
||||
|
||||
type RE struct {
|
||||
expr string; // the original expression
|
||||
ch *chan<- *RE; // reply channel when we're done
|
||||
ch chan<- *RE; // reply channel when we're done
|
||||
error *os.Error; // compile- or run-time error; nil if OK
|
||||
inst *array.Array;
|
||||
start Inst;
|
||||
@ -112,7 +112,7 @@ func (char *Char) Type() int { return CHAR }
|
||||
func (char *Char) Print() { print("char ", string(char.char)) }
|
||||
|
||||
func NewChar(char int) *Char {
|
||||
c := new(Char);
|
||||
c := new(*Char);
|
||||
c.char = char;
|
||||
return c;
|
||||
}
|
||||
@ -163,7 +163,7 @@ func (cclass *CharClass) Matches(c int) bool {
|
||||
}
|
||||
|
||||
func NewCharClass() *CharClass {
|
||||
c := new(CharClass);
|
||||
c := new(*CharClass);
|
||||
c.ranges = array.NewIntArray(0);
|
||||
return c;
|
||||
}
|
||||
@ -249,7 +249,7 @@ func (p *Parser) nextc() int {
|
||||
}
|
||||
|
||||
func NewParser(re *RE) *Parser {
|
||||
parser := new(Parser);
|
||||
parser := new(*Parser);
|
||||
parser.re = re;
|
||||
parser.nextc(); // load p.ch
|
||||
return parser;
|
||||
@ -364,15 +364,15 @@ func (p *Parser) Term() (start, end Inst) {
|
||||
p.re.Error(ErrUnmatchedRbkt);
|
||||
case '^':
|
||||
p.nextc();
|
||||
start = p.re.Add(new(Bot));
|
||||
start = p.re.Add(new(*Bot));
|
||||
return start, start;
|
||||
case '$':
|
||||
p.nextc();
|
||||
start = p.re.Add(new(Eot));
|
||||
start = p.re.Add(new(*Eot));
|
||||
return start, start;
|
||||
case '.':
|
||||
p.nextc();
|
||||
start = p.re.Add(new(Any));
|
||||
start = p.re.Add(new(*Any));
|
||||
return start, start;
|
||||
case '[':
|
||||
p.nextc();
|
||||
@ -393,9 +393,9 @@ func (p *Parser) Term() (start, end Inst) {
|
||||
}
|
||||
p.nlpar--;
|
||||
p.nextc();
|
||||
bra := new(Bra);
|
||||
bra := new(*Bra);
|
||||
p.re.Add(bra);
|
||||
ebra := new(Ebra);
|
||||
ebra := new(*Ebra);
|
||||
p.re.Add(ebra);
|
||||
bra.n = nbra;
|
||||
ebra.n = nbra;
|
||||
@ -437,7 +437,7 @@ func (p *Parser) Closure() (start, end Inst) {
|
||||
switch p.c() {
|
||||
case '*':
|
||||
// (start,end)*:
|
||||
alt := new(Alt);
|
||||
alt := new(*Alt);
|
||||
p.re.Add(alt);
|
||||
end.SetNext(alt); // after end, do alt
|
||||
alt.left = start; // alternate brach: return to start
|
||||
@ -445,16 +445,16 @@ func (p *Parser) Closure() (start, end Inst) {
|
||||
end = alt;
|
||||
case '+':
|
||||
// (start,end)+:
|
||||
alt := new(Alt);
|
||||
alt := new(*Alt);
|
||||
p.re.Add(alt);
|
||||
end.SetNext(alt); // after end, do alt
|
||||
alt.left = start; // alternate brach: return to start
|
||||
end = alt; // start is unchanged; end is alt
|
||||
case '?':
|
||||
// (start,end)?:
|
||||
alt := new(Alt);
|
||||
alt := new(*Alt);
|
||||
p.re.Add(alt);
|
||||
nop := new(Nop);
|
||||
nop := new(*Nop);
|
||||
p.re.Add(nop);
|
||||
alt.left = start; // alternate branch is start
|
||||
alt.next = nop; // follow on to nop
|
||||
@ -478,7 +478,7 @@ func (p *Parser) Concatenation() (start, end Inst) {
|
||||
switch {
|
||||
case nstart == NULL: // end of this concatenation
|
||||
if start == NULL { // this is the empty string
|
||||
nop := p.re.Add(new(Nop));
|
||||
nop := p.re.Add(new(*Nop));
|
||||
return nop, nop;
|
||||
}
|
||||
return;
|
||||
@ -501,11 +501,11 @@ func (p *Parser) Regexp() (start, end Inst) {
|
||||
case '|':
|
||||
p.nextc();
|
||||
nstart, nend := p.Concatenation();
|
||||
alt := new(Alt);
|
||||
alt := new(*Alt);
|
||||
p.re.Add(alt);
|
||||
alt.left = start;
|
||||
alt.next = nstart;
|
||||
nop := new(Nop);
|
||||
nop := new(*Nop);
|
||||
p.re.Add(nop);
|
||||
end.SetNext(nop);
|
||||
nend.SetNext(nop);
|
||||
@ -550,12 +550,12 @@ func (re *RE) Dump() {
|
||||
|
||||
func (re *RE) DoParse() {
|
||||
parser := NewParser(re);
|
||||
start := new(Start);
|
||||
start := new(*Start);
|
||||
re.Add(start);
|
||||
s, e := parser.Regexp();
|
||||
start.next = s;
|
||||
re.start = start;
|
||||
e.SetNext(re.Add(new(End)));
|
||||
e.SetNext(re.Add(new(*End)));
|
||||
|
||||
if debug {
|
||||
re.Dump();
|
||||
@ -571,8 +571,8 @@ func (re *RE) DoParse() {
|
||||
}
|
||||
|
||||
|
||||
func Compiler(str string, ch *chan *RE) {
|
||||
re := new(RE);
|
||||
func Compiler(str string, ch chan *RE) {
|
||||
re := new(*RE);
|
||||
re.expr = str;
|
||||
re.inst = array.New(0);
|
||||
re.ch = ch;
|
||||
|
@ -34,7 +34,7 @@ func StringToDecimal(s string) (neg bool, d *Decimal, trunc bool, ok bool) {
|
||||
}
|
||||
|
||||
// digits
|
||||
b := new(Decimal);
|
||||
b := new(*Decimal);
|
||||
sawdot := false;
|
||||
sawdigits := false;
|
||||
for ; i < len(s); i++ {
|
||||
|
@ -120,7 +120,7 @@ func (a *Decimal) Assign(v uint64) {
|
||||
}
|
||||
|
||||
package func NewDecimal(i uint64) *Decimal {
|
||||
a := new(Decimal);
|
||||
a := new(*Decimal);
|
||||
a.Assign(i);
|
||||
return a;
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func HammerSemaphore(s *int32, cdone *chan bool) {
|
||||
func HammerSemaphore(s *int32, cdone chan bool) {
|
||||
for i := 0; i < 1000; i++ {
|
||||
sys.semacquire(s);
|
||||
sys.semrelease(s);
|
||||
@ -20,7 +20,7 @@ func HammerSemaphore(s *int32, cdone *chan bool) {
|
||||
}
|
||||
|
||||
export func TestSemaphore(t *testing.T) {
|
||||
s := new(int32);
|
||||
s := new(*int32);
|
||||
*s = 1;
|
||||
c := new(chan bool);
|
||||
for i := 0; i < 10; i++ {
|
||||
@ -32,7 +32,7 @@ export func TestSemaphore(t *testing.T) {
|
||||
}
|
||||
|
||||
|
||||
func HammerMutex(m *Mutex, cdone *chan bool) {
|
||||
func HammerMutex(m *Mutex, cdone chan bool) {
|
||||
for i := 0; i < 1000; i++ {
|
||||
m.Lock();
|
||||
m.Unlock();
|
||||
@ -41,7 +41,7 @@ func HammerMutex(m *Mutex, cdone *chan bool) {
|
||||
}
|
||||
|
||||
export func TestMutex(t *testing.T) {
|
||||
m := new(Mutex);
|
||||
m := new(*Mutex);
|
||||
c := new(chan bool);
|
||||
for i := 0; i < 10; i++ {
|
||||
go HammerMutex(m, c);
|
||||
|
@ -15,7 +15,7 @@ const NameBufsize = 512
|
||||
|
||||
export func open(name string, mode int64, perm int64) (ret int64, errno int64) {
|
||||
var namebuf [NameBufsize]byte;
|
||||
if !StringToBytes(&namebuf, name) {
|
||||
if !StringToBytes(namebuf, name) {
|
||||
return -1, ENAMETOOLONG
|
||||
}
|
||||
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) {
|
||||
|
||||
export func creat(name string, perm int64) (ret int64, errno int64) {
|
||||
var namebuf [NameBufsize]byte;
|
||||
if !StringToBytes(&namebuf, name) {
|
||||
if !StringToBytes(namebuf, name) {
|
||||
return -1, ENAMETOOLONG
|
||||
}
|
||||
r1, r2, err := Syscall(SYS_OPEN, int64(uintptr(unsafe.pointer(&namebuf[0]))), O_CREAT|O_WRONLY|O_TRUNC, perm);
|
||||
@ -59,7 +59,7 @@ export func pipe(fds *[2]int64) (ret int64, errno int64) {
|
||||
|
||||
export func stat(name string, buf *Stat) (ret int64, errno int64) {
|
||||
var namebuf [NameBufsize]byte;
|
||||
if !StringToBytes(&namebuf, name) {
|
||||
if !StringToBytes(namebuf, name) {
|
||||
return -1, ENAMETOOLONG
|
||||
}
|
||||
r1, r2, err := Syscall(SYS_STAT, int64(uintptr(unsafe.pointer(&namebuf[0]))), int64(uintptr(unsafe.pointer(buf))), 0);
|
||||
@ -78,7 +78,7 @@ export func fstat(fd int64, buf *Stat) (ret int64, errno int64) {
|
||||
|
||||
export func unlink(name string) (ret int64, errno int64) {
|
||||
var namebuf [NameBufsize]byte;
|
||||
if !StringToBytes(&namebuf, name) {
|
||||
if !StringToBytes(namebuf, name) {
|
||||
return -1, ENAMETOOLONG
|
||||
}
|
||||
r1, r2, err := Syscall(SYS_UNLINK, int64(uintptr(unsafe.pointer(&namebuf[0]))), 0, 0);
|
||||
@ -92,7 +92,7 @@ export func fcntl(fd, cmd, arg int64) (ret int64, errno int64) {
|
||||
|
||||
export func mkdir(name string, perm int64) (ret int64, errno int64) {
|
||||
var namebuf [NameBufsize]byte;
|
||||
if !StringToBytes(&namebuf, name) {
|
||||
if !StringToBytes(namebuf, name) {
|
||||
return -1, ENAMETOOLONG
|
||||
}
|
||||
r1, r2, err := Syscall(SYS_MKDIR, int64(uintptr(unsafe.pointer(&namebuf[0]))), perm, 0);
|
||||
|
@ -165,7 +165,7 @@ func (b *Writer) Init(writer io.Write, cellwidth, padding int, padchar byte, ali
|
||||
b.lines_width.Init(0);
|
||||
b.widths.Init(0);
|
||||
b.AddLine(); // the very first line
|
||||
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
@ -219,7 +219,7 @@ func (b *Writer) WritePadding(textw, cellw int) (err *os.Error) {
|
||||
if b.padbytes[0] == '\t' {
|
||||
n = (n + b.cellwidth - 1) / b.cellwidth;
|
||||
}
|
||||
|
||||
|
||||
for n > len(b.padbytes) {
|
||||
err = b.Write0(b.padbytes);
|
||||
if err != nil {
|
||||
@ -269,7 +269,7 @@ func (b *Writer) WriteLines(pos0 int, line0, line1 int) (pos int, err *os.Error)
|
||||
pos += s;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if i+1 == b.lines_size.Len() {
|
||||
// last buffered line - we don't have a newline, so just write
|
||||
// any outstanding buffered data
|
||||
@ -291,22 +291,22 @@ exit:
|
||||
|
||||
func (b *Writer) Format(pos0 int, line0, line1 int) (pos int, err *os.Error) {
|
||||
pos = pos0;
|
||||
column := b.widths.Len();
|
||||
column := b.widths.Len();
|
||||
last := line0;
|
||||
for this := line0; this < line1; this++ {
|
||||
line_size, line_width := b.Line(this);
|
||||
|
||||
|
||||
if column < line_size.Len() - 1 {
|
||||
// cell exists in this column
|
||||
// (note that the last cell per line is ignored)
|
||||
|
||||
|
||||
// print unprinted lines until beginning of block
|
||||
pos, err = b.WriteLines(pos, last, this);
|
||||
if err != nil {
|
||||
goto exit;
|
||||
}
|
||||
last = this;
|
||||
|
||||
|
||||
// column block begin
|
||||
width := b.cellwidth; // minimal width
|
||||
for ; this < line1; this++ {
|
||||
@ -334,7 +334,7 @@ func (b *Writer) Format(pos0 int, line0, line1 int) (pos int, err *os.Error) {
|
||||
|
||||
// print unprinted lines until end
|
||||
pos, err = b.WriteLines(pos, last, line1);
|
||||
|
||||
|
||||
exit:
|
||||
return pos, err;
|
||||
}
|
||||
@ -366,7 +366,7 @@ func UnicodeLen(buf []byte) int {
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
|
||||
|
||||
func (b *Writer) Append(buf []byte) {
|
||||
b.buf.Append(buf);
|
||||
@ -438,7 +438,7 @@ func (b *Writer) Append(buf []byte) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// append leftover text
|
||||
b.Append(buf[i0 : n]);
|
||||
return n, nil;
|
||||
@ -446,5 +446,5 @@ func (b *Writer) Append(buf []byte) {
|
||||
|
||||
|
||||
export func New(writer io.Write, cellwidth, padding int, padchar byte, align_left, filter_html bool) *Writer {
|
||||
return new(Writer).Init(writer, cellwidth, padding, padchar, align_left, filter_html)
|
||||
return new(*Writer).Init(writer, cellwidth, padding, padchar, align_left, filter_html)
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ func Tabify(s string) string {
|
||||
export type T struct {
|
||||
errors string;
|
||||
failed bool;
|
||||
ch *chan *T;
|
||||
ch chan *T;
|
||||
}
|
||||
|
||||
func (t *T) Fail() {
|
||||
@ -92,7 +92,7 @@ export func Main(tests []Test) {
|
||||
if chatty {
|
||||
println("=== RUN ", tests[i].name);
|
||||
}
|
||||
t := new(T);
|
||||
t := new(*T);
|
||||
t.ch = new(chan *T);
|
||||
go TRunner(t, &tests[i]);
|
||||
<-t.ch;
|
||||
|
@ -18,14 +18,14 @@ import (
|
||||
// Also, if timeouts become part of the select statement,
|
||||
// perhaps the Ticker is just:
|
||||
//
|
||||
// func Ticker(ns int64, c *chan int64) {
|
||||
// func Ticker(ns int64, c chan int64) {
|
||||
// for {
|
||||
// select { timeout ns: }
|
||||
// nsec, err := time.Nanoseconds();
|
||||
// c <- nsec;
|
||||
// }
|
||||
|
||||
func Ticker(ns int64, c *chan int64) {
|
||||
func Ticker(ns int64, c chan int64) {
|
||||
var tv syscall.Timeval;
|
||||
now := time.Nanoseconds();
|
||||
when := now;
|
||||
@ -49,7 +49,7 @@ func Ticker(ns int64, c *chan int64) {
|
||||
}
|
||||
}
|
||||
|
||||
export func Tick(ns int64) *chan int64 {
|
||||
export func Tick(ns int64) chan int64 {
|
||||
if ns <= 0 {
|
||||
return nil
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ const (
|
||||
)
|
||||
|
||||
export func SecondsToUTC(sec int64) *Time {
|
||||
t := new(Time);
|
||||
t := new(*Time);
|
||||
|
||||
// Split into time and day.
|
||||
day := sec/SecondsPerDay;
|
||||
|
@ -30,13 +30,12 @@ type Data struct {
|
||||
error bool;
|
||||
}
|
||||
|
||||
var NIL []byte // TODO(rsc)
|
||||
|
||||
func (d *Data) Read(n int) []byte {
|
||||
if len(d.p) < n {
|
||||
d.p = NIL;
|
||||
d.p = nil;
|
||||
d.error = true;
|
||||
return NIL;
|
||||
return nil;
|
||||
}
|
||||
p := d.p[0:n];
|
||||
d.p = d.p[n:len(d.p)];
|
||||
@ -86,20 +85,19 @@ type Zonetime struct {
|
||||
}
|
||||
|
||||
func ParseZoneinfo(bytes []byte) (zt []Zonetime, err *os.Error) {
|
||||
var NIL []Zonetime; // TODO(rsc)
|
||||
|
||||
data1 := Data{bytes, false};
|
||||
data := &data1;
|
||||
|
||||
// 4-byte magic "TZif"
|
||||
if magic := data.Read(4); string(magic) != "TZif" {
|
||||
return NIL, BadZoneinfo
|
||||
return nil, BadZoneinfo
|
||||
}
|
||||
|
||||
// 1-byte version, then 15 bytes of padding
|
||||
var p []byte;
|
||||
if p = data.Read(16); len(p) != 16 || p[0] != 0 && p[0] != '2' {
|
||||
return NIL, BadZoneinfo
|
||||
return nil, BadZoneinfo
|
||||
}
|
||||
vers := p[0];
|
||||
|
||||
@ -122,7 +120,7 @@ func ParseZoneinfo(bytes []byte) (zt []Zonetime, err *os.Error) {
|
||||
for i := 0; i < 6; i++ {
|
||||
nn, ok := data.Big4();
|
||||
if !ok {
|
||||
return NIL, BadZoneinfo
|
||||
return nil, BadZoneinfo
|
||||
}
|
||||
n[i] = int(nn);
|
||||
}
|
||||
@ -154,7 +152,7 @@ func ParseZoneinfo(bytes []byte) (zt []Zonetime, err *os.Error) {
|
||||
isutc := data.Read(n[NUTCLocal]);
|
||||
|
||||
if data.error { // ran out of data
|
||||
return NIL, BadZoneinfo
|
||||
return nil, BadZoneinfo
|
||||
}
|
||||
|
||||
// If version == 2, the entire file repeats, this time using
|
||||
@ -169,16 +167,16 @@ func ParseZoneinfo(bytes []byte) (zt []Zonetime, err *os.Error) {
|
||||
var ok bool;
|
||||
var n uint32;
|
||||
if n, ok = zonedata.Big4(); !ok {
|
||||
return NIL, BadZoneinfo
|
||||
return nil, BadZoneinfo
|
||||
}
|
||||
zone[i].utcoff = int(n);
|
||||
var b byte;
|
||||
if b, ok = zonedata.Byte(); !ok {
|
||||
return NIL, BadZoneinfo
|
||||
return nil, BadZoneinfo
|
||||
}
|
||||
zone[i].isdst = b != 0;
|
||||
if b, ok = zonedata.Byte(); !ok || int(b) >= len(abbrev) {
|
||||
return NIL, BadZoneinfo
|
||||
return nil, BadZoneinfo
|
||||
}
|
||||
zone[i].name = ByteString(abbrev[b:len(abbrev)])
|
||||
}
|
||||
@ -189,11 +187,11 @@ func ParseZoneinfo(bytes []byte) (zt []Zonetime, err *os.Error) {
|
||||
var ok bool;
|
||||
var n uint32;
|
||||
if n, ok = txtimes.Big4(); !ok {
|
||||
return NIL, BadZoneinfo
|
||||
return nil, BadZoneinfo
|
||||
}
|
||||
zt[i].time = int32(n);
|
||||
if int(txzones[i]) >= len(zone) {
|
||||
return NIL, BadZoneinfo
|
||||
return nil, BadZoneinfo
|
||||
}
|
||||
zt[i].zone = &zone[txzones[i]];
|
||||
if i < len(isstd) {
|
||||
@ -207,10 +205,9 @@ func ParseZoneinfo(bytes []byte) (zt []Zonetime, 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);
|
||||
if e != nil {
|
||||
return NIL, e
|
||||
return nil, e
|
||||
}
|
||||
p = new([]byte, max+1)[0:0];
|
||||
n := 0;
|
||||
@ -218,7 +215,7 @@ func ReadFile(name string, max int) (p []byte, err *os.Error) {
|
||||
nn, e := fd.Read(p[n:cap(p)]);
|
||||
if e != nil {
|
||||
fd.Close();
|
||||
return NIL, e
|
||||
return nil, e
|
||||
}
|
||||
if nn == 0 {
|
||||
fd.Close();
|
||||
@ -227,15 +224,14 @@ func ReadFile(name string, max int) (p []byte, err *os.Error) {
|
||||
p = p[0:n+nn]
|
||||
}
|
||||
fd.Close();
|
||||
return NIL, BadZoneinfo // too long
|
||||
return nil, BadZoneinfo // too long
|
||||
}
|
||||
|
||||
|
||||
func ReadZoneinfoFile(name string) (tx []Zonetime, err *os.Error) {
|
||||
var NIL []Zonetime; // TODO(rsc)
|
||||
data, e := ReadFile(name, MaxFileSize);
|
||||
if e != nil {
|
||||
return NIL, e
|
||||
return nil, e
|
||||
}
|
||||
tx, err = ParseZoneinfo(data);
|
||||
return tx, err
|
||||
|
@ -26,16 +26,15 @@ maketest() {
|
||||
maketest \
|
||||
lib/fmt\
|
||||
lib/hash\
|
||||
lib/json\
|
||||
lib/math\
|
||||
lib/net\
|
||||
lib/reflect\
|
||||
lib/regexp\
|
||||
lib/strconv\
|
||||
lib/tabwriter\
|
||||
lib/time\
|
||||
|
||||
# lib/json\
|
||||
# lib/net\
|
||||
|
||||
# all of these are subtly different
|
||||
# from what maketest does.
|
||||
|
||||
|
10
test/235.go
10
test/235.go
@ -8,10 +8,10 @@ package main
|
||||
|
||||
type T chan uint64;
|
||||
|
||||
func M(f uint64) (in, out *T) {
|
||||
func M(f uint64) (in, out T) {
|
||||
in = new(T, 100);
|
||||
out = new(T, 100);
|
||||
go func(in, out *T, f uint64) {
|
||||
go func(in, out T, f uint64) {
|
||||
for {
|
||||
out <- f * <-in;
|
||||
}
|
||||
@ -44,8 +44,8 @@ func main() {
|
||||
1250, 1280, 1296, 1350, 1440, 1458, 1500, 1536, 1600 };
|
||||
|
||||
x := uint64(1);
|
||||
ins := new([]*T, n);
|
||||
outs := new([]*T, n);
|
||||
ins := new([]T, n);
|
||||
outs := new([]T, n);
|
||||
xs := new([]uint64, n);
|
||||
for i := 0; i < n; i++ {
|
||||
ins[i], outs[i] = M(F[i]);
|
||||
@ -61,7 +61,7 @@ func main() {
|
||||
for i := 0; i < n; i++ {
|
||||
if xs[i] == x { xs[i] = <- outs[i]; }
|
||||
}
|
||||
|
||||
|
||||
x = min(xs);
|
||||
if x != OUT[i] { panic("bad: ", x, " should be ", OUT[i]); }
|
||||
}
|
||||
|
@ -21,5 +21,5 @@ func (s *S) g() {}
|
||||
func (s *S) h() {} // here we can't write (s *S) T either
|
||||
|
||||
func main() {
|
||||
var i I = new(S);
|
||||
var i I = new(*S);
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ func AsynchFifo() {
|
||||
}
|
||||
}
|
||||
|
||||
func Chain(ch *<-chan int, val int, in *<-chan int, out *chan<- int) {
|
||||
func Chain(ch <-chan int, val int, in <-chan int, out chan<- int) {
|
||||
<-in;
|
||||
if <-ch != val {
|
||||
panic(val)
|
||||
|
@ -14,7 +14,7 @@ import (
|
||||
"strconv";
|
||||
)
|
||||
|
||||
func f(left, right *chan int) {
|
||||
func f(left, right chan int) {
|
||||
left <- <-right;
|
||||
}
|
||||
|
||||
@ -36,6 +36,6 @@ func main() {
|
||||
go f(left, right);
|
||||
left = right;
|
||||
}
|
||||
go func(c *chan int) { c <- 1 }(right);
|
||||
go func(c chan int) { c <- 1 }(right);
|
||||
<-leftmost;
|
||||
}
|
||||
|
@ -13,35 +13,35 @@ func pause() {
|
||||
for i:=0; i<100; i++ { sys.gosched() }
|
||||
}
|
||||
|
||||
func i32receiver(c *chan int32) {
|
||||
func i32receiver(c chan int32) {
|
||||
if <-c != 123 { panic("i32 value") }
|
||||
}
|
||||
|
||||
func i32sender(c *chan int32) {
|
||||
func i32sender(c chan int32) {
|
||||
c <- 234
|
||||
}
|
||||
|
||||
func i64receiver(c *chan int64) {
|
||||
func i64receiver(c chan int64) {
|
||||
if <-c != 123456 { panic("i64 value") }
|
||||
}
|
||||
|
||||
func i64sender(c *chan int64) {
|
||||
func i64sender(c chan int64) {
|
||||
c <- 234567
|
||||
}
|
||||
|
||||
func breceiver(c *chan bool) {
|
||||
func breceiver(c chan bool) {
|
||||
if ! <-c { panic("b value") }
|
||||
}
|
||||
|
||||
func bsender(c *chan bool) {
|
||||
func bsender(c chan bool) {
|
||||
c <- true
|
||||
}
|
||||
|
||||
func sreceiver(c *chan string) {
|
||||
func sreceiver(c chan string) {
|
||||
if <-c != "hello" { panic("s value") }
|
||||
}
|
||||
|
||||
func ssender(c *chan string) {
|
||||
func ssender(c chan string) {
|
||||
c <- "hello again"
|
||||
}
|
||||
|
||||
@ -57,19 +57,19 @@ func main() {
|
||||
c64 := new(chan int64, buffer);
|
||||
cb := new(chan bool, buffer);
|
||||
cs := new(chan string, buffer);
|
||||
|
||||
|
||||
i32, ok = <-c32;
|
||||
if ok { panic("blocked i32sender") }
|
||||
|
||||
|
||||
i64, ok = <-c64;
|
||||
if ok { panic("blocked i64sender") }
|
||||
|
||||
|
||||
b, ok = <-cb;
|
||||
if ok { panic("blocked bsender") }
|
||||
|
||||
|
||||
s, ok = <-cs;
|
||||
if ok { panic("blocked ssender") }
|
||||
|
||||
|
||||
go i32receiver(c32);
|
||||
pause();
|
||||
ok = c32 <- 123;
|
||||
@ -79,7 +79,7 @@ func main() {
|
||||
i32, ok = <-c32;
|
||||
if !ok { panic("i32sender") }
|
||||
if i32 != 234 { panic("i32sender value") }
|
||||
|
||||
|
||||
go i64receiver(c64);
|
||||
pause();
|
||||
ok = c64 <- 123456;
|
||||
@ -89,7 +89,7 @@ func main() {
|
||||
i64, ok = <-c64;
|
||||
if !ok { panic("i64sender") }
|
||||
if i64 != 234567 { panic("i64sender value") }
|
||||
|
||||
|
||||
go breceiver(cb);
|
||||
pause();
|
||||
ok = cb <- true;
|
||||
@ -99,7 +99,7 @@ func main() {
|
||||
b, ok = <-cb;
|
||||
if !ok { panic("bsender") }
|
||||
if !b{ panic("bsender value") }
|
||||
|
||||
|
||||
go sreceiver(cs);
|
||||
pause();
|
||||
ok = cs <- "hello";
|
||||
|
@ -30,8 +30,8 @@ func (u *rat) eq(c item) bool {
|
||||
}
|
||||
|
||||
type dch struct {
|
||||
req *chan int;
|
||||
dat *chan item;
|
||||
req chan int;
|
||||
dat chan item;
|
||||
nam int;
|
||||
}
|
||||
|
||||
@ -46,7 +46,7 @@ func Init();
|
||||
func mkdch() *dch {
|
||||
c := chnameserial % len(chnames);
|
||||
chnameserial++;
|
||||
d := new(dch);
|
||||
d := new(*dch);
|
||||
d.req = new(chan int);
|
||||
d.dat = new(chan item);
|
||||
d.nam = c;
|
||||
@ -54,7 +54,7 @@ func mkdch() *dch {
|
||||
}
|
||||
|
||||
func mkdch2() *dch2 {
|
||||
d2 := new(dch2);
|
||||
d2 := new(*dch2);
|
||||
d2[0] = mkdch();
|
||||
d2[1] = mkdch();
|
||||
return d2;
|
||||
@ -74,7 +74,7 @@ func mkdch2() *dch2 {
|
||||
// a signal on the release-wait channel tells the next newer
|
||||
// generation to begin servicing out[1].
|
||||
|
||||
func dosplit(in *dch, out *dch2, wait *chan int ){
|
||||
func dosplit(in *dch, out *dch2, wait chan int ){
|
||||
var t *dch;
|
||||
both := false; // do not service both channels
|
||||
|
||||
@ -127,9 +127,9 @@ func get(in *dch) *rat {
|
||||
func getn(in []*dch, n int) []item {
|
||||
// BUG n:=len(in);
|
||||
if n != 2 { panic("bad n in getn") };
|
||||
req := new([2] *chan int);
|
||||
dat := new([2] *chan item);
|
||||
out := new([2] item);
|
||||
req := new(*[2] chan int);
|
||||
dat := new(*[2] chan item);
|
||||
out := new([]item, 2);
|
||||
var i int;
|
||||
var it item;
|
||||
for i=0; i<n; i++ {
|
||||
@ -159,11 +159,8 @@ func getn(in []*dch, n int) []item {
|
||||
|
||||
// Get one item from each of 2 demand channels
|
||||
|
||||
func get2(in0 *dch, in1 *dch) []item {
|
||||
x := new([2] *dch);
|
||||
x[0] = in0;
|
||||
x[1] = in1;
|
||||
return getn(x, 2);
|
||||
func get2(in0 *dch, in1 *dch) []item {
|
||||
return getn([]*dch{in0, in1}, 2);
|
||||
}
|
||||
|
||||
func copy(in *dch, out *dch){
|
||||
@ -211,7 +208,7 @@ func gcd (u, v int64) int64{
|
||||
|
||||
func i2tor(u, v int64) *rat{
|
||||
g := gcd(u,v);
|
||||
r := new(rat);
|
||||
r := new(*rat);
|
||||
if v > 0 {
|
||||
r.num = u/g;
|
||||
r.den = v/g;
|
||||
@ -249,7 +246,7 @@ func add(u, v *rat) *rat {
|
||||
func mul(u, v *rat) *rat{
|
||||
g1 := gcd(u.num,v.den);
|
||||
g2 := gcd(u.den,v.num);
|
||||
r := new(rat);
|
||||
r := new(*rat);
|
||||
r.num =(u.num/g1)*(v.num/g2);
|
||||
r.den = (u.den/g2)*(v.den/g1);
|
||||
return r;
|
||||
@ -649,7 +646,7 @@ func main() {
|
||||
check(Ones, one, 5, "Ones");
|
||||
check(Add(Ones, Ones), itor(2), 0, "Add Ones Ones"); // 1 1 1 1 1
|
||||
check(Add(Ones, Twos), itor(3), 0, "Add Ones Twos"); // 3 3 3 3 3
|
||||
a := new([N] *rat);
|
||||
a := new([] *rat, N);
|
||||
d := Diff(Ones);
|
||||
// BUG: want array initializer
|
||||
for i:=0; i < N; i++ {
|
||||
|
@ -35,8 +35,8 @@ func (u *rat) eq(c item) bool {
|
||||
}
|
||||
|
||||
type dch struct {
|
||||
req *chan int;
|
||||
dat *chan item;
|
||||
req chan int;
|
||||
dat chan item;
|
||||
nam int;
|
||||
}
|
||||
|
||||
@ -51,7 +51,7 @@ func Init();
|
||||
func mkdch() *dch {
|
||||
c := chnameserial % len(chnames);
|
||||
chnameserial++;
|
||||
d := new(dch);
|
||||
d := new(*dch);
|
||||
d.req = new(chan int);
|
||||
d.dat = new(chan item);
|
||||
d.nam = c;
|
||||
@ -59,7 +59,7 @@ func mkdch() *dch {
|
||||
}
|
||||
|
||||
func mkdch2() *dch2 {
|
||||
d2 := new(dch2);
|
||||
d2 := new(*dch2);
|
||||
d2[0] = mkdch();
|
||||
d2[1] = mkdch();
|
||||
return d2;
|
||||
@ -79,7 +79,7 @@ func mkdch2() *dch2 {
|
||||
// a signal on the release-wait channel tells the next newer
|
||||
// generation to begin servicing out[1].
|
||||
|
||||
func dosplit(in *dch, out *dch2, wait *chan int ){
|
||||
func dosplit(in *dch, out *dch2, wait chan int ){
|
||||
var t *dch;
|
||||
both := false; // do not service both channels
|
||||
|
||||
@ -132,9 +132,9 @@ func get(in *dch) *rat {
|
||||
func getn(in []*dch, n int) []item {
|
||||
// BUG n:=len(in);
|
||||
if n != 2 { panic("bad n in getn") };
|
||||
req := new([2] *chan int);
|
||||
dat := new([2] *chan item);
|
||||
out := new([2] item);
|
||||
req := new([] chan int, 2);
|
||||
dat := new([] chan item, 2);
|
||||
out := new([]item, 2);
|
||||
var i int;
|
||||
var it item;
|
||||
for i=0; i<n; i++ {
|
||||
@ -165,10 +165,7 @@ func getn(in []*dch, n int) []item {
|
||||
// Get one item from each of 2 demand channels
|
||||
|
||||
func get2(in0 *dch, in1 *dch) []item {
|
||||
x := new([2] *dch);
|
||||
x[0] = in0;
|
||||
x[1] = in1;
|
||||
return getn(x, 2);
|
||||
return getn([]*dch{in0, in1}, 2);
|
||||
}
|
||||
|
||||
func copy(in *dch, out *dch){
|
||||
@ -216,7 +213,7 @@ func gcd (u, v int64) int64{
|
||||
|
||||
func i2tor(u, v int64) *rat{
|
||||
g := gcd(u,v);
|
||||
r := new(rat);
|
||||
r := new(*rat);
|
||||
if v > 0 {
|
||||
r.num = u/g;
|
||||
r.den = v/g;
|
||||
@ -254,7 +251,7 @@ func add(u, v *rat) *rat {
|
||||
func mul(u, v *rat) *rat{
|
||||
g1 := gcd(u.num,v.den);
|
||||
g2 := gcd(u.den,v.num);
|
||||
r := new(rat);
|
||||
r := new(*rat);
|
||||
r.num =(u.num/g1)*(v.num/g2);
|
||||
r.den = (u.den/g2)*(v.den/g1);
|
||||
return r;
|
||||
@ -654,7 +651,7 @@ func main() {
|
||||
check(Ones, one, 5, "Ones");
|
||||
check(Add(Ones, Ones), itor(2), 0, "Add Ones Ones"); // 1 1 1 1 1
|
||||
check(Add(Ones, Twos), itor(3), 0, "Add Ones Twos"); // 3 3 3 3 3
|
||||
a := new([N] *rat);
|
||||
a := new([]*rat, N);
|
||||
d := Diff(Ones);
|
||||
// BUG: want array initializer
|
||||
for i:=0; i < N; i++ {
|
||||
|
@ -14,7 +14,7 @@ func GetValue() uint {
|
||||
return 1 << shift
|
||||
}
|
||||
|
||||
func Send(a, b *chan uint) int {
|
||||
func Send(a, b chan uint) int {
|
||||
var i int;
|
||||
LOOP:
|
||||
for {
|
||||
|
@ -10,7 +10,7 @@
|
||||
package main
|
||||
|
||||
// Send the sequence 2, 3, 4, ... to channel 'ch'.
|
||||
func Generate(ch *chan<- int) {
|
||||
func Generate(ch chan<- int) {
|
||||
for i := 2; ; i++ {
|
||||
ch <- i // Send 'i' to channel 'ch'.
|
||||
}
|
||||
@ -18,7 +18,7 @@ func Generate(ch *chan<- int) {
|
||||
|
||||
// Copy the values from channel 'in' to channel 'out',
|
||||
// removing those divisible by 'prime'.
|
||||
func Filter(in *<-chan int, out *chan<- int, prime int) {
|
||||
func Filter(in <-chan int, out chan<- int, prime int) {
|
||||
for {
|
||||
i := <-in; // Receive value of new variable 'i' from 'in'.
|
||||
if i % prime != 0 {
|
||||
@ -28,7 +28,7 @@ func Filter(in *<-chan int, out *chan<- int, prime int) {
|
||||
}
|
||||
|
||||
// The prime sieve: Daisy-chain Filter processes together.
|
||||
func Sieve(primes *chan<- int) {
|
||||
func Sieve(primes chan<- int) {
|
||||
ch := new(chan int); // Create a new channel.
|
||||
go Generate(ch); // Start Generate() as a subprocess.
|
||||
for {
|
||||
|
@ -11,7 +11,7 @@ type T struct { i int; f float; s string; next *T }
|
||||
type R struct { num int }
|
||||
|
||||
func itor(a int) *R {
|
||||
r := new(R);
|
||||
r := new(*R);
|
||||
r.num = a;
|
||||
return r;
|
||||
}
|
||||
@ -49,12 +49,12 @@ func main() {
|
||||
if len(at) != 3 { panic("at") }
|
||||
|
||||
c := new(chan int);
|
||||
ac := []*chan int{c, c, c};
|
||||
ac := []chan int{c, c, c};
|
||||
if len(ac) != 3 { panic("ac") }
|
||||
|
||||
aat := [][len(at)]*T{at, at};
|
||||
if len(aat) != 2 || len(aat[1]) != 3 { panic("at") }
|
||||
|
||||
|
||||
s := string([]byte{'h', 'e', 'l', 'l', 'o'});
|
||||
if s != "hello" { panic("s") }
|
||||
|
||||
@ -62,7 +62,7 @@ func main() {
|
||||
if len(m) != 3 { panic("m") }
|
||||
|
||||
eq(&[]*R{itor(0), itor(1), itor(2), itor(3), itor(4), itor(5)});
|
||||
|
||||
|
||||
p1 := NewP(1, 2);
|
||||
p2 := NewP(1, 2);
|
||||
if p1 == p2 { panic("NewP") }
|
||||
|
@ -16,7 +16,7 @@ func (t *T) m(a int, b float) int {
|
||||
}
|
||||
|
||||
func main() {
|
||||
var t *T = new(T);
|
||||
var t *T = new(*T);
|
||||
t.x = 1;
|
||||
t.y = 2;
|
||||
r10 := t.m(1, 3.0);
|
||||
|
@ -18,8 +18,8 @@ func (v *Vector) Insert(i int, e Element) {
|
||||
|
||||
func main() {
|
||||
type I struct { val int; }; // BUG: can't be local; works if global
|
||||
v := new(Vector);
|
||||
v.Insert(0, new(I));
|
||||
v := new(*Vector);
|
||||
v.Insert(0, new(*I));
|
||||
}
|
||||
/*
|
||||
check: main_sigs_I: not defined
|
||||
|
@ -15,9 +15,9 @@ type Vector struct {
|
||||
}
|
||||
|
||||
func New() *Vector {
|
||||
v := new(Vector);
|
||||
v := new(*Vector);
|
||||
v.nelem = 0;
|
||||
v.elem = new([10]Element);
|
||||
v.elem = new(*[10]Element);
|
||||
return v;
|
||||
}
|
||||
|
||||
@ -33,11 +33,11 @@ func (v *Vector) Insert(e Element) {
|
||||
type I struct { val int; }; // BUG: can't be local;
|
||||
|
||||
func main() {
|
||||
i0 := new(I); i0.val = 0;
|
||||
i1 := new(I); i1.val = 11;
|
||||
i2 := new(I); i2.val = 222;
|
||||
i3 := new(I); i3.val = 3333;
|
||||
i4 := new(I); i4.val = 44444;
|
||||
i0 := new(*I); i0.val = 0;
|
||||
i1 := new(*I); i1.val = 11;
|
||||
i2 := new(*I); i2.val = 222;
|
||||
i3 := new(*I); i3.val = 3333;
|
||||
i4 := new(*I); i4.val = 44444;
|
||||
v := New();
|
||||
print("hi\n");
|
||||
v.Insert(i4);
|
||||
|
@ -9,5 +9,5 @@ package main
|
||||
|
||||
func main() {
|
||||
var z [3]byte;
|
||||
z := new([3]byte); // BUG redeclaration
|
||||
z := new(*[3]byte); // BUG redeclaration
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ type T struct {
|
||||
func main() {
|
||||
var ta []*T;
|
||||
|
||||
ta = new([1]*T);
|
||||
ta = new(*[1]*T);
|
||||
ta[0] = nil;
|
||||
}
|
||||
/*
|
||||
|
@ -30,12 +30,12 @@ func (s *TStruct) field(i int) *TStruct {
|
||||
}
|
||||
|
||||
func main() {
|
||||
v := new(Vector);
|
||||
v.elem = new([10]Element);
|
||||
t := new(TStruct);
|
||||
v := new(*Vector);
|
||||
v.elem = new(*[10]Element);
|
||||
t := new(*TStruct);
|
||||
t.name = "hi";
|
||||
v.elem[0] = t;
|
||||
s := new(TStruct);
|
||||
s := new(*TStruct);
|
||||
s.name = "foo";
|
||||
s.fields = v;
|
||||
if s.field(0).name != "hi" {
|
||||
|
@ -7,8 +7,8 @@
|
||||
package main
|
||||
|
||||
type Box struct {};
|
||||
var m *map[string] *Box;
|
||||
|
||||
var m map[string] *Box;
|
||||
|
||||
func main() {
|
||||
m := new(map[string] *Box);
|
||||
s := "foo";
|
||||
|
@ -20,7 +20,7 @@ func P(a []string) string {
|
||||
|
||||
func main() {
|
||||
m := new(map[string] []string);
|
||||
as := new([2]string);
|
||||
as := new(*[2]string);
|
||||
as[0] = "0";
|
||||
as[1] = "1";
|
||||
m["0"] = as;
|
||||
|
@ -12,7 +12,7 @@ type (
|
||||
)
|
||||
|
||||
type Scope struct {
|
||||
entries *map[string] *Object;
|
||||
entries map[string] *Object;
|
||||
}
|
||||
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
package main
|
||||
|
||||
var c *chan int
|
||||
var c chan int
|
||||
|
||||
func main() {
|
||||
c = new(chan int);
|
||||
|
@ -13,6 +13,6 @@ func main(){
|
||||
|
||||
i, ok = <-c; // works
|
||||
|
||||
ca := new([2]*chan int);
|
||||
ca := new(*[2]chan int);
|
||||
i, ok = <-(ca[0]); // fails: c.go:11: bad shape across assignment - cr=1 cl=2
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ func (u *rat) pr() {
|
||||
}
|
||||
|
||||
type dch struct {
|
||||
dat *chan *rat;
|
||||
dat chan *rat;
|
||||
}
|
||||
|
||||
func dosplit(in *dch){
|
||||
|
@ -6,9 +6,9 @@
|
||||
|
||||
package main
|
||||
|
||||
type T struct { m *map[int]int }
|
||||
type T struct { m map[int]int }
|
||||
func main() {
|
||||
t := new(T);
|
||||
t := new(*T);
|
||||
t.m = new(map[int]int);
|
||||
var x int;
|
||||
var ok bool;
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
package main
|
||||
|
||||
func dosplit(wait *chan int ){
|
||||
func dosplit(wait chan int ){
|
||||
select {
|
||||
case <-wait:
|
||||
}
|
||||
|
@ -18,6 +18,6 @@ var arith Service
|
||||
|
||||
func main() {
|
||||
c := new(chan string);
|
||||
a := new(Service);
|
||||
a := new(*Service);
|
||||
go a.Serve(1234);
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ func (s *S) F() int { return 1 }
|
||||
// if you take it out (and the 0s below)
|
||||
// then the bug goes away.
|
||||
func NewI(i int) I {
|
||||
return new(S)
|
||||
return new(*S)
|
||||
}
|
||||
|
||||
// Uses interface method.
|
||||
|
@ -22,7 +22,7 @@ func (s *Stucky) Me() Iffy {
|
||||
}
|
||||
|
||||
func main() {
|
||||
s := new(Stucky);
|
||||
s := new(*Stucky);
|
||||
i := s.Me();
|
||||
j := i.Me();
|
||||
j.Me();
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
package main
|
||||
|
||||
export func Send(c *chan int) int {
|
||||
export func Send(c chan int) int {
|
||||
select {
|
||||
default:
|
||||
return 1;
|
||||
|
@ -81,7 +81,7 @@ func main() {
|
||||
r9, s9 := f9(1);
|
||||
assertequal(r9, 9, "r9");
|
||||
assertequal(int(s9), 9, "s9");
|
||||
var t *T = new(T);
|
||||
var t *T = new(*T);
|
||||
t.x = 1;
|
||||
t.y = 2;
|
||||
r10 := t.m10(1, 3.0);
|
||||
|
@ -64,7 +64,7 @@ func (m *HashMap) Clear() {
|
||||
|
||||
func (m *HashMap) Initialize (initial_log2_capacity uint32) {
|
||||
m.log2_capacity_ = initial_log2_capacity;
|
||||
m.map_ = new([1024] Entry);
|
||||
m.map_ = new(*[1024] Entry);
|
||||
m.Clear();
|
||||
}
|
||||
|
||||
@ -74,7 +74,7 @@ func (m *HashMap) Probe (key *KeyType) *Entry {
|
||||
|
||||
var i uint32 = key.Hash() % m.capacity();
|
||||
ASSERT(0 <= i && i < m.capacity());
|
||||
|
||||
|
||||
ASSERT(m.occupancy_ < m.capacity()); // guarantees loop termination
|
||||
for m.map_[i].key != nil && !m.map_[i].key.Match(key) {
|
||||
i++;
|
||||
@ -82,7 +82,7 @@ func (m *HashMap) Probe (key *KeyType) *Entry {
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return &m.map_[i];
|
||||
}
|
||||
|
||||
@ -102,13 +102,13 @@ func (m *HashMap) Lookup (key *KeyType, insert bool) *Entry {
|
||||
p.key = key;
|
||||
p.value = nil;
|
||||
m.occupancy_++;
|
||||
|
||||
|
||||
// Grow the map if we reached >= 80% occupancy.
|
||||
if m.occupancy_ + m.occupancy_/4 >= m.capacity() {
|
||||
m.Resize();
|
||||
p = m.Probe(key);
|
||||
}
|
||||
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
@ -120,10 +120,10 @@ func (m *HashMap) Lookup (key *KeyType, insert bool) *Entry {
|
||||
func (m *HashMap) Resize() {
|
||||
var hmap *[1024] Entry = m.map_;
|
||||
var n uint32 = m.occupancy_;
|
||||
|
||||
|
||||
// Allocate a new map of twice the current size.
|
||||
m.Initialize(m.log2_capacity_ << 1);
|
||||
|
||||
|
||||
// Rehash all current entries.
|
||||
var i uint32 = 0;
|
||||
for n > 0 {
|
||||
@ -157,7 +157,7 @@ func (n *Number) Match(other *KeyType) bool {
|
||||
|
||||
|
||||
func MakeNumber (x uint32) *Number {
|
||||
var n *Number = new(Number);
|
||||
var n *Number = new(*Number);
|
||||
n.x = x;
|
||||
return n;
|
||||
}
|
||||
@ -167,18 +167,18 @@ func main() {
|
||||
//f unc (n int) int { return n + 1; }(1);
|
||||
|
||||
//print "HashMap - gri 2/8/2008\n";
|
||||
|
||||
var hmap *HashMap = new(HashMap);
|
||||
|
||||
var hmap *HashMap = new(*HashMap);
|
||||
hmap.Initialize(0);
|
||||
|
||||
|
||||
var x1 *Number = MakeNumber(1001);
|
||||
var x2 *Number = MakeNumber(2002);
|
||||
var x3 *Number = MakeNumber(3003);
|
||||
|
||||
|
||||
// this doesn't work I think...
|
||||
//hmap.Lookup(x1, true);
|
||||
//hmap.Lookup(x2, true);
|
||||
//hmap.Lookup(x3, true);
|
||||
|
||||
|
||||
//print "done\n";
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ func (a *Matrix) set(i, j int, x *Big.Rational) {
|
||||
|
||||
func NewMatrix(n, m int) *Matrix {
|
||||
assert(0 <= n && 0 <= m);
|
||||
a := new(Matrix);
|
||||
a := new(*Matrix);
|
||||
a.n = n;
|
||||
a.m = m;
|
||||
a.a = new([]*Big.Rational, n*m);
|
||||
|
@ -7,7 +7,7 @@
|
||||
package main
|
||||
|
||||
var a = []int { 1, 2, }
|
||||
var b = [5]int { }
|
||||
var b = []int { }
|
||||
var c = []int { 1 }
|
||||
|
||||
func main() {
|
||||
|
@ -28,8 +28,8 @@ func AddInst(Inst) *Inst {
|
||||
}
|
||||
|
||||
func main() {
|
||||
re := new(Regexp);
|
||||
re := new(*Regexp);
|
||||
print("call addinst\n");
|
||||
var x Inst = AddInst(new(Start)); // ERROR "illegal|incompatible"
|
||||
var x Inst = AddInst(new(*Start)); // ERROR "illegal|incompatible"
|
||||
print("return from addinst\n");
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ testpfpf()
|
||||
func
|
||||
testpdpf1()
|
||||
{
|
||||
a := new([40]int);
|
||||
a := new(*[40]int);
|
||||
setpd(a);
|
||||
res(sumpd(a), 0, 40);
|
||||
|
||||
|
@ -22,7 +22,7 @@ nrand(n int) int
|
||||
type Chan
|
||||
struct
|
||||
{
|
||||
sc,rc *chan int; // send and recv chan
|
||||
sc,rc chan int; // send and recv chan
|
||||
sv,rv int; // send and recv seq
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@ var
|
||||
func
|
||||
init()
|
||||
{
|
||||
nc = new(Chan);
|
||||
nc = new(*Chan);
|
||||
}
|
||||
|
||||
func
|
||||
@ -47,7 +47,7 @@ mkchan(c,n int) []*Chan
|
||||
ca := new([]*Chan, n);
|
||||
for i:=0; i<n; i++ {
|
||||
cval = cval+100;
|
||||
ch := new(Chan);
|
||||
ch := new(*Chan);
|
||||
ch.sc = new(chan int, c);
|
||||
ch.rc = ch.sc;
|
||||
ch.sv = cval;
|
||||
|
@ -166,10 +166,10 @@ main()
|
||||
var s *S;
|
||||
|
||||
// allocate
|
||||
s = new(S);
|
||||
s.Subp = new(Subp);
|
||||
s.Sub.SubSubp = new(SubSubp);
|
||||
s.Subp.SubpSubp = new(SubpSubp);
|
||||
s = new(*S);
|
||||
s.Subp = new(*Subp);
|
||||
s.Sub.SubSubp = new(*SubSubp);
|
||||
s.Subp.SubpSubp = new(*SubpSubp);
|
||||
|
||||
// explicit assignment
|
||||
s.a = 1;
|
||||
|
@ -40,7 +40,7 @@ main()
|
||||
var i2 I2;
|
||||
var g *S;
|
||||
|
||||
s := new(S);
|
||||
s := new(*S);
|
||||
s.a = 5;
|
||||
s.b = 6;
|
||||
|
||||
|
@ -58,9 +58,9 @@ puts(s string)
|
||||
func
|
||||
main()
|
||||
{
|
||||
p := new(Print);
|
||||
b := new(Bio);
|
||||
f := new(File);
|
||||
p := new(*Print);
|
||||
b := new(*Bio);
|
||||
f := new(*File);
|
||||
|
||||
p.whoami = 1;
|
||||
p.put = b;
|
||||
|
@ -27,7 +27,7 @@ main()
|
||||
var v int;
|
||||
var c *C;
|
||||
|
||||
c = new(C);
|
||||
c = new(*C);
|
||||
c.a = 6;
|
||||
c.x = &g;
|
||||
|
||||
|
@ -10,7 +10,7 @@ const size = 16;
|
||||
|
||||
var a [size]byte;
|
||||
var p []byte;
|
||||
var m *map[int]byte;
|
||||
var m map[int]byte;
|
||||
|
||||
func
|
||||
f(k int) byte
|
||||
|
@ -31,7 +31,7 @@ Init()
|
||||
func (list *List)
|
||||
Insert(i Item)
|
||||
{
|
||||
item := new(ListItem);
|
||||
item := new(*ListItem);
|
||||
item.item = i;
|
||||
item.next = list.head;
|
||||
list.head = item;
|
||||
@ -69,10 +69,10 @@ Print()
|
||||
func
|
||||
main()
|
||||
{
|
||||
list := new(List);
|
||||
list := new(*List);
|
||||
list.Init();
|
||||
for i := 0; i < 10; i = i + 1 {
|
||||
integer := new(Integer);
|
||||
integer := new(*Integer);
|
||||
integer.Init(i);
|
||||
list.Insert(integer);
|
||||
}
|
||||
|
@ -213,7 +213,7 @@ func ParseList() *Slist
|
||||
{
|
||||
var slist, retval *Slist;
|
||||
|
||||
slist = new(Slist);
|
||||
slist = new(*Slist);
|
||||
slist.list.car = nil;
|
||||
slist.list.cdr = nil;
|
||||
slist.isatom = false;
|
||||
@ -225,7 +225,7 @@ func ParseList() *Slist
|
||||
if token == ')' || token == EOF { // empty cdr
|
||||
break;
|
||||
}
|
||||
slist.list.cdr = new(Slist);
|
||||
slist.list.cdr = new(*Slist);
|
||||
slist = slist.list.cdr;
|
||||
}
|
||||
return retval;
|
||||
@ -236,7 +236,7 @@ func atom(i int) *Slist // BUG: uses tokenbuf; should take argument
|
||||
var h, length int;
|
||||
var slist, tail *Slist;
|
||||
|
||||
slist = new(Slist);
|
||||
slist = new(*Slist);
|
||||
if token == '0' {
|
||||
slist.atom.integer = i;
|
||||
slist.isstring = false;
|
||||
|
@ -86,7 +86,7 @@ func main() {
|
||||
r9, s9 = f9(1);
|
||||
assertequal(r9, 9, "r9");
|
||||
assertequal(int(s9), 9, "s9");
|
||||
var t *T = new(T);
|
||||
var t *T = new(*T);
|
||||
t.x = 1;
|
||||
t.y = 2;
|
||||
r10 := t.m10(1, 3.0);
|
||||
|
@ -35,7 +35,7 @@ main()
|
||||
|
||||
if s2 != 35 { panic(s2); }
|
||||
|
||||
b := new([100]int);
|
||||
b := new(*[100]int);
|
||||
for i:=0; i<100; i=i+1 {
|
||||
b[i] = i;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ main()
|
||||
if !!!a { panic(6); }
|
||||
|
||||
var x *s;
|
||||
x = new(s);
|
||||
x = new(*s);
|
||||
x.a = true;
|
||||
x.b = false;
|
||||
|
||||
|
@ -92,7 +92,7 @@ main()
|
||||
}
|
||||
|
||||
/* create string with byte array pointer */
|
||||
z2 := new([3]byte);
|
||||
z2 := new(*[3]byte);
|
||||
z2[0] = 'a';
|
||||
z2[1] = 'b';
|
||||
z2[2] = 'c';
|
||||
|
16
test/map.go
16
test/map.go
@ -46,8 +46,8 @@ func main() {
|
||||
//mit := new(map[int] T); // should be able to do a value but: fatal error: algtype: cant find type <T>{}
|
||||
//mti := new(map[T] int); // should be able to do a value but: fatal error: algtype: cant find type <T>{}
|
||||
|
||||
type M map[int] int;
|
||||
mipM := new(map[int] *M);
|
||||
type M map[int] int;
|
||||
mipM := new(map[int] M);
|
||||
|
||||
const count = 100; // BUG: should be bigger but maps do linear lookup
|
||||
var apT [2*count]*T;
|
||||
@ -55,14 +55,14 @@ func main() {
|
||||
for i := 0; i < count; i++ {
|
||||
s := F.d(i).str();
|
||||
f := float(i);
|
||||
apT[i] = new(T);
|
||||
apT[i] = new(*T);
|
||||
apT[i].s = s;
|
||||
apT[i].f = f;
|
||||
apT[2*i] = new(T); // need twice as many entries as we use, for the nonexistence check
|
||||
apT[2*i] = new(*T); // need twice as many entries as we use, for the nonexistence check
|
||||
apT[2*i].s = s;
|
||||
apT[2*i].f = f;
|
||||
// BUG t := T(s, f);
|
||||
t := new(T); t.s = s; t.f = f;
|
||||
t := new(*T); t.s = s; t.f = f;
|
||||
// BUG m := M(i, i+1);
|
||||
m := new(M); m[i] = i+1;
|
||||
mib[i] = (i != 0);
|
||||
@ -73,7 +73,7 @@ func main() {
|
||||
msi[F.d(i).str()] = i;
|
||||
mss[F.d(i).str()] = F.d(10*i).str();
|
||||
mss[F.d(i).str()] = F.d(10*i).str();
|
||||
as := new([arraylen]string);
|
||||
as := new([]string, arraylen);
|
||||
as[0] = F.d(10*i).str();
|
||||
as[1] = F.d(10*i).str();
|
||||
mspa[F.d(i).str()] = as;
|
||||
@ -120,7 +120,7 @@ func main() {
|
||||
if len(mipM) != count {
|
||||
F.s("len(mipM) = ").d(len(mipM)).putnl();
|
||||
}
|
||||
|
||||
|
||||
// test construction directly
|
||||
for i := 0; i < count; i++ {
|
||||
s := F.d(i).str();
|
||||
@ -411,7 +411,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// tests for structured map element updates
|
||||
for i := 0; i < count; i++ {
|
||||
|
@ -17,8 +17,8 @@ func main() {
|
||||
var i *int;
|
||||
var f *float;
|
||||
var s *string;
|
||||
var m *map[float] *int;
|
||||
var c *chan int;
|
||||
var m map[float] *int;
|
||||
var c chan int;
|
||||
var t *T;
|
||||
var in IN;
|
||||
var ta []IN;
|
||||
@ -30,6 +30,6 @@ func main() {
|
||||
c = nil;
|
||||
t = nil;
|
||||
i = nil;
|
||||
ta = new([1]IN);
|
||||
ta = new([]IN, 1);
|
||||
ta[0] = nil;
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ func is_zero(x *Number) bool {
|
||||
|
||||
|
||||
func add1(x *Number) *Number {
|
||||
e := new(Number);
|
||||
e := new(*Number);
|
||||
e.next = x;
|
||||
return e;
|
||||
}
|
||||
@ -122,7 +122,7 @@ func verify() {
|
||||
|
||||
|
||||
func main() {
|
||||
|
||||
|
||||
verify();
|
||||
for i := 0; i <= 10; i++ {
|
||||
print(i, "! = ", count(fact(gen(i))), "\n");
|
||||
|
@ -7,7 +7,7 @@
|
||||
package main
|
||||
|
||||
// Send the sequence 2, 3, 4, ... to channel 'ch'.
|
||||
func Generate(ch *chan<- int) {
|
||||
func Generate(ch chan<- int) {
|
||||
for i := 2; ; i++ {
|
||||
ch <- i // Send 'i' to channel 'ch'.
|
||||
}
|
||||
@ -15,7 +15,7 @@ func Generate(ch *chan<- int) {
|
||||
|
||||
// Copy the values from channel 'in' to channel 'out',
|
||||
// removing those divisible by 'prime'.
|
||||
func Filter(in *<-chan int, out *chan<- int, prime int) {
|
||||
func Filter(in <-chan int, out chan<- int, prime int) {
|
||||
for {
|
||||
i := <-in; // Receive value of new variable 'i' from 'in'.
|
||||
if i % prime != 0 {
|
||||
|
@ -8,7 +8,7 @@ package main
|
||||
|
||||
const
|
||||
a_const = 0
|
||||
|
||||
|
||||
const (
|
||||
pi = /* the usual */ 3.14159265358979323;
|
||||
e = 2.718281828;
|
||||
@ -55,7 +55,7 @@ func swap(x, y int) (u, v int) {
|
||||
}
|
||||
|
||||
func control_structs() {
|
||||
var p *Point = new(Point).Initialize(2, 3);
|
||||
var p *Point = new(*Point).Initialize(2, 3);
|
||||
i := p.Distance();
|
||||
var f float = 0.3;
|
||||
for {}
|
||||
|
@ -29,7 +29,7 @@ func main() {
|
||||
// encoded as bytes: 'a' 'b' 'c' e6 97 a5 e6 9c ac e8 aa 9e
|
||||
const L = 12;
|
||||
if L != l { panic("wrong length constructing array") }
|
||||
a := new([L]byte);
|
||||
a := new(*[L]byte);
|
||||
a[0] = 'a';
|
||||
a[1] = 'b';
|
||||
a[2] = 'c';
|
||||
|
@ -31,7 +31,7 @@ func test0() {
|
||||
func test1() {
|
||||
var a [1000] *S;
|
||||
for i := 0; i < len(a); i++ {
|
||||
a[i] = new(S).Init(i);
|
||||
a[i] = new(*S).Init(i);
|
||||
}
|
||||
|
||||
v := array.New(0);
|
||||
@ -48,7 +48,7 @@ func test1() {
|
||||
panic("expected ", i, ", found ", x.val, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for v.Len() > 10 {
|
||||
v.Remove(10);
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ func (x *Literal) typ() *Globals.Type {
|
||||
|
||||
|
||||
export func NewLiteral(pos int, typ *Globals.Type) *Literal {
|
||||
x := new(Literal);
|
||||
x := new(*Literal);
|
||||
x.pos_ = pos;
|
||||
x.typ_ = typ;
|
||||
return x;
|
||||
@ -63,7 +63,7 @@ func (x *Object) typ() *Globals.Type {
|
||||
|
||||
|
||||
export func NewObject(pos int, obj* Globals.Object) *Object {
|
||||
x := new(Object);
|
||||
x := new(*Object);
|
||||
x.pos_ = pos;
|
||||
x.obj = obj;
|
||||
return x;
|
||||
@ -88,7 +88,7 @@ func (x *Selector) typ() *Globals.Type {
|
||||
|
||||
|
||||
export func NewSelector(pos int, typ *Globals.Type) *Selector {
|
||||
x := new(Selector);
|
||||
x := new(*Selector);
|
||||
x.pos_ = pos;
|
||||
x.typ_ = typ;
|
||||
return x;
|
||||
|
@ -93,16 +93,16 @@ export func Compile(comp *Globals.Compilation, src_file string) {
|
||||
print(src_file, "\n");
|
||||
}
|
||||
|
||||
scanner := new(Scanner.Scanner);
|
||||
scanner := new(*Scanner.Scanner);
|
||||
scanner.Open(src_file, src);
|
||||
|
||||
var tstream *chan *Scanner.Token;
|
||||
var tstream chan *Scanner.Token;
|
||||
if comp.flags.token_chan {
|
||||
tstream = new(chan *Scanner.Token, 100);
|
||||
go scanner.Server(tstream);
|
||||
}
|
||||
|
||||
parser := new(Parser.Parser);
|
||||
parser := new(*Parser.Parser);
|
||||
parser.Open(comp, scanner, tstream);
|
||||
|
||||
parser.ParseProgram();
|
||||
|
@ -52,7 +52,7 @@ type T8 chan <- *T6
|
||||
|
||||
type T9 struct {
|
||||
p *T9;
|
||||
q [] *map [int] *T9;
|
||||
q [] map [int] *T9;
|
||||
f *(x, y *T9) *T9;
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ export type List struct {
|
||||
export type Scope struct {
|
||||
parent *Scope;
|
||||
entries *List;
|
||||
// entries *map[string] *Object; // doesn't work properly
|
||||
// entries map[string] *Object; // doesn't work properly
|
||||
}
|
||||
|
||||
|
||||
@ -129,7 +129,7 @@ type Elem struct {
|
||||
export var Universe_void_t *Type // initialized by Universe to Universe.void_t
|
||||
|
||||
export func NewObject(pos, kind int, ident string) *Object {
|
||||
obj := new(Object);
|
||||
obj := new(*Object);
|
||||
obj.exported = false;
|
||||
obj.pos = pos;
|
||||
obj.kind = kind;
|
||||
@ -141,7 +141,7 @@ export func NewObject(pos, kind int, ident string) *Object {
|
||||
|
||||
|
||||
export func NewType(form int) *Type {
|
||||
typ := new(Type);
|
||||
typ := new(*Type);
|
||||
typ.ref = -1; // not yet exported
|
||||
typ.form = form;
|
||||
return typ;
|
||||
@ -149,7 +149,7 @@ export func NewType(form int) *Type {
|
||||
|
||||
|
||||
export func NewPackage(file_name string, obj *Object, scope *Scope) *Package {
|
||||
pkg := new(Package);
|
||||
pkg := new(*Package);
|
||||
pkg.ref = -1; // not yet exported
|
||||
pkg.file_name = file_name;
|
||||
pkg.key = "<the package key>"; // empty key means package forward declaration
|
||||
@ -160,12 +160,12 @@ export func NewPackage(file_name string, obj *Object, scope *Scope) *Package {
|
||||
|
||||
|
||||
export func NewList() *List {
|
||||
return new(List);
|
||||
return new(*List);
|
||||
}
|
||||
|
||||
|
||||
export func NewScope(parent *Scope) *Scope {
|
||||
scope := new(Scope);
|
||||
scope := new(*Scope);
|
||||
scope.parent = parent;
|
||||
scope.entries = NewList();
|
||||
return scope;
|
||||
@ -176,7 +176,7 @@ export func NewScope(parent *Scope) *Scope {
|
||||
// Object methods
|
||||
|
||||
func (obj *Object) Copy() *Object {
|
||||
copy := new(Object);
|
||||
copy := new(*Object);
|
||||
copy.exported = obj.exported;
|
||||
copy.pos = obj.pos;
|
||||
copy.kind = obj.kind;
|
||||
@ -211,7 +211,7 @@ func (L *List) Clear() {
|
||||
|
||||
func (L *List) Add() *Elem {
|
||||
L.len_++;
|
||||
e := new(Elem);
|
||||
e := new(*Elem);
|
||||
if L.first == nil {
|
||||
L.first = e;
|
||||
} else {
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user