summary refs log tree commit diff
path: root/src/libstd
AgeCommit message (Collapse)AuthorLines
2015-07-29std: Fix sub-second Condvar::wait_timeout_msAlex Crichton-13/+14
The API we're calling requires us to pass an absolute point in time as an argument (`pthread_cond_timedwait`) so we call `gettimeofday` ahead of time to then add the specified duration to. Unfortuantely the current "add the duration" logic forgot to take into account the current time's sub-second precision (e.g. the `tv_usec` field was ignored), causing sub-second duration waits to return spuriously.
2015-07-29Fix typo in stability attribute.Lee Jeffery-1/+1
2015-06-30Make `align_of` behave like `min_align_of`.Huon Wilson-11/+11
This removes a footgun, since it is a reasonable assumption to make that pointers to `T` will be aligned to `align_of::<T>()`. This also matches the behaviour of C/C++. `min_align_of` is now deprecated. Closes #21611.
2015-06-23Auto merge of #26514 - tshepang:repetition, r=Gankrobors-1/+1
2015-06-23doc: remove repeated wordTshepang Lekhonkhobe-1/+1
2015-06-22Fix build on Android API levels below 21Geoffrey Thomas-0/+20
signal(), sigemptyset(), and sigaddset() are only available as inline functions until Android API 21. liblibc already handles signal() appropriately, so drop it from c.rs; translate sigemptyset() and sigaddset() (which is only used in a test) by hand from the C inlines. We probably want to revert this commit when we bump Android API level.
2015-06-22sys/unix/process: Reset signal behavior before execGeoffrey Thomas-2/+85
Make sure that child processes don't get affected by libstd's desire to ignore SIGPIPE, nor a third-party library's signal mask (which is needed to use either a signal-handling thread correctly or to use signalfd / kqueue correctly).
2015-06-22sys/unix: Consolidate signal-handling FFI bindingsGeoffrey Thomas-268/+199
Both c.rs and stack_overflow.rs had bindings of libc's signal-handling routines. It looks like the split dated from #16388, when (what is now) c.rs was in libnative but not libgreen. Nobody is currently using the c.rs bindings, but they're a bit more accurate in some places. Move everything to c.rs (since I'll need signal handling in process.rs, and we should avoid duplication), clean up the bindings, and manually double-check everything against the relevant system headers (fixing a few things in the process).
2015-06-22sys/unix/c.rs: Remove unused codeGeoffrey Thomas-77/+5
It looks like a lot of this dated to previous incarnations of the io module, etc., and went unused in the reworking leading up to 1.0. Remove everything we're not actively using (except for signal handling, which will be reworked in the next commit).
2015-06-22std::process: Remove helper function pwd_cmd from test moduleGeoffrey Thomas-18/+0
The test that used it was removed in 700e627cf727873a472b1876238aac10b932258b.
2015-06-21Auto merge of #26463 - sfackler:stdout-panic-fix, r=alexcrichtonbors-11/+12
If a local stderr is present but the normal stderr is missing, we still want to print. r? @alexcrichton
2015-06-21Auto merge of #25641 - geofft:execve-const, r=alexcrichtonbors-1/+1
The `execv` family of functions and `getopt` are prototyped somewhat strangely in C: they take a `char *const argv[]` (and `envp`, for `execve`), an immutable array of mutable C strings -- in other words, a `char *const *argv` or `argv: *const *mut c_char`. The current Rust binding uses `*mut *const c_char`, which is backwards (a mutable array of constant C strings). That said, these functions do not actually modify their arguments. Once upon a time, C didn't have `const`, and to this day, string literals in C have type `char *` (`*mut c_char`). So an array of string literals has type `char * []`, equivalent to `char **` in a function parameter (Rust `*mut *mut c_char`). C allows an implicit cast from `T **` to `T * const *` (`*const *mut T`) but not to `const T * const *` (`*const *const T`). Therefore, prototyping `execv` as taking `const char * const argv[]` would have broken existing code (by requiring an explicit cast), despite being more correct. So, even though these functions don't need mutable data, they're prototyped as if they do. While it's theoretically possible that an implementation could choose to use its freedom to modify the mutable data, such an implementation would break the innumerable users of `execv`-family functions that call them with string literals. Such an implementation would also break `std::process`, which currently works around this with an unsafe `as *mut _` cast, and assumes that `execvp` secretly does not modify its argument. Furthermore, there's nothing useful to be gained by being able to write to the strings in `argv` themselves but not being able to write to the array containing those strings (you can't reorder arguments, add arguments, increase the length of any parameter, etc.). So, despite the C prototype with its legacy C problems, it's simpler for everyone for Rust to consider these functions as taking `*const *const c_char`, and it's also safe to do so. Rust does not need to expose the mistakes of C here. This patch makes that change, and drops the unsafe cast in `std::process` since it's now unnecessary.
2015-06-21Auto merge of #26457 - meqif:master, r=alexcrichtonbors-2/+1
The documentation of `std::net::Shutdown` mentions says it can be passed to the `shutdown` method of `UdpSocket`, which isn't true because `UdpSocket` has no such method. This commit removes that mention.
2015-06-21Auto merge of #26416 - retep998:error-debug, r=sfacklerbors-1/+21
Fixes https://github.com/rust-lang/rust/issues/26408 Example output when using `Result::unwrap`: ``` thread '<main>' panicked at 'called `Result::unwrap()` on an `Err` value: Error { repr: Os { code: 2, message: "The system cannot find the file specified.\r\n" } }', src/libcore\result.rs:731 ``` This could technically be considered a breaking change for any code that depends on the format of the `Debug` output for `io::Error` but I sincerely hope nobody wrote code like that.
2015-06-20Fix logic in panic printing with no stderrSteven Fackler-11/+12
If a local stderr is present but the normal stderr is missing, we still want to print.
2015-06-20Remove mention of `UdpSocket` in `Shutdown` docs.Ricardo Martins-2/+1
2015-06-19liblibc: Fix prototype of functions taking `char *const argv[]`Geoffrey Thomas-1/+1
The execv family of functions do not modify their arguments, so they do not need mutable pointers. The C prototypes take a constant array of mutable C-strings, but that's a legacy quirk from before C had const (since C string literals have type `char *`). The Rust prototypes had `*mut` in the wrong place, anyway: to match the C prototypes, it should have been `*const *mut c_char`. But it is safe to pass constant strings (like string literals) to these functions. getopt is a special case, since GNU getopt modifies its arguments despite the `const` claim in the prototype. It is apparently only well-defined to call getopt on the actual argc and argv parameters passed to main, anyway. Change it to take `*mut *mut c_char` for an attempt at safety, but probably nobody should be using it from Rust, since there's no great way to get at the parameters as passed to main. Also fix the one caller of execvp in libstd, which now no longer needs an unsafe cast. Fixes #16290.
2015-06-19Add a test for Debug for io::ErrorPeter Atashian-0/+10
Signed-off-by: Peter Atashian <retep998@gmail.com>
2015-06-19Fix docs for column/lineSteve Klabnik-2/+2
Fixes #26424
2015-06-18Custom Debug impl for io::ErrorPeter Atashian-1/+11
Fixes #26408 Signed-off-by: Peter Atashian <retep998@gmail.com>
2015-06-18std: Add FromRaw{Fd,Handle,Socket} to os preludesAlex Crichton-1/+3
These were just left out by mistake!
2015-06-18Auto merge of #26192 - alexcrichton:features-clean, r=aturonbors-197/+166
This commit shards the all-encompassing `core`, `std_misc`, `collections`, and `alloc` features into finer-grained components that are much more easily opted into and tracked. This reflects the effort to push forward current unstable APIs to either stabilization or removal. Keeping track of unstable features on a much more fine-grained basis will enable the library subteam to quickly analyze a feature and help prioritize internally about what APIs should be stabilized. A few assorted APIs were deprecated along the way, but otherwise this change is just changing the feature name associated with each API. Soon we will have a dashboard for keeping track of all the unstable APIs in the standard library, and I'll also start making issues for each unstable API after performing a first-pass for stabilization.
2015-06-18Fix libstd testsAlex Crichton-5/+6
2015-06-17Add comment about stabilizing CString::from_ptrAlex Crichton-0/+4
This naming needs to consider the raw vs ptr naming of Box/CStr/CString/slice/etc.
2015-06-17std: Hide some internal functions more aggressivelyAlex Crichton-1/+1
* Add `#[doc(hidden)]` * Rename away from `Error::description`
2015-06-17More test fixes and fallout of stability changesAlex Crichton-54/+30
2015-06-17std: Deprecate the `thunk` moduleAlex Crichton-0/+1
This has been replaced with `FnBox`
2015-06-17std: Deprecate the `scoped` featureAlex Crichton-0/+6
The `thread::scoped` function will never be stabilized as-is and the API will likely change significantly if it does, so this function is deprecated for removal.
2015-06-17std: Deprecate the `future` featureAlex Crichton-0/+4
This commit deprecates the `sync::Future` type to be developed outside in crates.io instead.
2015-06-17std: Deprecate the `exit_status` featureAlex Crichton-0/+2
These two functions should be replaceable with the `process::exit` function.
2015-06-17std: Deprecate the io::BufStream typeAlex Crichton-0/+4
Questions about the utility of this type has caused it to move to crates.io in the `bufstream` crate, so this type can be deprecated.
2015-06-17std: Stabilize the `once_new` featureAlex Crichton-1/+1
This function follows the well-established "constructor" pattern and the initialization constant will likely be deprecated in favor of it once `const_fn` is stabilized.
2015-06-17std: Stabilize the sync_poison featureAlex Crichton-6/+6
These accessor/constructor methods for a `PoisonError` are quite standard for a wrapper type and enable manipulation of the underlying type.
2015-06-17std: Remove two internal `str_internals` functionsAlex Crichton-25/+0
These were just exposed to be used elsewhere at some point, but neither is currently being used so just make them private again.
2015-06-17Fallout in tests and docs from feature renamingsAlex Crichton-4/+6
2015-06-17std: Split the `std_misc` featureAlex Crichton-110/+82
2015-06-17collections: Split the `collections` featureAlex Crichton-0/+5
This commit also deprecates the `as_string` and `as_slice` free functions in the `string` and `vec` modules.
2015-06-17alloc: Split apart the global `alloc` featureAlex Crichton-0/+3
2015-06-17core: Split apart the global `core` featureAlex Crichton-7/+21
This commit shards the broad `core` feature of the libcore library into finer grained features. This split groups together similar APIs and enables tracking each API separately, giving a better sense of where each feature is within the stabilization process. A few minor APIs were deprecated along the way: * Iterator::reverse_in_place * marker::NoCopy
2015-06-17collections: fix a couple of typosIvan Ukhov-3/+3
2015-06-16Auto merge of #25952 - alexcrichton:fix-scoped-tls, r=aturonbors-32/+48
Currently the compiler has no knowledge of `#[thread_local]` which forces users to take on two burdens of unsafety: * The lifetime of the borrow of a `#[thread_local]` static is **not** `'static` * Types in `static`s are required to be `Sync` The thread-local modules mostly curb these facets of unsafety by only allowing very limited scopes of borrows as well as allowing all types to be stored in a thread-local key (regardless of whether they are `Sync`) through an `unsafe impl`. Unfortunately these measures have the consequence of being able to take the address of the key itself and send it to another thread, allowing the same key to be accessed from two different threads. This is clearly unsafe, and this commit fixes this problem with the same trick used by `LocalKey`, which is to have an indirect function call to find the address of the *current thread's* thread local. This way the address of thread local keys can safely be sent among threads as their lifetime truly is `'static`. This commit will reduce the performance of cross-crate scoped thread locals as it now requires an indirect function call, but this can likely be overcome in a future commit. Closes #25894
2015-06-15Auto merge of #26168 - sfackler:stdout-panic, r=alexcrichtonbors-33/+96
Closes #25977 The various `stdfoo_raw` methods in std::io now return `io::Result`s, since they may not exist on Windows. They will always return `Ok` on Unix-like platforms. [breaking-change]
2015-06-14Implement RFC 1014Steven Fackler-33/+96
Closes #25977 The various `stdfoo_raw` methods in std::io now return `io::Result`s, since they may not exist on Windows. They will always return `Ok` on Unix-like platforms. [breaking-change]
2015-06-12Auto merge of #25844 - alexcrichton:stabilize-fs-features, r=aturonbors-256/+654
This commit stabilizes the following APIs, slating them all to be cherry-picked into the 1.1 release. * fs::FileType (and transitively the derived trait implementations) * fs::Metadata::file_type * fs::FileType::is_dir * fs::FileType::is_file * fs::FileType::is_symlink * fs::DirEntry::metadata * fs::DirEntry::file_type * fs::DirEntry::file_name * fs::set_permissions * fs::symlink_metadata * os::raw::{self, *} * os::{android, bitrig, linux, ...}::raw::{self, *} * os::{android, bitrig, linux, ...}::fs::MetadataExt * os::{android, bitrig, linux, ...}::fs::MetadataExt::as_raw_stat * os::unix::fs::PermissionsExt * os::unix::fs::PermissionsExt::mode * os::unix::fs::PermissionsExt::set_mode * os::unix::fs::PermissionsExt::from_mode * os::unix::fs::OpenOptionsExt * os::unix::fs::OpenOptionsExt::mode * os::unix::fs::DirEntryExt * os::unix::fs::DirEntryExt::ino * os::windows::fs::MetadataExt * os::windows::fs::MetadataExt::file_attributes * os::windows::fs::MetadataExt::creation_time * os::windows::fs::MetadataExt::last_access_time * os::windows::fs::MetadataExt::last_write_time * os::windows::fs::MetadataExt::file_size The `os::unix::fs::Metadata` structure was also removed entirely, moving all of its associated methods into the `os::unix::fs::MetadataExt` trait instead. The methods are all marked as `#[stable]` still. As some minor cleanup, some deprecated and unstable fs apis were also removed: * File::path * Metadata::accessed * Metadata::modified Features that were explicitly left unstable include: * fs::WalkDir - the semantics of this were not considered in the recent fs expansion RFC. * fs::DirBuilder - it's still not 100% clear if the naming is right here and if the set of functionality exposed is appropriate. * fs::canonicalize - the implementation on Windows here is specifically in question as it always returns a verbatim path. Additionally the Unix implementation is susceptible to buffer overflows on long paths unfortunately. * fs::PathExt - as this is just a convenience trait, it is not stabilized at this time. * fs::set_file_times - this funciton is still waiting on a time abstraction.
2015-06-11Auto merge of #26190 - Veedrac:no-iter, r=alexcrichtonbors-16/+17
Pull request for #26188.
2015-06-11Conver reborrows to .iter() calls where appropriateJoshua Landau-1/+1
2015-06-11Auto merge of #26159 - alexcrichton:tweak-process-lowering-raising, r=brsonbors-101/+60
* Slate these features to be stable in 1.2 instead of 1.1 (not being backported) * Have the `FromRawFd` implementations follow the contract of the `FromRawFd` trait by taking ownership of the primitive specified. * Refactor the implementations slightly to remove the `unreachable!` blocks as well as separating the stdio representation of `std::process` from `std::sys::process`. cc #25494
2015-06-10Removed many pointless calls to *iter() and iter_mut()Joshua Landau-15/+16
2015-06-10disabling socking timing tests because openbsd/bitrig get/set are not ↵Dave Huseby-0/+6
congruent due to rounding errors
2015-06-10Auto merge of #25777 - shepmaster:cstring-return-to-c, r=alexcrichtonbors-4/+41
As far as I was able to determine, it's currently *impossible* to allocate a C NUL-terminated string in Rust and then return it to C (transferring ownership), without leaking memory. There is support for passing the string to C (borrowing). To complicate matters, it's not possible for the C code to just call `free` on the allocated string, due to the different allocators in use. `CString` has no way to recreate itself from a pointer. This commit adds one. This is complicated a bit because Rust `Vec`s want the pointer, size, and capacity. To deal with that, another method to shrink and "leak" the `CString` to a `char *` is also provided. We can then use `strlen` to determine the length of the string, which must match the capacity. **TODO** - [x] Improve documentation - [x] Add stability markers - [x] Convert to `Box<[u8]>` ### Example code With this example code: ```rust #![feature(libc)] #![feature(cstr_to_str)] #![feature(c_str_memory)] extern crate libc; use std::ffi::{CStr,CString}; #[no_mangle] pub extern fn reverse(s: *const libc::c_char) -> *const libc::c_char { let s = unsafe { CStr::from_ptr(s) }; let s2 = s.to_str().unwrap(); let s3: String = s2.chars().rev().collect(); let s4 = CString::new(s3).unwrap(); s4.into_ptr() } #[no_mangle] pub extern fn cleanup(s: *const libc::c_char) { unsafe { CString::from_ptr(s) }; } ``` Compiled using `rustc --crate-type dylib str.rs`, I was able to link against it from C (`gcc -L. -l str str.c -o str`): ```c #include <stdio.h> extern char *reverse(char *); extern void cleanup(char *); int main() { char *s = reverse("Hello, world!"); printf("%s\n", s); cleanup(s); } ``` As well as dynamically link via Ruby: ```ruby require 'fiddle' require 'fiddle/import' module LibSum extend Fiddle::Importer dlload './libstr.dylib' extern 'char* reverse(char *)' extern 'void cleanup(char *)' end s = LibSum.reverse("hello, world!") puts s LibSum.cleanup(s) ```