about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorBrian Anderson <andersrb@gmail.com>2011-01-07 21:29:32 -0500
committerGraydon Hoare <graydon@mozilla.com>2011-01-10 11:31:32 -0800
commit04056d89c831767f3c71a0cc274e7c17b5721734 (patch)
tree1b82e86ead3fa0089c2e17729390beb133435262 /src
parent32c1c9f55c7a5575aa462bcec9e00cd11273841a (diff)
downloadrust-04056d89c831767f3c71a0cc274e7c17b5721734.tar.gz
rust-04056d89c831767f3c71a0cc274e7c17b5721734.zip
Fix the check for growing the circular_buffer
Diffstat (limited to 'src')
-rw-r--r--src/rt/circular_buffer.cpp2
-rw-r--r--src/test/run-pass/chan-poweroftwo.rs14
2 files changed, 15 insertions, 1 deletions
diff --git a/src/rt/circular_buffer.cpp b/src/rt/circular_buffer.cpp
index bdf251248cd..77509abb069 100644
--- a/src/rt/circular_buffer.cpp
+++ b/src/rt/circular_buffer.cpp
@@ -62,7 +62,7 @@ circular_buffer::enqueue(void *src) {
     I(dom, _unread <= _buffer_sz);
 
     // Grow if necessary.
-    if (_unread == _buffer_sz) {
+    if (_unread + unit_sz > _buffer_sz) {
         size_t new_buffer_sz = _buffer_sz << 1;
         I(dom, new_buffer_sz <= MAX_CIRCULAR_BUFFFER_SIZE);
         void *new_buffer = dom->malloc(new_buffer_sz);
diff --git a/src/test/run-pass/chan-poweroftwo.rs b/src/test/run-pass/chan-poweroftwo.rs
index fc05d7cc047..f3a4b9b5d66 100644
--- a/src/test/run-pass/chan-poweroftwo.rs
+++ b/src/test/run-pass/chan-poweroftwo.rs
@@ -25,8 +25,22 @@ impure fn test_init() {
     mychan <| val;
 }
 
+// Dump lots of items into the channel so it has to grow.
+// Don't trigger any assertions.
+impure fn test_grow() {
+    let port[record] myport = port();
+    auto mychan = chan(myport);
+
+    let record val = rec(val1=0i32, val2=0i32, val3=0i32);
+
+    for each (uint i in _uint.range(0u, 100u)) {
+        mychan <| val;
+    }
+}
+
 impure fn main() {
     test_init();
+    test_grow();
 }
 
 // Local Variables: