about summary refs log tree commit diff
path: root/src/libstd
AgeCommit message (Collapse)AuthorLines
2014-05-14Add ToCStr impl for &Path and StrBufAaron Turon-3/+95
This is a stopgap until DST (#12938) lands. Until DST lands, we cannot decompose &str into & and str, so we cannot usefully take ToCStr arguments by reference (without forcing an additional & around &str). So we are instead temporarily adding an instance for &Path and StrBuf, so that we can take ToCStr as owned. When DST lands, the &Path instance should be removed, the string instances should be revisted, and arguments bound by ToCStr should be passed by reference. FIXMEs have been added accordingly.
2014-05-14auto merge of #14133 : db48x/rust/ord-for-mut-refs, r=alexcrichtonbors-0/+3
Also Show, which is useful in assertions. Fixes #14074
2014-05-14librand: Remove all uses of `~str` from `librand`Patrick Walton-3/+3
2014-05-14Change StrBuf::from_utf8() to return ResultKevin Ballard-5/+10
This allows the original vector to be recovered in the event that it is not UTF-8. [breaking-change]
2014-05-14Change str::from_utf8_owned() to return ResultKevin Ballard-7/+10
This allows the original vector to be recovered in the event that it is not valid UTF-8. [breaking-change]
2014-05-14Added substring searching benchmarks.Jonathan S-0/+74
test str::bench::bench_contains_bad_naive ... bench: 1309 ns/iter (+/- 36) test str::bench::bench_contains_equal ... bench: 137 ns/iter (+/- 2) test str::bench::bench_contains_short_long ... bench: 5473 ns/iter (+/- 14) test str::bench::bench_contains_short_short ... bench: 57 ns/iter (+/- 6)
2014-05-14auto merge of #14009 : jcmoyer/rust/bitflags-complement, r=alexcrichtonbors-2/+32
I feel that this is a very vital, missing piece of functionality. This adds on to #13072. Only bits used in the definition of the bitflag are considered for the universe set. This is a bit safer than simply inverting all of the bits in the wrapped value. ```rust bitflags!(flags Flags: u32 { FlagA = 0x00000001, FlagB = 0x00000010, FlagC = 0x00000100, FlagABC = FlagA.bits | FlagB.bits | FlagC.bits }) ... // `Not` implements set complement assert!(!(FlagB | FlagC) == FlagA); // `all` and `is_all` are the inverses of `empty` and `is_empty` assert!(Flags::all() - FlagA == !FlagA); assert!(FlagABC.is_all()); ```
2014-05-14auto merge of #14186 : omasanori/rust/suppress-warnings, r=alexcrichtonbors-1/+1
2014-05-14Implement set complement and universe for bitflagsJ.C. Moyer-2/+32
2014-05-14define Eq,TotalEq,Ord,TotalOrd for &mut TDaniel Brooks-0/+3
Also Show, which is useful in assertions. Fixes #14074
2014-05-13core: Inherit the atomics moduleAlex Crichton-795/+21
2014-05-13auto merge of #13127 : kballard/rust/read_at_least, r=alexcrichtonbors-82/+251
Reader.read_at_least() ensures that at least a given number of bytes have been read. The most common use-case for this is ensuring at least 1 byte has been read. If the reader returns 0 enough times in a row, a new error kind NoProgress will be returned instead of looping infinitely. This change is necessary in order to properly support Readers that repeatedly return 0, either because they're broken, or because they're attempting to do a non-blocking read on some resource that never becomes available. Also add .push() and .push_at_least() methods. push() is like read() but the results are appended to the passed Vec. Remove Reader.fill() and Reader.push_exact() as they end up being thin wrappers around read_at_least() and push_at_least(). [breaking-change]
2014-05-13io: Add .read_at_least() to ReaderKevin Ballard-82/+251
Reader.read_at_least() ensures that at least a given number of bytes have been read. The most common use-case for this is ensuring at least 1 byte has been read. If the reader returns 0 enough times in a row, a new error kind NoProgress will be returned instead of looping infinitely. This change is necessary in order to properly support Readers that repeatedly return 0, either because they're broken, or because they're attempting to do a non-blocking read on some resource that never becomes available. Also add .push() and .push_at_least() methods. push() is like read() but the results are appended to the passed Vec. Remove Reader.fill() and Reader.push_exact() as they end up being thin wrappers around read_at_least() and push_at_least(). [breaking-change]
2014-05-13io: Implement process wait timeoutsAlex Crichton-60/+133
This implements set_timeout() for std::io::Process which will affect wait() operations on the process. This follows the same pattern as the rest of the timeouts emerging in std::io::net. The implementation was super easy for everything except libnative on unix (backwards from usual!), which required a good bit of signal handling. There's a doc comment explaining the strategy in libnative. Internally, this also required refactoring the "helper thread" implementation used by libnative to allow for an extra helper thread (not just the timer). This is a breaking change in terms of the io::Process API. It is now possible for wait() to fail, and subsequently wait_with_output(). These two functions now return IoResult<T> due to the fact that they can time out. Additionally, the wait_with_output() function has moved from taking `&mut self` to taking `self`. If a timeout occurs while waiting with output, the semantics are undesirable in almost all cases if attempting to re-wait on the process. Equivalent functionality can still be achieved by dealing with the output handles manually. [breaking-change] cc #13523
2014-05-13std: Rename str::Normalizations to str::DecompositionsFlorian Zeitz-17/+17
The Normalizations iterator has been renamed to Decompositions. It does not currently include all forms of Unicode normalization, but only encompasses decompositions. If implemented recomposition would likely be a separate iterator which works on the result of this one. [breaking-change]
2014-05-13std, core: Generate unicode.rs using unicode.pyFlorian Zeitz-2/+2
2014-05-13Add tests for from_bits.OGINO Masanori-0/+7
Signed-off-by: OGINO Masanori <masanori.ogino@gmail.com>
2014-05-13std: Move the owned module from core to stdAlex Crichton-6/+111
The compiler was updated to recognize that implementations for ty_uniq(..) are allowed if the Box lang item is located in the current crate. This enforces the idea that libcore cannot allocated, and moves all related trait implementations from libcore to libstd. This is a breaking change in that the AnyOwnExt trait has moved from the any module to the owned module. Any previous users of std::any::AnyOwnExt should now use std::owned::AnyOwnExt instead. This was done because the trait is intended for Box traits and only Box traits. [breaking-change]
2014-05-14Suppress a "unused variable" warning.OGINO Masanori-1/+1
Signed-off-by: OGINO Masanori <masanori.ogino@gmail.com>
2014-05-13auto merge of #14075 : Rufflewind/rust/patch-3, r=alexcrichtonbors-10/+36
- Use Unicode-aware versions of `CreateProcess` (Fixes #13815) and `Get/FreeEnvironmentStrings`. - Includes a helper function `os::win32::as_mut_utf16_p`, which does the same thing as `os::win32::as_utf16_p` except the pointer is mutable. - Fixed `make_command_line` to handle Unicode correctly. - Tests for the above.
2014-05-13Use Get/FreeEnvironmentStringsW instead of Get/FreeEnvironmentStringsAPhil Ruffwind-9/+31
Changed libstd to use Get/FreeEnvironmentStringsW instead of Get/FreeEnvironmentStringsA to support Unicode environment variables.
2014-05-13Use CreateProcessW instead of CreateProcessAPhil Ruffwind-1/+5
Changed libnative to use CreateProcessW instead of CreateProcessA. In addition, the lpEnvironment parameter now uses Unicode. Added a helper function os::win32::as_mut_utf16_p, which does basically the same thing as os::win32::as_utf16_p except the pointer is mutable.
2014-05-13Added functions pop_char and shift_char to StrBuf struct along with ↵Dylan Braithwaite-4/+57
appropriate unit tests, using the same test case as push_char. Changed StrBuf.shift_byte() that it no longer reallocates the buffer by just calling Vec.shift(); Added warning to shift_char()'s docs about it having to copy the whole buffer, as per the docs for Vec.shift().
2014-05-12auto merge of #13919 : thomaslee/rust/thomaslee_proposed_tcpstream_open, ↵bors-96/+264
r=alexcrichton Been meaning to try my hand at something like this for a while, and noticed something similar mentioned as part of #13537. The suggestion on the original ticket is to use `TcpStream::open(&str)` to pass in a host + port string, but seems a little cleaner to pass in host and port separately -- so a signature like `TcpStream::open(&str, u16)`. Also means we can use std::io::net::addrinfo directly instead of using e.g. liburl to parse the host+port pair from a string. One outstanding issue in this PR that I'm not entirely sure how to address: in open_timeout, the timeout_ms will apply for every A record we find associated with a hostname -- probably not the intended behavior, but I didn't want to waste my time on elaborate alternatives until the general idea was a-OKed. :) Anyway, perhaps there are other reasons for us to prefer the original proposed syntax, but thought I'd get some thoughts on this. Maybe there are some solid reasons to prefer using liburl to do this stuff.
2014-05-12Document a possible way in which connect_timout may change in the futureTom Lee-0/+3
2014-05-12Try to parse TcpStream::connect 'host' parameter as an IP.Tom Lee-1/+4
Fall back to get_host_addresses to try a DNS lookup if we can't parse it as an IP address.
2014-05-12Easier interface for TCP ::connect and ::bind.Tom Lee-96/+258
Prior to this commit, TcpStream::connect and TcpListener::bind took a single SocketAddr argument. This worked well enough, but the API felt a little too "low level" for most simple use cases. A great example is connecting to rust-lang.org on port 80. Rust users would need to: 1. resolve the IP address of rust-lang.org using io::net::addrinfo::get_host_addresses. 2. check for errors 3. if all went well, use the returned IP address and the port number to construct a SocketAddr 4. pass this SocketAddr to TcpStream::connect. I'm modifying the type signature of TcpStream::connect and TcpListener::bind so that the API is a little easier to use. TcpStream::connect now accepts two arguments: a string describing the host/IP of the host we wish to connect to, and a u16 representing the remote port number. Similarly, TcpListener::bind has been modified to take two arguments: a string describing the local interface address (e.g. "0.0.0.0" or "127.0.0.1") and a u16 port number. Here's how to port your Rust code to use the new TcpStream::connect API: // old ::connect API let addr = SocketAddr{ip: Ipv4Addr{127, 0, 0, 1}, port: 8080}; let stream = TcpStream::connect(addr).unwrap() // new ::connect API (minimal change) let addr = SocketAddr{ip: Ipv4Addr{127, 0, 0, 1}, port: 8080}; let stream = TcpStream::connect(addr.ip.to_str(), addr.port()).unwrap() // new ::connect API (more compact) let stream = TcpStream::connect("127.0.0.1", 8080).unwrap() // new ::connect API (hostname) let stream = TcpStream::connect("rust-lang.org", 80) Similarly, for TcpListener::bind: // old ::bind API let addr = SocketAddr{ip: Ipv4Addr{0, 0, 0, 0}, port: 8080}; let mut acceptor = TcpListener::bind(addr).listen(); // new ::bind API (minimal change) let addr = SocketAddr{ip: Ipv4Addr{0, 0, 0, 0}, port: 8080}; let mut acceptor = TcpListener::bind(addr.ip.to_str(), addr.port()).listen() // new ::bind API (more compact) let mut acceptor = TcpListener::bind("0.0.0.0", 8080).listen() [breaking-change]
2014-05-12Test fixes from rollupAlex Crichton-3/+1
Closes #14163 (Fix typos in rustc manpage) Closes #14161 (Add the patch number to version strings. Closes #13289) Closes #14156 (rustdoc: Fix hiding implementations of traits) Closes #14152 (add shebang to scripts that have execute bit set) Closes #14150 (libcore: remove fails from slice.rs and remove duplicated length checking) Closes #14147 (Make ProcessOutput Eq, TotalEq, Clone) Closes #14142 (doc: updates rust manual (loop to continue)) Closes #14141 (doc: Update the linkage documentation) Closes #14139 (Remove an unnecessary .move_iter().collect()) Closes #14136 (Two minor fixes in parser.rs) Closes #14130 (Fixed typo in comments of driver.rs) Closes #14128 (Add `stat` method to `std::io::fs::File` to stat without a Path.) Closes #14114 (rustdoc: List macros in the sidebar) Closes #14113 (shootout-nbody improvement) Closes #14112 (Improved example code in Option) Closes #14104 (Remove reference to MutexArc) Closes #14087 (emacs: highlight `macro_name!` in macro invocations using [] delimiters)
2014-05-12Improved example code in OptionAdolfo Ochagavía-12/+15
2014-05-12Add `stat` method to `std::io::fs::File` to stat without a Path.Yuri Kunde Schlesner-9/+15
The `FileStat` struct contained a `path` field, which was filled by the `stat` and `lstat` function. Since this field isn't in fact returned by the operating system (it was copied from the paths passed to the functions) it was removed, as in the `fstat` case we aren't working with a `Path`, but directly with a fd. If your code used the `path` field of `FileStat` you will now have to manually store the path passed to `stat` along with the returned struct. [breaking-change]
2014-05-12Remove an unnecessary .move_iter().collect()Simon Sapin-1/+1
2014-05-12Make ProcessOutput Eq, TotalEq, CloneYehuda Katz-0/+1
2014-05-12Add the patch number to version strings. Closes #13289Brian Anderson-1/+1
2014-05-12librustc: Remove all uses of `~str` from librustc.Patrick Walton-0/+22
2014-05-12register snapshotsDaniel Micay-84/+2
2014-05-11auto merge of #14119 : thestinger/rust/heap, r=cmrbors-24/+33
2014-05-11auto merge of #14110 : SSheldon/rust/strbuf_mutable, r=alexcrichtonbors-1/+17
Despite implementing the Container trait, StrBuf did not implement the Mutable trait and had no clear method; this request implements the clear method of the Mutable trait for StrBuf. Testing done: added a test and ran `make check` without any failures.
2014-05-11heap: replace `exchange_free` with `deallocate`Daniel Micay-17/+12
The `std::rt::heap` API is Rust's global allocator, so there's no need to have this as a separate API.
2014-05-11heap: add a way to print allocator statisticsDaniel Micay-2/+16
2014-05-11mark rust_malloc/rust_free as unsafeDaniel Micay-6/+6
Support for this was added by 08237cad8d2ce9287aedf99e57384407cc9dc42d.
2014-05-11sync::deque: port to the new allocator APIDaniel Micay-15/+19
2014-05-11Implement Mutable trait for StrBuf.Steven Sheldon-1/+17
2014-05-11core: Remove the cast moduleAlex Crichton-253/+258
This commit revisits the `cast` module in libcore and libstd, and scrutinizes all functions inside of it. The result was to remove the `cast` module entirely, folding all functionality into the `mem` module. Specifically, this is the fate of each function in the `cast` module. * transmute - This function was moved to `mem`, but it is now marked as #[unstable]. This is due to planned changes to the `transmute` function and how it can be invoked (see the #[unstable] comment). For more information, see RFC 5 and #12898 * transmute_copy - This function was moved to `mem`, with clarification that is is not an error to invoke it with T/U that are different sizes, but rather that it is strongly discouraged. This function is now #[stable] * forget - This function was moved to `mem` and marked #[stable] * bump_box_refcount - This function was removed due to the deprecation of managed boxes as well as its questionable utility. * transmute_mut - This function was previously deprecated, and removed as part of this commit. * transmute_mut_unsafe - This function doesn't serve much of a purpose when it can be achieved with an `as` in safe code, so it was removed. * transmute_lifetime - This function was removed because it is likely a strong indication that code is incorrect in the first place. * transmute_mut_lifetime - This function was removed for the same reasons as `transmute_lifetime` * copy_lifetime - This function was moved to `mem`, but it is marked `#[unstable]` now due to the likelihood of being removed in the future if it is found to not be very useful. * copy_mut_lifetime - This function was also moved to `mem`, but had the same treatment as `copy_lifetime`. * copy_lifetime_vec - This function was removed because it is not used today, and its existence is not necessary with DST (copy_lifetime will suffice). In summary, the cast module was stripped down to these functions, and then the functions were moved to the `mem` module. transmute - #[unstable] transmute_copy - #[stable] forget - #[stable] copy_lifetime - #[unstable] copy_mut_lifetime - #[unstable] [breaking-change]
2014-05-11android workaroundDaniel Micay-1/+1
2014-05-10rename `global_heap` -> `libc_heap`Daniel Micay-10/+9
This module only contains wrappers for malloc and realloc with out-of-memory checks.
2014-05-10vec: factor out some deallocation codeDaniel Micay-9/+12
2014-05-10vec: move some code inside alloc_or_reallocDaniel Micay-7/+5
2014-05-10fix Vec<ZeroSizeType>Daniel Micay-2/+15
2014-05-10initial port of the exchange allocator to jemallocDaniel Micay-142/+205
In stage0, all allocations are 8-byte aligned. Passing a size and alignment to free is not yet implemented everywhere (0 size and 8 align are used as placeholders). Fixing this is part of #13994. Closes #13616
2014-05-10use jemalloc to implement Vec<T>Daniel Micay-27/+49