Skip to content

Commit 08ca30b

Browse files
committed
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
1 parent d47d888 commit 08ca30b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+814
-845
lines changed

src/cmd/gotest/gotest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ done
4141
set -e
4242

4343
# They all compile; now generate the code to call them.
44-
#trap "rm -f _testmain.go _testmain.6" 0 1 2 3 14 15
44+
trap "rm -f _testmain.go _testmain.6" 0 1 2 3 14 15
4545
{
4646
# package spec
4747
echo 'package main'

src/lib/bignum.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ func (x *Natural) Add(y *Natural) *Natural {
164164
if n < m {
165165
return y.Add(x);
166166
}
167-
167+
168168
c := Digit(0);
169-
z := new(Natural, n + 1);
169+
z := new(*Natural, n + 1);
170170
i := 0;
171171
for i < m {
172172
t := c + x[i] + y[i];
@@ -193,9 +193,9 @@ func (x *Natural) Sub(y *Natural) *Natural {
193193
if n < m {
194194
panic("underflow")
195195
}
196-
196+
197197
c := Digit(0);
198-
z := new(Natural, n);
198+
z := new(*Natural, n);
199199
i := 0;
200200
for i < m {
201201
t := c + x[i] - y[i];
@@ -253,7 +253,7 @@ func (x *Natural) Mul(y *Natural) *Natural {
253253
n := len(x);
254254
m := len(y);
255255

256-
z := new(Natural, n + m);
256+
z := new(*Natural, n + m);
257257
for j := 0; j < m; j++ {
258258
d := y[j];
259259
if d != 0 {
@@ -296,7 +296,7 @@ func Unpack(x *Natural) []Digit2 {
296296

297297
func Pack(x []Digit2) *Natural {
298298
n := (len(x) + 1) / 2;
299-
z := new(Natural, n);
299+
z := new(*Natural, n);
300300
if len(x) & 1 == 1 {
301301
// handle odd len(x)
302302
n--;
@@ -376,7 +376,7 @@ func DivMod(x, y []Digit2) ([]Digit2, []Digit2) {
376376
} else {
377377
// general case
378378
assert(2 <= m && m <= n);
379-
379+
380380
// normalize x and y
381381
// TODO Instead of multiplying, it would be sufficient to
382382
// shift y such that the normalization condition is
@@ -472,7 +472,7 @@ func Shl(z, x []Digit, s uint) Digit {
472472
func (x *Natural) Shl(s uint) *Natural {
473473
n := uint(len(x));
474474
m := n + s/W;
475-
z := new(Natural, m+1);
475+
z := new(*Natural, m+1);
476476

477477
z[m] = Shl(z[m-n : m], x, s%W);
478478

@@ -497,7 +497,7 @@ func (x *Natural) Shr(s uint) *Natural {
497497
if m > n { // check for underflow
498498
m = 0;
499499
}
500-
z := new(Natural, m);
500+
z := new(*Natural, m);
501501

502502
Shr(z, x[n-m : n], s%W);
503503

@@ -512,7 +512,7 @@ func (x *Natural) And(y *Natural) *Natural {
512512
return y.And(x);
513513
}
514514

515-
z := new(Natural, m);
515+
z := new(*Natural, m);
516516
for i := 0; i < m; i++ {
517517
z[i] = x[i] & y[i];
518518
}
@@ -536,7 +536,7 @@ func (x *Natural) Or(y *Natural) *Natural {
536536
return y.Or(x);
537537
}
538538

539-
z := new(Natural, n);
539+
z := new(*Natural, n);
540540
for i := 0; i < m; i++ {
541541
z[i] = x[i] | y[i];
542542
}
@@ -553,7 +553,7 @@ func (x *Natural) Xor(y *Natural) *Natural {
553553
return y.Xor(x);
554554
}
555555

556-
z := new(Natural, n);
556+
z := new(*Natural, n);
557557
for i := 0; i < m; i++ {
558558
z[i] = x[i] ^ y[i];
559559
}
@@ -630,7 +630,7 @@ func (x *Natural) ToString(base uint) string {
630630
s := new([]byte, n);
631631

632632
// don't destroy x
633-
t := new(Natural, len(x));
633+
t := new(*Natural, len(x));
634634
Copy(t, x);
635635

636636
// convert
@@ -682,7 +682,7 @@ func HexValue(ch byte) uint {
682682
func MulAdd1(x *Natural, d, c Digit) *Natural {
683683
assert(IsSmall(d-1) && IsSmall(c));
684684
n := len(x);
685-
z := new(Natural, n + 1);
685+
z := new(*Natural, n + 1);
686686

687687
for i := 0; i < n; i++ {
688688
t := c + x[i]*d;
@@ -1088,7 +1088,7 @@ func (x *Integer) ToString(base uint) string {
10881088
return s + x.mant.ToString(base);
10891089
}
10901090

1091-
1091+
10921092
func (x *Integer) String() string {
10931093
return x.ToString(10);
10941094
}

src/lib/bufio.go

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export func NewBufReadSize(rd io.Read, size int) (b *BufRead, err *os.Error) {
5050
if size <= 0 {
5151
return nil, BadBufSize
5252
}
53-
b = new(BufRead);
53+
b = new(*BufRead);
5454
b.buf = new([]byte, size);
5555
b.rd = rd;
5656
return b, nil
@@ -191,11 +191,9 @@ func (b *BufRead) Buffered() int {
191191
// For internal (or advanced) use only.
192192
// Use ReadLineString or ReadLineBytes instead.
193193

194-
var NIL []byte // TODO(rsc): should be able to use nil
195-
196194
func (b *BufRead) ReadLineSlice(delim byte) (line []byte, err *os.Error) {
197195
if b.err != nil {
198-
return NIL, b.err
196+
return nil, b.err
199197
}
200198

201199
// Look in buffer.
@@ -210,7 +208,7 @@ func (b *BufRead) ReadLineSlice(delim byte) (line []byte, err *os.Error) {
210208
n := b.Buffered();
211209
b.Fill();
212210
if b.err != nil {
213-
return NIL, b.err
211+
return nil, b.err
214212
}
215213
if b.Buffered() == n { // no data added; end of file
216214
line := b.buf[b.r:b.w];
@@ -227,12 +225,12 @@ func (b *BufRead) ReadLineSlice(delim byte) (line []byte, err *os.Error) {
227225

228226
// Buffer is full?
229227
if b.Buffered() >= len(b.buf) {
230-
return NIL, BufferFull
228+
return nil, BufferFull
231229
}
232230
}
233231

234232
// BUG 6g bug100
235-
return NIL, nil
233+
return nil, nil
236234
}
237235

238236
// 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) {
242240
// we might have read more than the buffer size.)
243241
func (b *BufRead) ReadLineBytes(delim byte) (line []byte, err *os.Error) {
244242
if b.err != nil {
245-
return NIL, b.err
243+
return nil, b.err
246244
}
247245

248246
// Use ReadLineSlice to look for array,
@@ -279,7 +277,7 @@ func (b *BufRead) ReadLineBytes(delim byte) (line []byte, err *os.Error) {
279277
}
280278

281279
// Grow list if needed.
282-
if len(full) == 0 {
280+
if full == nil {
283281
full = new([][]byte, 16);
284282
} else if nfull >= len(full) {
285283
newfull := new([][]byte, len(full)*2);
@@ -313,26 +311,18 @@ func (b *BufRead) ReadLineBytes(delim byte) (line []byte, err *os.Error) {
313311
return buf, err
314312
}
315313

316-
// BUG(bugs/bug102.go): string(empty bytes array) throws error
317-
func ToString(p []byte) string {
318-
if len(p) == 0 {
319-
return ""
320-
}
321-
return string(p)
322-
}
323-
324314
// Read until the first occurrence of delim in the input,
325315
// returning a new string containing the line.
326316
// If savedelim, keep delim in the result; otherwise chop it off.
327317
func (b *BufRead) ReadLineString(delim byte, savedelim bool) (line string, err *os.Error) {
328318
bytes, e := b.ReadLineBytes(delim);
329319
if e != nil {
330-
return ToString(bytes), e
320+
return string(bytes), e
331321
}
332322
if !savedelim {
333323
bytes = bytes[0:len(bytes)-1]
334324
}
335-
return ToString(bytes), nil
325+
return string(bytes), nil
336326
}
337327

338328

@@ -349,7 +339,7 @@ export func NewBufWriteSize(wr io.Write, size int) (b *BufWrite, err *os.Error)
349339
if size <= 0 {
350340
return nil, BadBufSize
351341
}
352-
b = new(BufWrite);
342+
b = new(*BufWrite);
353343
b.buf = new([]byte, size);
354344
b.wr = wr;
355345
return b, nil

src/lib/bufio_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type ByteReader struct {
3434
}
3535

3636
func NewByteReader(p []byte) io.Read {
37-
b := new(ByteReader);
37+
b := new(*ByteReader);
3838
b.p = p;
3939
return b
4040
}
@@ -56,7 +56,7 @@ type HalfByteReader struct {
5656
}
5757

5858
func NewHalfByteReader(p []byte) io.Read {
59-
b := new(HalfByteReader);
59+
b := new(*HalfByteReader);
6060
b.p = p;
6161
return b
6262
}
@@ -80,7 +80,7 @@ type Rot13Reader struct {
8080
}
8181

8282
func NewRot13Reader(r io.Read) *Rot13Reader {
83-
r13 := new(Rot13Reader);
83+
r13 := new(*Rot13Reader);
8484
r13.r = r;
8585
return r13
8686
}
@@ -238,7 +238,7 @@ type ByteWriter struct {
238238
}
239239

240240
func NewByteWriter() WriteBuffer {
241-
return new(ByteWriter)
241+
return new(*ByteWriter)
242242
}
243243

244244
func (w *ByteWriter) Write(p []byte) (int, *os.Error) {
@@ -266,7 +266,7 @@ type HalfByteWriter struct {
266266
}
267267

268268
func NewHalfByteWriter() WriteBuffer {
269-
w := new(HalfByteWriter);
269+
w := new(*HalfByteWriter);
270270
w.bw = NewByteWriter();
271271
return w
272272
}

src/lib/container/array/array.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (p *Array) Init(initial_len int) *Array {
3636

3737

3838
export func New(len int) *Array {
39-
return new(Array).Init(len)
39+
return new(*Array).Init(len)
4040
}
4141

4242

src/lib/container/array/intarray.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func (p *IntArray) Init(len int) *IntArray {
1919

2020

2121
export func NewIntArray(len int) *IntArray {
22-
return new(IntArray).Init(len)
22+
return new(*IntArray).Init(len)
2323
}
2424

2525

src/lib/flag.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ export type Flag struct {
289289
}
290290

291291
type Flags struct {
292-
actual *map[string] *Flag;
293-
formal *map[string] *Flag;
292+
actual map[string] *Flag;
293+
formal map[string] *Flag;
294294
first_arg int;
295295
flag_list *Flag; // BUG: remove when we can iterate over maps
296296
}
@@ -318,7 +318,7 @@ func (f *Flag) SVal() string {
318318
}
319319

320320
func New() *Flags {
321-
f := new(Flags);
321+
f := new(*Flags);
322322
f.first_arg = 1; // 0 is the program name, 1 is first arg
323323
f.actual = new(map[string] *Flag);
324324
f.formal = new(map[string] *Flag);
@@ -361,7 +361,7 @@ export func NArg() int {
361361
}
362362

363363
func Add(name string, value Value, usage string) *Flag {
364-
f := new(Flag);
364+
f := new(*Flag);
365365
f.name = name;
366366
f.usage = usage;
367367
f.value = value;

src/lib/hash/adler32.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
// Adler-32 checksum.
5+
// Adler-32 checksum.
66
// Defined in RFC 1950:
77
// Adler-32 is composed of two sums accumulated per byte: s1 is
88
// the sum of all bytes, s2 is the sum of all s1 values. Both sums

src/lib/hash/crc32.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const (
2525
Koopman = 0xeb31d82e;
2626
)
2727

28-
// TODO(rsc): Change to [256]uint32
28+
// TODO(rsc): Change to [256]uint32 once 6g can handle it.
2929
export type Table []uint32
3030

3131
export func MakeTable(poly uint32) Table {

src/lib/hash/md5.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export type Digest struct {
2727
}
2828

2929
export func NewDigest() *Digest {
30-
d := new(Digest);
30+
d := new(*Digest);
3131
d.s[0] = A;
3232
d.s[1] = B;
3333
d.s[2] = C;

0 commit comments

Comments
 (0)