summaryrefslogtreecommitdiff
path: root/src/pkg/reflect
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/reflect')
-rw-r--r--src/pkg/reflect/all_test.go11
-rw-r--r--src/pkg/reflect/value.go12
2 files changed, 23 insertions, 0 deletions
diff --git a/src/pkg/reflect/all_test.go b/src/pkg/reflect/all_test.go
index 3a1c220da..2a30ddd87 100644
--- a/src/pkg/reflect/all_test.go
+++ b/src/pkg/reflect/all_test.go
@@ -757,6 +757,17 @@ func TestChan(t *testing.T) {
if cv.TryRecv() != nil {
t.Errorf("TryRecv on sync chan succeeded");
}
+
+ // len/cap
+ cv = MakeChan(Typeof(c).(*ChanType), 10);
+ c = cv.Interface().(chan int);
+ for i := 0; i < 3; i++ {
+ c <- i;
+ }
+ if l, m := cv.Len(), cv.Cap(); l != len(c) || m != cap(c) {
+ t.Errorf("Len/Cap = %d/%d want %d/%d", l, m, len(c), cap(c));
+ }
+
}
// Difficult test for function call because of
diff --git a/src/pkg/reflect/value.go b/src/pkg/reflect/value.go
index daa3f11ba..014ea933c 100644
--- a/src/pkg/reflect/value.go
+++ b/src/pkg/reflect/value.go
@@ -636,6 +636,8 @@ func chansend(ch, val *byte, pres *bool)
func chanrecv(ch, val *byte, pres *bool)
func chanclosed(ch *byte) bool
func chanclose(ch *byte)
+func chanlen(ch *byte) int32
+func chancap(ch *byte) int32
// Closed returns the result of closed(c) on the underlying channel.
func (v *ChanValue) Closed() bool {
@@ -649,6 +651,16 @@ func (v *ChanValue) Close() {
chanclose(ch);
}
+func (v *ChanValue) Len() int {
+ ch := *(**byte)(v.addr);
+ return int(chanlen(ch));
+}
+
+func (v *ChanValue) Cap() int {
+ ch := *(**byte)(v.addr);
+ return int(chancap(ch));
+}
+
// internal send; non-blocking if b != nil
func (v *ChanValue) send(x Value, b *bool) {
t := v.Type().(*ChanType);