summary refs log tree commit diff
path: root/src/libstd
AgeCommit message (Collapse)AuthorLines
2014-02-22Reduce reliance on `to_str_radix`Brendan Zabarauskas-15/+8
This is in preparation to remove the implementations of ToStrRadix in integers, and to remove the associated logic from `std::num::strconv`. The parts that still need to be liberated are: - `std::fmt::Formatter::runplural` - `num::{bigint, complex, rational}`
2014-02-22Decouple integer formatting from std::num::strconvBrendan Zabarauskas-139/+609
This works towards a complete rewrite and ultimate removal of the `std::num::strconv` module (see #6220), and the removal of the `ToStrRadix` trait in favour of using the `std::fmt` functionality directly. This should make for a cleaner API, encourage less allocation, and make the implementation far more comprehensible. The `Formatter::pad_integral` method has also been refactored make it easier to understand. The formatting tests for integers have been moved out of `run-pass/ifmt.rs` in order to provide more immediate feedback when building using `make check-stage2-std NO_REBUILD=1`. The benchmarks have been standardised between std::num::strconv and std::num::fmt to make it easier to compare the performance of the different implementations. Arbitrary radixes are now easier to use in format strings. For example: ~~~ assert_eq!(format!("{:04}", radix(3, 2)), ~"0011"); ~~~
2014-02-22Add Pod trait bound to std::num::PrimitiveBrendan Zabarauskas-1/+3
2014-02-21auto merge of #12420 : pnkfelix/rust/fsk-improve-doc-for-ptr-offset, ↵bors-1/+2
r=alexcrichton ptr::RawPtr, spell out units used for the `offset` argument. spell out units used for the `offset` argument, so that callers do not try to scale to byte units themselves. (this was originally landed in PR #11002 for the stand-alone functions, but that PR did not modify the `RawPtr` methods, since that had no doc at all at the time. Now `RawPtr` has the *only* documentation for `offset`, since the stand-alone functions went away in PR #12167 / PR #12248.)
2014-02-21auto merge of #12419 : huonw/rust/compiler-unsafe, r=alexcrichtonbors-17/+13
Previously an `unsafe` block created by the compiler (like those in the formatting macros) would be "ignored" if surrounded by `unsafe`, that is, the internal unsafety would be being legitimised by the external block: unsafe { println!("...") } =(expansion)=> unsafe { ... unsafe { ... } } And the code in the inner block would be using the outer block, making it considered used (and the inner one considered unused). This patch forces the compiler to create a new unsafe context for compiler generated blocks, so that their internal unsafety doesn't escape to external blocks. Fixes #12418.
2014-02-22Move std::num::Integer to libnumBrendan Zabarauskas-418/+29
2014-02-21auto merge of #12410 : DaGenix/rust/fix-incorrect-comment, r=alexcrichtonbors-11/+2
The comments say that the prelude imports std::io::println since it would be annoying to have to import it in every program that uses it. However, the prelude doesn't actually import that function anymore. So, update the comments to better match reality.
2014-02-20Mass rename if_ok! to try!Alex Crichton-101/+101
This "bubble up an error" macro was originally named if_ok! in order to get it landed, but after the fact it was discovered that this name is not exactly desirable. The name `if_ok!` isn't immediately clear that is has much to do with error handling, and it doesn't look fantastic in all contexts (if if_ok!(...) {}). In general, the agreed opinion about `if_ok!` is that is came in as subpar. The name `try!` is more invocative of error handling, it's shorter by 2 letters, and it looks fitting in almost all circumstances. One concern about the word `try!` is that it's too invocative of exceptions, but the belief is that this will be overcome with documentation and examples. Close #12037
2014-02-20Return a buffered stdin by default.Alex Crichton-10/+20
One of the most common ways to use the stdin stream is to read it line by line for a small program. In order to facilitate this common usage pattern, this commit changes the stdin() function to return a BufferedReader by default. A new `stdin_raw()` method was added to get access to the raw unbuffered stream. I have not changed the stdout or stderr methods because they are currently unable to flush in their destructor, but #12403 should have just fixed that.
2014-02-20Fix some typos.Ivan Enderlin-3/+3
2014-02-20ptr::RawPtr, spell out units used for the `offset` argument.Felix S. Klock II-1/+2
spell out units used for the `offset` argument, so that callers do not try to scale to byte units themselves.
2014-02-20rustc: avoid compiler generated `unsafe` blocks leaking.Huon Wilson-17/+13
Previously an `unsafe` block created by the compiler (like those in the formatting macros) would be "ignored" if surrounded by `unsafe`, that is, the internal unsafety would be being legitimised by the external block: unsafe { println!("...") } =(expansion)=> unsafe { ... unsafe { ... } } And the code in the inner block would be using the outer block, making it considered used (and the inner one considered unused). This patch forces the compiler to create a new unsafe context for compiler generated blocks, so that their internal unsafety doesn't escape to external blocks. Fixes #12418.
2014-02-20auto merge of #12397 : alexcrichton/rust/send-off-the-runtime, r=brsonbors-10/+49
The fairness yield mistakenly called `Local::take()` which meant that it would only work if a local task was available. In theory sending on a channel (or calling try_recv) requires no runtime because it never blocks, so there's no reason it shouldn't support such a use case. Closes #12391
2014-02-20auto merge of #12343 : liigo/rust/move-extra-test-to-libtest, r=alexcrichtonbors-21/+34
I don't think `extra` is a good/meaningful name for a library. `libextra` should disappear, and we move all of its sub modules out of it. This PR is just one of that steps: move `extra::test` to `libtest`. I didn't add `libtest` to doc index, because it's an internal library currently. **Update:** All comments addressed. All tests passed. Rebased and squashed.
2014-02-20auto merge of #12396 : alexcrichton/rust/windows-env-var, r=huonwbors-1/+13
On windows, the GetEnvironmentVariable function will return the necessary buffer size if the buffer provided was too small. This case previously fell through the checks inside of fill_utf16_buf_and_decode, tripping an assertion in the `slice` method. This adds an extra case for when the return value is >= the buffer size, in which case we assume the return value as the new buffer size and try again. Closes #12376
2014-02-20move extra::test to libtestLiigo Zhuang-21/+34
2014-02-19Update comments in the preludePalmer Cox-11/+2
The comments say that the prelude imports std::io::println since it would be annoying to have to import it in every program that uses it. However, the prelude doesn't actually import that function anymore. So, update the comments to better match reality.
2014-02-19Fix sending/try_recv on channels off the runtimeAlex Crichton-10/+49
The fairness yield mistakenly called `Local::take()` which meant that it would only work if a local task was available. In theory sending on a channel (or calling try_recv) requires no runtime because it never blocks, so there's no reason it shouldn't support such a use case. Closes #12391
2014-02-19Fix getting/setting huge env vars on windowsAlex Crichton-1/+13
On windows, the GetEnvironmentVariable function will return the necessary buffer size if the buffer provided was too small. This case previously fell through the checks inside of fill_utf16_buf_and_decode, tripping an assertion in the `slice` method. This adds an extra case for when the return value is >= the buffer size, in which case we assume the return value as the new buffer size and try again. Closes #12376
2014-02-19auto merge of #12374 : dylanbraithwaite/rust/size_of_unit_clarification, r=cmrbors-5/+5
Changed the docs for std::mem to clarify the fact that the size functions return sizes in bytes.
2014-02-19rustdoc: Handle links to reexported itemsAlex Crichton-2/+5
When building up our path cache, we don't plaster over a path which was previously inserted if we're inserting a non-public-item thing. Closes #11678
2014-02-19rustdoc: Show macros in documentationAlex Crichton-1/+173
Any macro tagged with #[macro_export] will be showed in the documentation for that module. This also documents all the existing macros inside of std::macros. Closes #3163 cc #5605 Closes #9954
2014-02-18auto merge of #12317 : huonw/rust/utf16, r=alexcrichtonbors-50/+305
Iterators! Use them (in `is_utf16`), create them (in `utf16_items`). Handle errors gracefully (`from_utf16_lossy`) and `from_utf16` returning `Option<~str>` instead of failing. Add a pile of tests.
2014-02-19str: add a function for truncating a vector of u16 at NUL.Huon Wilson-3/+51
Many of the functions interacting with Windows APIs allocate a vector of 0's and do not retrieve a length directly from the API call, and so need to be sure to remove the unmodified junk at the end of the vector.
2014-02-18Clarify unit of size in docs for size_of functions.Dylan Braithwaite-5/+5
Changed the docs in mem.rs to clarify the fact the the size functions return sizes in bytes.
2014-02-18auto merge of #12357 : chromatic/rust/gh_11976_fail_bounds_check_str, ↵bors-2/+12
r=alexcrichton Fixes #11976.
2014-02-18auto merge of #12314 : huonw/rust/is_utf8_iter, r=kballardbors-45/+70
See the commit messages for more details, but this makes `std::str::is_utf8` slightly faster and 100% non-`unsafe` and uses a similar thing to make the first scan of `from_utf8_lossy` 100% safe & faster.
2014-02-18std: convert first_non_utf8_byte to use the iterator.Huon Wilson-61/+11
This makes it very slightly faster, especially when the string is valid UTF-8, and completely removes the use of `unsafe` from the first half. Before: from_utf8_lossy_100_ascii ... bench: 151 ns/iter (+/- 17) from_utf8_lossy_100_invalid ... bench: 447 ns/iter (+/- 33) from_utf8_lossy_100_multibyte ... bench: 135 ns/iter (+/- 4) from_utf8_lossy_invalid ... bench: 124 ns/iter (+/- 10 After: from_utf8_lossy_100_ascii ... bench: 119 ns/iter (+/- 8) from_utf8_lossy_100_invalid ... bench: 454 ns/iter (+/- 16) from_utf8_lossy_100_multibyte ... bench: 116 ns/iter (+/- 9) from_utf8_lossy_invalid ... bench: 119 ns/iter (+/- 9)
2014-02-18std::str: safen and optimize is_utf8.Huon Wilson-2/+77
This uses a vector iterator to avoid the necessity for unsafe indexing, and makes this function slightly faster. Unfortunately #11751 means that the iterator comes with repeated `null` checks which means the pure-ASCII case still has room for significant improvement (and the other cases too, but it's most significant for just ASCII). Before: is_utf8_100_ascii ... bench: 143 ns/iter (+/- 6) is_utf8_100_multibyte ... bench: 134 ns/iter (+/- 4) After: is_utf8_100_ascii ... bench: 123 ns/iter (+/- 4) is_utf8_100_multibyte ... bench: 115 ns/iter (+/- 5)
2014-02-18auto merge of #12345 : huonw/rust/speeling, r=cmrbors-7/+6
2014-02-17auto merge of #12321 : bjz/rust/remove-real, r=alexcrichtonbors-504/+494
This is part of the effort to simplify `std::num`, as tracked in issue #10387. It is also a step towards a proper IEEE-754 trait (see #12281).
2014-02-17auto merge of #12103 : alexcrichton/rust/unix, r=brsonbors-42/+134
There's a few parts to this PR * Implement unix pipes in libnative for unix platforms (thanks @Geal!) * Implement named pipes in libnative for windows (terrible, terrible code) * Remove `#[cfg(unix)]` from `mod unix` in `std::io::net`. This is a terrible name for what it is, but that's the topic of #12093. The windows implementation was significantly more complicated than I thought it would be, but it seems to be passing all the tests. now. Closes #11201
2014-02-17Made fail_bounds_check more careful with strings.chromatic-2/+12
Fixes GH #11976.
2014-02-17auto merge of #12232 : kballard/rust/taskbuilder-is-a-builder, r=alexcrichtonbors-95/+26
Delete all the documentation from std::task that references linked failure. Tweak TaskBuilder to be more builder-like. `.name()` is now `.named()` and `.add_wrapper()` is now `.with_wrapper()`. Remove `.watched()` and `.unwatched()` as they didn't actually do anything. Closes #6399.
2014-02-17Fix a deadlock in channels, again.Alex Crichton-4/+4
This deadlock was caused when the channel was closed at just the right time, so the extra `self.cnt.fetch_add` actually should have preserved the DISCONNECTED state of the channel. by modifying this the channel entered a state such that the port would never succeed in dropping. This also moves the increment of self.steals until after the MAX_STEALS block. The reason for this is that in 'fn recv()' the steals variable is decremented immediately after the try_recv(), which could in theory set steals to -1 if it was previously set to 0 in try_recv(). Closes #12340
2014-02-18Spellcheck library docs.Huon Wilson-7/+6
2014-02-17auto merge of #12331 : bjz/rust/count-ones, r=alexcrichtonbors-39/+89
This is inspired by the [function naming in the Julia standard library](http://docs.julialang.org/en/release-0.2/stdlib/base/#Base.count_ones). It seems like a more self-explanatory name, and is more consistent with the accompanying methods, `leading_zeros` and `trailing_zeros`.
2014-02-17auto merge of #12325 : big-guy/rust/doc-fixes, r=alexcrichtonbors-3/+3
* Change '...your own time' => '...your own type' * Fix typo in the Vector2D example
2014-02-18std: make str::from_utf16 return an Option.Huon Wilson-23/+46
The rest of the codebase is moving toward avoiding `fail!` so we do it here too!
2014-02-17std: decode even numbered non-BMP planes in the UTF-16 decoder.Huon Wilson-2/+5
Fixes #12318.
2014-02-17str: provide lossy UTF-16 support.Huon Wilson-23/+133
This replaces the iterator with one that handles lone surrogates gracefully and uses that to implement `from_utf16_lossy` which replaces invalid `u16`s with U+FFFD.
2014-02-17std: convert str::from_utf16 to an external iterator.Huon Wilson-27/+38
Fixes #12316.
2014-02-17std: iteratize str::is_utf16 & add tests.Huon Wilson-18/+78
Most of the tests are randomly generated with Python 3 and rely on it's UTF-16be encoder/decoder being correct.
2014-02-17Rename Bitwise::population_count to Bitwise::count_ones and add ↵Brendan Zabarauskas-39/+89
Bitwise::count_zeros These are inspired by the [functions in the Julia standard library](http://docs.julialang.org/en/release-0.2/stdlib/base/#Base.count_ones).
2014-02-16Implement named pipes for windows, touch up unixAlex Crichton-51/+114
* Implementation of pipe_win32 filled out for libnative * Reorganize pipes to be clone-able * Fix a few file descriptor leaks on error * Factor out some common code into shared functions * Make use of the if_ok!() macro for less indentation Closes #11201
2014-02-16Implement Unix domain sockets in libnativeGeoffroy Couprie-0/+29
2014-02-16Allow configuration of uid/gid/detach on processesAlex Crichton-31/+138
This just copies the libuv implementation for libnative which seems reasonable enough (uid/gid fail on windows). Closes #12082
2014-02-16Clean up std::task docs, make TaskBuilder a real builderKevin Ballard-95/+26
Delete all the documentation from std::task that references linked failure. Tweak TaskBuilder to be more builder-like. .name() is now .named() and .add_wrapper() is now .with_wrapper(). Remove .watched() and .unwatched() as they didn't actually do anything.
2014-02-16Minor documentation fixes in std::fmtSterling Greene-3/+3
* Change '...your own time' => '...your own type' * Fix typo in the Vector2D example
2014-02-17Remove Real trait and move methods into FloatBrendan Zabarauskas-504/+494
This is part of the effort to simplify `std::num`, as tracked in issue #10387.