提交 4a7aa75b 编写于 作者: R Roy Frostig

Make _io.buf_reader read more than 0 bytes at a time.

上级 b6b348a1
...@@ -48,7 +48,7 @@ fn read() -> vec[u8] { ...@@ -48,7 +48,7 @@ fn read() -> vec[u8] {
buf = new_buf(); buf = new_buf();
} }
auto len = _vec.len[u8](buf); auto len = default_bufsz();
auto vbuf = _vec.buf[u8](buf); auto vbuf = _vec.buf[u8](buf);
auto count = os.libc.read(fd, vbuf, len); auto count = os.libc.read(fd, vbuf, len);
...@@ -56,9 +56,10 @@ fn read() -> vec[u8] { ...@@ -56,9 +56,10 @@ fn read() -> vec[u8] {
log "error filling buffer"; log "error filling buffer";
log sys.rustrt.last_os_error(); log sys.rustrt.last_os_error();
fail; fail;
} else {
ret buf;
} }
_vec.len_set[u8](buf, count as uint);
ret buf;
} }
drop { drop {
......
...@@ -3,13 +3,25 @@ ...@@ -3,13 +3,25 @@
native "rust" mod rustrt { native "rust" mod rustrt {
type vbuf; type vbuf;
fn vec_buf[T](vec[T] v, uint offset) -> vbuf; fn vec_buf[T](vec[T] v, uint offset) -> vbuf;
fn vec_len[T](vec[T] v) -> uint; fn vec_len[T](vec[T] v) -> uint;
/* The T in vec_alloc[T, U] is the type of the vec to allocate. The /**
* Sometimes we modify the vec internal data via vec_buf and need to update
* the vec's fill length accordingly.
*/
fn vec_len_set[T](vec[T] v, uint n);
/**
* The T in vec_alloc[T, U] is the type of the vec to allocate. The
* U is the type of an element in the vec. So to allocate a vec[U] we * U is the type of an element in the vec. So to allocate a vec[U] we
* want to invoke this as vec_alloc[vec[U], U]. */ * want to invoke this as vec_alloc[vec[U], U].
*/
fn vec_alloc[T, U](uint n_elts) -> vec[U]; fn vec_alloc[T, U](uint n_elts) -> vec[U];
fn refcount[T](vec[T] v) -> uint; fn refcount[T](vec[T] v) -> uint;
fn vec_print_debug_info[T](vec[T] v); fn vec_print_debug_info[T](vec[T] v);
} }
...@@ -46,12 +58,16 @@ fn init_elt[T](&T t, uint n_elts) -> vec[T] { ...@@ -46,12 +58,16 @@ fn init_elt[T](&T t, uint n_elts) -> vec[T] {
ret v; ret v;
} }
fn buf[T](vec[T] v) -> vbuf {
ret rustrt.vec_buf[T](v, 0u);
}
fn len[T](vec[T] v) -> uint { fn len[T](vec[T] v) -> uint {
ret rustrt.vec_len[T](v); ret rustrt.vec_len[T](v);
} }
fn buf[T](vec[T] v) -> vbuf { fn len_set[T](vec[T] v, uint n) {
ret rustrt.vec_buf[T](v, 0u); rustrt.vec_len_set[T](v, n);
} }
fn buf_off[T](vec[T] v, uint offset) -> vbuf { fn buf_off[T](vec[T] v, uint offset) -> vbuf {
......
...@@ -108,6 +108,19 @@ vec_len(rust_task *task, type_desc *ty, rust_vec *v) ...@@ -108,6 +108,19 @@ vec_len(rust_task *task, type_desc *ty, rust_vec *v)
return v->fill / ty->size; return v->fill / ty->size;
} }
extern "C" CDECL void
vec_len_set(rust_task *task, type_desc *ty, rust_vec *v, size_t len)
{
task->log(rust_log::STDLIB,
"vec_len_set(0x%" PRIxPTR ", %" PRIdPTR ") on vec with "
"alloc = %" PRIdPTR
", fill = %" PRIdPTR
", len = %" PRIdPTR
". New fill is %" PRIdPTR,
v, len, v->alloc, v->fill, v->fill / ty->size, len * ty->size);
v->fill = len * ty->size;
}
extern "C" CDECL void extern "C" CDECL void
vec_print_debug_info(rust_task *task, type_desc *ty, rust_vec *v) vec_print_debug_info(rust_task *task, type_desc *ty, rust_vec *v)
{ {
...@@ -115,8 +128,15 @@ vec_print_debug_info(rust_task *task, type_desc *ty, rust_vec *v) ...@@ -115,8 +128,15 @@ vec_print_debug_info(rust_task *task, type_desc *ty, rust_vec *v)
"vec_print_debug_info(0x%" PRIxPTR ")" "vec_print_debug_info(0x%" PRIxPTR ")"
" with tydesc 0x%" PRIxPTR " with tydesc 0x%" PRIxPTR
" (size = %" PRIdPTR ", align = %" PRIdPTR ")" " (size = %" PRIdPTR ", align = %" PRIdPTR ")"
" alloc = %" PRIdPTR ", fill = %" PRIdPTR " alloc = %" PRIdPTR ", fill = %" PRIdPTR ", len = %" PRIdPTR
" , data = ...", v, ty, ty->size, ty->align, v->alloc, v->fill); " , data = ...",
v,
ty,
ty->size,
ty->align,
v->alloc,
v->fill,
v->fill / ty->size);
for (size_t i = 0; i < v->fill; ++i) { for (size_t i = 0; i < v->fill; ++i) {
task->log(rust_log::STDLIB, task->log(rust_log::STDLIB,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册