summary refs log tree commit diff
path: root/src/libstd/c_str.rs
AgeCommit message (Collapse)AuthorLines
2014-03-20rename std::vec -> std::sliceDaniel Micay-3/+3
Closes #12702
2014-02-23std: Move raw to std::rawBrian Anderson-1/+1
Issue #1457
2014-02-20move extra::test to libtestLiigo Zhuang-1/+2
2014-02-14Add c_str::CString.as_bytes_no_nul()Kevin Ballard-4/+37
2014-02-13remove duplicate function from std::ptr (is_null, is_not_null, offset, ↵JeremyLetang-24/+23
mut_offset)
2014-02-09std: Add init and uninit to mem. Replace direct intrinsic usageBrian Anderson-2/+2
2014-02-08Remove an unused variable in a test of std::c_str.OGINO Masanori-1/+0
Signed-off-by: OGINO Masanori <masanori.ogino@gmail.com>
2014-02-06Remove std::conditionAlex Crichton-44/+6
This has been a long time coming. Conditions in rust were initially envisioned as being a good alternative to error code return pattern. The idea is that all errors are fatal-by-default, and you can opt-in to handling the error by registering an error handler. While sounding nice, conditions ended up having some unforseen shortcomings: * Actually handling an error has some very awkward syntax: let mut result = None; let mut answer = None; io::io_error::cond.trap(|e| { result = Some(e) }).inside(|| { answer = Some(some_io_operation()); }); match result { Some(err) => { /* hit an I/O error */ } None => { let answer = answer.unwrap(); /* deal with the result of I/O */ } } This pattern can certainly use functions like io::result, but at its core actually handling conditions is fairly difficult * The "zero value" of a function is often confusing. One of the main ideas behind using conditions was to change the signature of I/O functions. Instead of read_be_u32() returning a result, it returned a u32. Errors were notified via a condition, and if you caught the condition you understood that the "zero value" returned is actually a garbage value. These zero values are often difficult to understand, however. One case of this is the read_bytes() function. The function takes an integer length of the amount of bytes to read, and returns an array of that size. The array may actually be shorter, however, if an error occurred. Another case is fs::stat(). The theoretical "zero value" is a blank stat struct, but it's a little awkward to create and return a zero'd out stat struct on a call to stat(). In general, the return value of functions that can raise error are much more natural when using a Result as opposed to an always-usable zero-value. * Conditions impose a necessary runtime requirement on *all* I/O. In theory I/O is as simple as calling read() and write(), but using conditions imposed the restriction that a rust local task was required if you wanted to catch errors with I/O. While certainly an surmountable difficulty, this was always a bit of a thorn in the side of conditions. * Functions raising conditions are not always clear that they are raising conditions. This suffers a similar problem to exceptions where you don't actually know whether a function raises a condition or not. The documentation likely explains, but if someone retroactively adds a condition to a function there's nothing forcing upstream users to acknowledge a new point of task failure. * Libaries using I/O are not guaranteed to correctly raise on conditions when an error occurs. In developing various I/O libraries, it's much easier to just return `None` from a read rather than raising an error. The silent contract of "don't raise on EOF" was a little difficult to understand and threw a wrench into the answer of the question "when do I raise a condition?" Many of these difficulties can be overcome through documentation, examples, and general practice. In the end, all of these difficulties added together ended up being too overwhelming and improving various aspects didn't end up helping that much. A result-based I/O error handling strategy also has shortcomings, but the cognitive burden is much smaller. The tooling necessary to make this strategy as usable as conditions were is much smaller than the tooling necessary for conditions. Perhaps conditions may manifest themselves as a future entity, but for now we're going to remove them from the standard library. Closes #9795 Closes #8968
2014-02-01impl Eq for CStringCorey Richardson-4/+28
2014-02-01impl Clone for CStringCorey Richardson-4/+48
Clone tests
2014-01-31Test for null buffer in CString.len()/.iter() and failKevin Ballard-3/+36
Also change .as_str() to fail on null buffer.
2014-01-31Introduce marker types for indicating variance and for opting outNiko Matsakis-2/+3
of builtin bounds. Fixes #10834. Fixes #11385. cc #5922.
2014-01-28Rename CopyableVector to CloneableVectorVirgile Andreani-1/+1
2014-01-22libc: switch `free` to the proper signatureDaniel Micay-2/+2
This does not attempt to fully propagate the mutability everywhere, but gives new code a hint to avoid the same issues.
2014-01-21[std::str] Rename from_utf8_opt() to from_utf8(), drop the old from_utf8() ↵Simon Sapin-1/+1
behavior
2014-01-18Rename iterators for consistencyPalmer Cox-4/+4
Rename existing iterators to get rid of the Iterator suffix and to give them names that better describe the things being iterated over.
2014-01-07stdtest: Fix all leaked trait importsAlex Crichton-4/+3
2013-12-23std: Fix all code examplesAlex Crichton-3/+7
2013-12-20std: silence warnings when compiling test.Huon Wilson-2/+1
2013-12-19std::str: replace .as_imm_buf with .as_ptr.Huon Wilson-8/+7
2013-12-19std::vec: remove .as_muf_buf, replaced by .as_mut_ptr & .len.Huon Wilson-6/+5
2013-12-19std::vec: remove .as_imm_buf, replaced by .as_ptr & .len.Huon Wilson-9/+8
There's no need for the restrictions of a closure with the above methods.
2013-12-15std::vec: convert to(_mut)_ptr to as_... methods on &[] and &mut [].Huon Wilson-1/+1
2013-12-15std::vec: remove unnecessary count parameter on {bytes,Huon Wilson-1/+1
raw}::copy_memory. Slices carry their length with them, so we can just use that information.
2013-12-11Make 'self lifetime illegal.Erik Price-5/+5
Also remove all instances of 'self within the codebase. This fixes #10889.
2013-12-04std::str: s/from_utf8_slice/from_utf8/, to make the basic case shorter.Huon Wilson-1/+1
2013-11-26libstd: Remove all non-`proc` uses of `do` from libstdPatrick Walton-54/+42
2013-11-19libstd: Change all uses of `&fn(A)->B` over to `|A|->B` in libstdPatrick Walton-10/+10
2013-11-11Remove #[fixed_stack_segment] and #[rust_stack]Alex Crichton-8/+3
These two attributes are no longer useful now that Rust has decided to leave segmented stacks behind. It is assumed that the rust task's stack is always large enough to make an FFI call (due to the stack being very large). There's always the case of stack overflow, however, to consider. This does not change the behavior of stack overflow in Rust. This is still normally triggered by the __morestack function and aborts the whole process. C stack overflow will continue to corrupt the stack, however (as it did before this commit as well). The future improvement of a guard page at the end of every rust stack is still unimplemented and is intended to be the mechanism through which we attempt to detect C stack overflow. Closes #8822 Closes #10155
2013-11-04docs: Replace std::iterator with std::iter.Huon Wilson-1/+1
2013-10-24Remove IoFactoryObject for ~IoFactoryAlex Crichton-1/+3
This involved changing a fair amount of code, rooted in how we access the local IoFactory instance. I added a helper method to the rtio module to access the optional local IoFactory. This is different than before in which it was assumed that a local IoFactory was *always* present. Now, a separate io_error is raised when an IoFactory is not present, yet I/O is requested.
2013-10-24Remove rt::io::supportAlex Crichton-0/+43
This removes the PathLike trait associated with this "support module". This is yet another "container of bytes" trait, so I didn't want to duplicate what already exists throughout libstd. In actuality, we're going to pass of C strings to the libuv APIs, so instead the arguments are now bound with the 'ToCStr' trait instead. Additionally, a layer of complexity was removed by immediately converting these type-generic parameters into CStrings to get handed off to libuv apis.
2013-10-22Drop the '2' suffix from logging macrosAlex Crichton-4/+4
Who doesn't like a massive renaming?
2013-09-30std: Remove usage of fmt!Alex Crichton-4/+4
2013-09-26std: simplify vec.with_c_strErick Tryzelaar-28/+20
This also fixes a bug in `vec.with_c_str_unchecked` where we were not calling `.to_c_str_unchecked()` for long strings.
2013-09-26std: add micro optimization to vec.with_c_str_uncheckedErick Tryzelaar-0/+47
before: test c_str::bench::bench_with_c_str_unchecked_long ... bench: 361 ns/iter (+/- 9) test c_str::bench::bench_with_c_str_unchecked_medium ... bench: 75 ns/iter (+/- 2) test c_str::bench::bench_with_c_str_unchecked_short ... bench: 60 ns/iter (+/- 9) after: test c_str::bench::bench_with_c_str_unchecked_long ... bench: 362 ns/iter (+/- test c_str::bench::bench_with_c_str_unchecked_medium ... bench: 30 ns/iter (+/- 7) test c_str::bench::bench_with_c_str_unchecked_short ... bench: 12 ns/iter (+/- 4)
2013-09-26std: Up vec.with_c_str's stack buffer to 128Erick Tryzelaar-1/+1
This matches @graydon's recommendation.
2013-09-26std: Remove an unnecessary comment from c_strErick Tryzelaar-3/+0
The documentation for `.with_c_str()` already says that the pointer will be deallocated before returning from the function.
2013-09-26std: Micro-optimize vec.with_c_str for short vectorsErick Tryzelaar-14/+52
This now makes it unsafe to save the pointer returned by .with_c_str as that pointer now may be pointing at a stack allocated array. I arbitrarily chose 32 bytes as the length of the stack vector, and so it might not be the most optimal size. before: test c_str::bench::bench_with_c_str_long ... bench: 539 ns/iter (+/- 91) test c_str::bench::bench_with_c_str_medium ... bench: 97 ns/iter (+/- 2) test c_str::bench::bench_with_c_str_short ... bench: 70 ns/iter (+/- 5) after: test c_str::bench::bench_with_c_str_long ... bench: 542 ns/iter (+/- 13) test c_str::bench::bench_with_c_str_medium ... bench: 53 ns/iter (+/- 6) test c_str::bench::bench_with_c_str_short ... bench: 19 ns/iter (+/- 0)
2013-09-26std: Add benchmarks to c_strErick Tryzelaar-0/+103
2013-09-26std: implement Container for CStringErick Tryzelaar-2/+10
2013-09-25rustdoc: Change all code-blocks with a scriptAlex Crichton-4/+4
find src -name '*.rs' | xargs sed -i '' 's/~~~.*{\.rust}/```rust/g' find src -name '*.rs' | xargs sed -i '' 's/ ~~~$/ ```/g' find src -name '*.rs' | xargs sed -i '' 's/^~~~$/ ```/g'
2013-09-20auto merge of #9276 : alexcrichton/rust/dox, r=brsonbors-0/+52
Hopefull this will make our libstd docs appear a little more "full".
2013-09-18Register new snapshotsAlex Crichton-3/+1
2013-09-17Document a few undocumented modules in libstdAlex Crichton-0/+52
Hopefull this will make our libstd docs appear a little more "full".
2013-09-16switch Drop to `&mut self`Daniel Micay-1/+1
2013-09-15c_str: Add new method .as_str() -> Option<&str>Kevin Ballard-3/+74
Also rustify .as_bytes(), so it no longer calls libc::strlen() and is inlineable.
2013-09-09rename `std::iterator` to `std::iter`Daniel Micay-2/+2
The trait will keep the `Iterator` naming, but a more concise module name makes using the free functions less verbose. The module will define iterables in addition to iterators, as it deals with iteration in general.
2013-09-04Added explicit pub to several conditions. Enables completion of #6009.Felix S. Klock II-3/+3
2013-09-03Fixes #8881. condition! imports parent's pub identifiersjmgrosen-0/+2