Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
8a45917f
Commit
8a45917f
authored
Aug 20, 2009
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
len and cap on chans
R=ken OCL=33599 CL=33599
parent
7c4f7cc7
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
78 additions
and
12 deletions
+78
-12
doc/go_spec.html
doc/go_spec.html
+0
-4
src/cmd/6g/cgen.c
src/cmd/6g/cgen.c
+24
-2
src/cmd/8g/cgen.c
src/cmd/8g/cgen.c
+23
-1
src/cmd/gc/align.c
src/cmd/gc/align.c
+2
-3
src/pkg/runtime/chan.c
src/pkg/runtime/chan.c
+2
-2
test/chancap.go
test/chancap.go
+27
-0
No files found.
doc/go_spec.html
View file @
8a45917f
...
...
@@ -4345,10 +4345,6 @@ The following minimal alignment properties are guaranteed:
<p>
<font
color=
red
>
Implementation does not honor the restriction on goto statements and targets (no intervening declarations).
<br/>
cap() does not work on chans.
<br/>
len() does not work on chans.
</font>
</p>
...
...
src/cmd/6g/cgen.c
View file @
8a45917f
...
...
@@ -242,8 +242,8 @@ cgen(Node *n, Node *res)
break
;
case
OLEN
:
if
(
istype
(
nl
->
type
,
TMAP
))
{
// map
has
len in the first 32-bit word.
if
(
istype
(
nl
->
type
,
TMAP
)
||
istype
(
nl
->
type
,
TCHAN
)
)
{
// map
and chan have
len in the first 32-bit word.
// a zero pointer means zero length
regalloc
(
&
n1
,
types
[
tptr
],
res
);
cgen
(
nl
,
&
n1
);
...
...
@@ -279,6 +279,28 @@ cgen(Node *n, Node *res)
break
;
case
OCAP
:
if
(
istype
(
nl
->
type
,
TCHAN
))
{
// chan has cap in the second 32-bit word.
// a zero pointer means zero length
regalloc
(
&
n1
,
types
[
tptr
],
res
);
cgen
(
nl
,
&
n1
);
nodconst
(
&
n2
,
types
[
tptr
],
0
);
gins
(
optoas
(
OCMP
,
types
[
tptr
]),
&
n1
,
&
n2
);
p1
=
gbranch
(
optoas
(
OEQ
,
types
[
tptr
]),
T
);
n2
=
n1
;
n2
.
op
=
OINDREG
;
n2
.
xoffset
=
4
;
n2
.
type
=
types
[
TINT32
];
gmove
(
&
n2
,
&
n1
);
patch
(
p1
,
pc
);
gmove
(
&
n1
,
res
);
regfree
(
&
n1
);
break
;
}
if
(
isslice
(
nl
->
type
))
{
regalloc
(
&
n1
,
types
[
tptr
],
res
);
agen
(
nl
,
&
n1
);
...
...
src/cmd/8g/cgen.c
View file @
8a45917f
...
...
@@ -237,7 +237,7 @@ cgen(Node *n, Node *res)
break
;
case
OLEN
:
if
(
istype
(
nl
->
type
,
TMAP
))
{
if
(
istype
(
nl
->
type
,
TMAP
)
||
istype
(
nl
->
type
,
TCHAN
)
)
{
// map has len in the first 32-bit word.
// a zero pointer means zero length
tempalloc
(
&
n1
,
types
[
tptr
]);
...
...
@@ -280,6 +280,28 @@ cgen(Node *n, Node *res)
break
;
case
OCAP
:
if
(
istype
(
nl
->
type
,
TCHAN
))
{
// chan has cap in the second 32-bit word.
// a zero pointer means zero length
regalloc
(
&
n1
,
types
[
tptr
],
res
);
cgen
(
nl
,
&
n1
);
nodconst
(
&
n2
,
types
[
tptr
],
0
);
gins
(
optoas
(
OCMP
,
types
[
tptr
]),
&
n1
,
&
n2
);
p1
=
gbranch
(
optoas
(
OEQ
,
types
[
tptr
]),
T
);
n2
=
n1
;
n2
.
op
=
OINDREG
;
n2
.
xoffset
=
4
;
n2
.
type
=
types
[
TINT32
];
gmove
(
&
n2
,
&
n1
);
patch
(
p1
,
pc
);
gmove
(
&
n1
,
res
);
regfree
(
&
n1
);
break
;
}
if
(
isslice
(
nl
->
type
))
{
igen
(
nl
,
&
n1
,
res
);
n1
.
op
=
OINDREG
;
...
...
src/cmd/gc/align.c
View file @
8a45917f
...
...
@@ -303,11 +303,10 @@ typeinit(void)
okforbool
[
TBOOL
]
=
1
;
okforcap
[
TARRAY
]
=
1
;
//okforcap[TCHAN] = 1;
//okforcap[TMAP] = 1;
okforcap
[
TCHAN
]
=
1
;
okforlen
[
TARRAY
]
=
1
;
//
okforlen[TCHAN] = 1;
okforlen
[
TCHAN
]
=
1
;
okforlen
[
TMAP
]
=
1
;
okforlen
[
TSTRING
]
=
1
;
...
...
src/pkg/runtime/chan.c
View file @
8a45917f
...
...
@@ -39,10 +39,10 @@ struct WaitQ
struct
Hchan
{
uint32
qcount
;
// total data in the q
uint32
dataqsiz
;
// size of the circular q
uint16
elemsize
;
uint16
closed
;
// Wclosed Rclosed errorcount
uint32
dataqsiz
;
// size of the circular q
uint32
qcount
;
// total data in the q
Alg
*
elemalg
;
// interface for element type
Link
*
senddataq
;
// pointer for sender
Link
*
recvdataq
;
// pointer for receiver
...
...
test/chancap.go
0 → 100644
View file @
8a45917f
// $G $D/$F.go && $L $F.$A && ./$A.out
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
main
func
main
()
{
c
:=
make
(
chan
int
,
10
);
if
len
(
c
)
!=
0
||
cap
(
c
)
!=
10
{
panicln
(
"chan len/cap "
,
len
(
c
),
cap
(
c
),
" want 0 10"
);
}
for
i
:=
0
;
i
<
3
;
i
++
{
c
<-
i
;
}
if
len
(
c
)
!=
3
||
cap
(
c
)
!=
10
{
panicln
(
"chan len/cap "
,
len
(
c
),
cap
(
c
),
" want 3 10"
);
}
c
=
make
(
chan
int
);
if
len
(
c
)
!=
0
||
cap
(
c
)
!=
0
{
panicln
(
"chan len/cap "
,
len
(
c
),
cap
(
c
),
" want 0 0"
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment