diff options
| author | Graydon Hoare <[email protected]> | 2011-05-02 16:24:09 -0700 |
|---|---|---|
| committer | Graydon Hoare <[email protected]> | 2011-05-02 17:35:33 -0700 |
| commit | d08b443fffb1181d8d45ae5d061412f202dd4118 (patch) | |
| tree | ad75b4e4fc9407aa1201f9068012f30664d17b64 /src/lib | |
| parent | Add a regression test that exports can expose unexported items (diff) | |
| download | rust-d08b443fffb1181d8d45ae5d061412f202dd4118.tar.xz rust-d08b443fffb1181d8d45ae5d061412f202dd4118.zip | |
Revert "Use different syntax for checks that matter to typestate"
This reverts commit aa25f22f197682de3b18fc4c8ba068d1feda220f. It broke stage2, not sure why yet.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/Term.rs | 2 | ||||
| -rw-r--r-- | src/lib/_int.rs | 2 | ||||
| -rw-r--r-- | src/lib/_str.rs | 14 | ||||
| -rw-r--r-- | src/lib/_uint.rs | 2 | ||||
| -rw-r--r-- | src/lib/_vec.rs | 11 | ||||
| -rw-r--r-- | src/lib/bitv.rs | 10 | ||||
| -rw-r--r-- | src/lib/deque.rs | 2 | ||||
| -rw-r--r-- | src/lib/ebml.rs | 2 | ||||
| -rw-r--r-- | src/lib/fs.rs | 2 | ||||
| -rw-r--r-- | src/lib/io.rs | 10 | ||||
| -rw-r--r-- | src/lib/linux_os.rs | 4 | ||||
| -rw-r--r-- | src/lib/macos_os.rs | 4 | ||||
| -rw-r--r-- | src/lib/posix_fs.rs | 2 | ||||
| -rw-r--r-- | src/lib/sha1.rs | 8 | ||||
| -rw-r--r-- | src/lib/win32_os.rs | 2 |
15 files changed, 38 insertions, 39 deletions
diff --git a/src/lib/Term.rs b/src/lib/Term.rs index 368fe217..0d925d7d 100644 --- a/src/lib/Term.rs +++ b/src/lib/Term.rs @@ -35,7 +35,7 @@ fn color_supported() -> bool { } fn set_color(io.buf_writer writer, u8 first_char, u8 color) { - assert (color < 16u8); + check (color < 16u8); esc(writer); if (color >= 8u8) { diff --git a/src/lib/_int.rs b/src/lib/_int.rs index 1824d142..dfd2204d 100644 --- a/src/lib/_int.rs +++ b/src/lib/_int.rs @@ -27,7 +27,7 @@ iter range(int lo, int hi) -> int { fn to_str(int n, uint radix) -> str { - assert (0u < radix && radix <= 16u); + check (0u < radix && radix <= 16u); if (n < 0) { ret "-" + _uint.to_str((-n) as uint, radix); } else { diff --git a/src/lib/_str.rs b/src/lib/_str.rs index ed2027e1..44f14fb6 100644 --- a/src/lib/_str.rs +++ b/src/lib/_str.rs @@ -218,14 +218,14 @@ fn utf8_char_width(u8 b) -> uint { fn char_range_at(str s, uint i) -> tup(char, uint) { auto b0 = s.(i); auto w = utf8_char_width(b0); - assert (w != 0u); + check(w != 0u); if (w == 1u) {ret tup(b0 as char, i + 1u);} auto val = 0u; auto end = i + w; i += 1u; while (i < end) { auto byte = s.(i); - assert (byte & 0xc0_u8 == tag_cont_u8); + check(byte & 0xc0_u8 == tag_cont_u8); val <<= 6u; val += (byte & 0x3f_u8) as uint; i += 1u; @@ -247,11 +247,11 @@ fn char_len(str s) -> uint { auto total = byte_len(s); while (i < total) { auto chsize = utf8_char_width(s.(i)); - assert (chsize > 0u); + check(chsize > 0u); len += 1u; i += chsize; } - assert (i == total); + check(i == total); ret len; } @@ -274,7 +274,7 @@ fn push_char(&mutable str s, char ch) { fn pop_char(&mutable str s) -> char { auto end = byte_len(s); while (end > 0u && s.(end - 1u) & 0xc0_u8 == tag_cont_u8) {end -= 1u;} - assert (end > 0u); + check(end > 0u); auto ch = char_at(s, end - 1u); s = substr(s, 0u, end - 1u); ret ch; @@ -404,7 +404,7 @@ fn slice(str s, uint begin, uint end) -> str { fn shift_byte(&mutable str s) -> u8 { auto len = byte_len(s); - assert (len > 0u); + check(len > 0u); auto b = s.(0); s = substr(s, 1u, len - 1u); ret b; @@ -412,7 +412,7 @@ fn shift_byte(&mutable str s) -> u8 { fn pop_byte(&mutable str s) -> u8 { auto len = byte_len(s); - assert (len > 0u); + check(len > 0u); auto b = s.(len - 1u); s = substr(s, 0u, len - 1u); ret b; diff --git a/src/lib/_uint.rs b/src/lib/_uint.rs index 2d373cdd..97108c90 100644 --- a/src/lib/_uint.rs +++ b/src/lib/_uint.rs @@ -56,7 +56,7 @@ fn to_str(uint num, uint radix) -> str { auto n = num; - assert (0u < radix && radix <= 16u); + check (0u < radix && radix <= 16u); fn digit(uint n) -> char { alt (n) { case (0u) { ret '0'; } diff --git a/src/lib/_vec.rs b/src/lib/_vec.rs index 4761a867..126bf363 100644 --- a/src/lib/_vec.rs +++ b/src/lib/_vec.rs @@ -131,7 +131,7 @@ fn len_set[T](array[T] v, uint n) { } fn buf_off[T](array[T] v, uint offset) -> vbuf { - assert (offset < len[T](v)); + check (offset < len[T](v)); ret rustrt.vec_buf[T](v, offset); } @@ -149,10 +149,9 @@ fn last[T](array[T] v) -> option.t[T] { } // Returns elements from [start..end) from v. - fn slice[T](array[T] v, uint start, uint end) -> vec[T] { - assert (start <= end); - assert (end <= len[T](v)); + check (start <= end); + check (end <= len[T](v)); auto result = alloc[T](end - start); let uint i = start; while (i < end) { @@ -164,7 +163,7 @@ fn slice[T](array[T] v, uint start, uint end) -> vec[T] { fn shift[T](&mutable array[T] v) -> T { auto ln = len[T](v); - assert (ln > 0u); + check(ln > 0u); auto e = v.(0); v = slice[T](v, 1u, ln); ret e; @@ -172,7 +171,7 @@ fn shift[T](&mutable array[T] v) -> T { fn pop[T](&mutable array[T] v) -> T { auto ln = len[T](v); - assert (ln > 0u); + check(ln > 0u); ln -= 1u; auto e = v.(ln); v = slice[T](v, 0u, ln); diff --git a/src/lib/bitv.rs b/src/lib/bitv.rs index f52b016b..feb4296a 100644 --- a/src/lib/bitv.rs +++ b/src/lib/bitv.rs @@ -28,8 +28,8 @@ fn create(uint nbits, bool init) -> t { fn process(&fn(uint, uint) -> uint op, &t v0, &t v1) -> bool { auto len = _vec.len[mutable uint](v1.storage); - assert (_vec.len[mutable uint](v0.storage) == len); - assert (v0.nbits == v1.nbits); + check (_vec.len[mutable uint](v0.storage) == len); + check (v0.nbits == v1.nbits); auto changed = false; @@ -84,7 +84,7 @@ fn clone(t v) -> t { } fn get(&t v, uint i) -> bool { - assert (i < v.nbits); + check (i < v.nbits); auto bits = uint_bits(); @@ -129,7 +129,7 @@ fn difference(&t v0, &t v1) -> bool { } fn set(&t v, uint i, bool x) { - assert (i < v.nbits); + check (i < v.nbits); auto bits = uint_bits(); @@ -196,7 +196,7 @@ fn to_str(&t v) -> str { // FIXME: can we just use structural equality on to_vec? fn eq_vec(&t v0, &vec[uint] v1) -> bool { - assert (v0.nbits == _vec.len[uint](v1)); + check (v0.nbits == _vec.len[uint](v1)); auto len = v0.nbits; auto i = 0u; while (i < len) { diff --git a/src/lib/deque.rs b/src/lib/deque.rs index ee706ae7..776f82e9 100644 --- a/src/lib/deque.rs +++ b/src/lib/deque.rs @@ -28,7 +28,7 @@ fn create[T]() -> t[T] { * elsewhere. */ fn grow[T](uint nelts, uint lo, vec[cell[T]] elts) -> vec[cell[T]] { - assert (nelts == _vec.len[cell[T]](elts)); + check (nelts == _vec.len[cell[T]](elts)); fn fill[T](uint i, uint nelts, uint lo, vec[cell[T]] old) -> cell[T] { diff --git a/src/lib/ebml.rs b/src/lib/ebml.rs index 9bad0f33..f73ad4fc 100644 --- a/src/lib/ebml.rs +++ b/src/lib/ebml.rs @@ -99,7 +99,7 @@ fn doc_data(doc d) -> vec[u8] { fn be_uint_from_bytes(vec[u8] data, uint start, uint size) -> uint { auto sz = size; - assert (sz <= 4u); + check (sz <= 4u); auto val = 0u; auto pos = start; while (sz > 0u) { diff --git a/src/lib/fs.rs b/src/lib/fs.rs index e185ca3e..774ce113 100644 --- a/src/lib/fs.rs +++ b/src/lib/fs.rs @@ -10,7 +10,7 @@ type path = str; fn dirname(path p) -> path { auto sep = path_sep(); - assert (_str.byte_len(sep) == 1u); + check (_str.byte_len(sep) == 1u); let int i = _str.rindex(p, sep.(0)); if (i == -1) { ret p; diff --git a/src/lib/io.rs b/src/lib/io.rs index 7d59da30..4c1bf2df 100644 --- a/src/lib/io.rs +++ b/src/lib/io.rs @@ -72,7 +72,7 @@ state obj FILE_buf_reader(os.libc.FILE f, bool must_close) { ret os.libc.feof(f) != 0; } fn seek(int offset, seek_style whence) { - assert (os.libc.fseek(f, offset, convert_whence(whence)) == 0); + check (os.libc.fseek(f, offset, convert_whence(whence)) == 0); } fn tell() -> uint { ret os.libc.ftell(f) as uint; @@ -101,14 +101,14 @@ state obj new_reader(buf_reader rdr) { if (c0 == -1) {ret -1 as char;} // FIXME will this stay valid? auto b0 = c0 as u8; auto w = _str.utf8_char_width(b0); - assert (w > 0u); + check(w > 0u); if (w == 1u) {ret b0 as char;} auto val = 0u; while (w > 1u) { w -= 1u; auto next = rdr.read_byte(); - assert (next > -1); - assert (next & 0xc0 == 0x80); + check(next > -1); + check(next & 0xc0 == 0x80); val <<= 6u; val += (next & 0x3f) as uint; } @@ -279,7 +279,7 @@ state obj FILE_writer(os.libc.FILE f, bool must_close) { } fn seek(int offset, seek_style whence) { - assert (os.libc.fseek(f, offset, convert_whence(whence)) == 0); + check(os.libc.fseek(f, offset, convert_whence(whence)) == 0); } fn tell() -> uint { diff --git a/src/lib/linux_os.rs b/src/lib/linux_os.rs index d2a8ff97..d5230e9a 100644 --- a/src/lib/linux_os.rs +++ b/src/lib/linux_os.rs @@ -66,7 +66,7 @@ fn dylib_filename(str base) -> str { fn pipe() -> tup(int, int) { let vec[mutable int] fds = vec(mutable 0, 0); - assert (os.libc.pipe(_vec.buf[mutable int](fds)) == 0); + check(os.libc.pipe(_vec.buf[mutable int](fds)) == 0); ret tup(fds.(0), fds.(1)); } @@ -76,7 +76,7 @@ fn fd_FILE(int fd) -> libc.FILE { fn waitpid(int pid) -> int { let vec[mutable int] status = vec(mutable 0); - assert (os.libc.waitpid(pid, _vec.buf[mutable int](status), 0) != -1); + check(os.libc.waitpid(pid, _vec.buf[mutable int](status), 0) != -1); ret status.(0); } diff --git a/src/lib/macos_os.rs b/src/lib/macos_os.rs index a52b02c5..b0980bc5 100644 --- a/src/lib/macos_os.rs +++ b/src/lib/macos_os.rs @@ -63,7 +63,7 @@ fn dylib_filename(str base) -> str { fn pipe() -> tup(int, int) { let vec[mutable int] fds = vec(mutable 0, 0); - assert (os.libc.pipe(_vec.buf[mutable int](fds)) == 0); + check(os.libc.pipe(_vec.buf[mutable int](fds)) == 0); ret tup(fds.(0), fds.(1)); } @@ -73,7 +73,7 @@ fn fd_FILE(int fd) -> libc.FILE { fn waitpid(int pid) -> int { let vec[mutable int] status = vec(mutable 0); - assert (os.libc.waitpid(pid, _vec.buf[mutable int](status), 0) != -1); + check(os.libc.waitpid(pid, _vec.buf[mutable int](status), 0) != -1); ret status.(0); } diff --git a/src/lib/posix_fs.rs b/src/lib/posix_fs.rs index f4cf12d3..03115fc7 100644 --- a/src/lib/posix_fs.rs +++ b/src/lib/posix_fs.rs @@ -5,7 +5,7 @@ native "rust" mod rustrt { fn list_dir(str path) -> vec[str] { // TODO ensure this is always closed auto dir = os.libc.opendir(_str.buf(path)); - assert (dir as uint != 0u); + check (dir as uint != 0u); let vec[str] result = vec(); while (true) { auto ent = os.libc.readdir(dir); diff --git a/src/lib/sha1.rs b/src/lib/sha1.rs index 690489db..3866be1e 100644 --- a/src/lib/sha1.rs +++ b/src/lib/sha1.rs @@ -43,7 +43,7 @@ fn mk_sha1() -> sha1 { fn add_input(&sha1state st, &vec[u8] msg) { // FIXME: Should be typestate precondition - assert (!st.computed); + check (!st.computed); for (u8 element in msg) { st.msg_block.(st.msg_block_idx) = element; @@ -67,7 +67,7 @@ fn mk_sha1() -> sha1 { fn process_msg_block(&sha1state st) { // FIXME: Make precondition - assert (_vec.len[mutable u32](st.h) == digest_buf_len); + check (_vec.len[mutable u32](st.h) == digest_buf_len); // Constants auto k = vec(0x5A827999u32, @@ -192,7 +192,7 @@ fn mk_sha1() -> sha1 { */ fn pad_msg(&sha1state st) { // FIXME: Should be a precondition - assert (_vec.len[mutable u8](st.msg_block) == msg_block_len); + check (_vec.len[mutable u8](st.msg_block) == msg_block_len); /* * Check to see if the current message block is too small to hold @@ -236,7 +236,7 @@ fn mk_sha1() -> sha1 { fn reset() { // FIXME: Should be typestate precondition - assert (_vec.len[mutable u32](st.h) == digest_buf_len); + check (_vec.len[mutable u32](st.h) == digest_buf_len); st.len_low = 0u32; st.len_high = 0u32; diff --git a/src/lib/win32_os.rs b/src/lib/win32_os.rs index 1c6521e3..a2940d8d 100644 --- a/src/lib/win32_os.rs +++ b/src/lib/win32_os.rs @@ -53,7 +53,7 @@ fn dylib_filename(str base) -> str { fn pipe() -> tup(int, int) { let vec[mutable int] fds = vec(mutable 0, 0); - assert (os.libc._pipe(_vec.buf[mutable int](fds), 1024u, + check(os.libc._pipe(_vec.buf[mutable int](fds), 1024u, libc_constants.O_BINARY()) == 0); ret tup(fds.(0), fds.(1)); } |