bors
680eb71564
auto merge of #8532 : kballard/rust/cstr-cleanup, r=erickt
...
Implement interior null checking in `.to_c_str()`, among other changes.
2013-08-16 06:02:14 -07:00
Daniel Micay
062747b9c9
ptr: inline the Clone implementation
2013-08-15 21:12:34 -04:00
Kevin Ballard
03ef71e262
Add ToCStr method .with_c_str()
...
.with_c_str() is a replacement for the old .as_c_str(), to avoid
unnecessary boilerplate.
Replace all usages of .to_c_str().with_ref() with .with_c_str().
2013-08-15 01:33:10 -07:00
Alex Crichton
930885d5e5
Forbid pub/priv where it has no effect
...
Closes #5495
2013-08-12 23:20:46 -07:00
Daniel Micay
0cb0ef2ca5
fix build with the new snapshot compiler
2013-08-12 17:37:46 -04:00
Erick Tryzelaar
a54476b0aa
Merge remote-tracking branch 'remotes/origin/master' into remove-str-trailing-nulls
2013-08-07 14:10:39 -07:00
Daniel Micay
55f3d04101
vec: use offset_inbounds
for iterators
...
This allows LLVM to optimize vector iterators to an `getelementptr` and
`icmp` pair, instead of `getelementptr` and *two* comparisons.
Code snippet:
~~~
fn foo(xs: &mut [f64]) {
for x in xs.mut_iter() {
*x += 10.0;
}
}
~~~
LLVM IR at stage0:
~~~
; Function Attrs: noinline uwtable
define void @"_ZN3foo17_68e1b25bca131dba7_0$x2e0E"({ i64, %tydesc*, i8*, i8*, i8 }* nocapture, { double*, i64 }* nocapture) #1 {
"function top level":
%2 = getelementptr inbounds { double*, i64 }* %1, i64 0, i32 0
%3 = load double** %2, align 8
%4 = getelementptr inbounds { double*, i64 }* %1, i64 0, i32 1
%5 = load i64* %4, align 8
%6 = ptrtoint double* %3 to i64
%7 = and i64 %5, -8
%8 = add i64 %7, %6
%9 = inttoptr i64 %8 to double*
%10 = icmp eq double* %3, %9
%11 = icmp eq double* %3, null
%or.cond6 = or i1 %10, %11
br i1 %or.cond6, label %match_case, label %match_else
match_else: ; preds = %"function top level", %match_else
%12 = phi double* [ %13, %match_else ], [ %3, %"function top level" ]
%13 = getelementptr double* %12, i64 1
%14 = load double* %12, align 8
%15 = fadd double %14, 1.000000e+01
store double %15, double* %12, align 8
%16 = icmp eq double* %13, %9
%17 = icmp eq double* %13, null
%or.cond = or i1 %16, %17
br i1 %or.cond, label %match_case, label %match_else
match_case: ; preds = %match_else, %"function top level"
ret void
}
~~~
Optimized LLVM IR at stage1/stage2:
~~~
; Function Attrs: noinline uwtable
define void @"_ZN3foo17_68e1b25bca131dba7_0$x2e0E"({ i64, %tydesc*, i8*, i8*, i8 }* nocapture, { double*, i64 }* nocapture) #1 {
"function top level":
%2 = getelementptr inbounds { double*, i64 }* %1, i64 0, i32 0
%3 = load double** %2, align 8
%4 = getelementptr inbounds { double*, i64 }* %1, i64 0, i32 1
%5 = load i64* %4, align 8
%6 = lshr i64 %5, 3
%7 = getelementptr inbounds double* %3, i64 %6
%8 = icmp eq i64 %6, 0
%9 = icmp eq double* %3, null
%or.cond6 = or i1 %8, %9
br i1 %or.cond6, label %match_case, label %match_else
match_else: ; preds = %"function top level", %match_else
%.sroa.0.0.in7 = phi double* [ %10, %match_else ], [ %3, %"function top level" ]
%10 = getelementptr inbounds double* %.sroa.0.0.in7, i64 1
%11 = load double* %.sroa.0.0.in7, align 8
%12 = fadd double %11, 1.000000e+01
store double %12, double* %.sroa.0.0.in7, align 8
%13 = icmp eq double* %10, %7
br i1 %13, label %match_case, label %match_else
match_case: ; preds = %match_else, %"function top level"
ret void
}
~~~
2013-08-06 23:54:24 -04:00
Daniel Micay
7d115c9420
add an intrinsic for inbounds GEP
2013-08-06 23:41:20 -04:00
Erick Tryzelaar
5eaa4d1d2f
Merge remote-tracking branch 'remotes/origin/master' into remove-str-trailing-nulls
2013-08-06 16:21:02 -07:00
blake2-ppc
ea9c5c405e
std: Remove uint::iterate, replaced by range
2013-08-06 04:05:08 +02:00
Erick Tryzelaar
3c94b5044c
Merge remote-tracking branch 'remotes/origin/master' into str-remove-null
2013-08-04 16:23:41 -07:00
Erick Tryzelaar
bd908d4c0e
std and rustc: explicitly pass c strings to c functions
...
When strings lose their trailing null, this pattern will become dangerous:
let foo = "bar";
let foo_ptr: *u8 = &foo[0];
Instead we should use c_strs to handle this correctly.
2013-08-04 15:45:16 -07:00
Erick Tryzelaar
3102b1797e
std: replace str::as_c_str with std::c_str
2013-08-04 14:13:17 -07:00
Daniel Micay
9f74217d80
register snapshots
2013-08-03 21:09:28 -04:00
Daniel Micay
ef870d37a5
implement pointer arithmetic with GEP
...
Closes #8118 , #7136
~~~rust
extern mod extra;
use std::vec;
use std::ptr;
fn bench_from_elem(b: &mut extra::test::BenchHarness) {
do b.iter {
let v: ~[u8] = vec::from_elem(1024, 0u8);
}
}
fn bench_set_memory(b: &mut extra::test::BenchHarness) {
do b.iter {
let mut v: ~[u8] = vec::with_capacity(1024);
unsafe {
let vp = vec::raw::to_mut_ptr(v);
ptr::set_memory(vp, 0, 1024);
vec::raw::set_len(&mut v, 1024);
}
}
}
fn bench_vec_repeat(b: &mut extra::test::BenchHarness) {
do b.iter {
let v: ~[u8] = ~[0u8, ..1024];
}
}
~~~
Before:
test bench_from_elem ... bench: 415 ns/iter (+/- 17)
test bench_set_memory ... bench: 85 ns/iter (+/- 4)
test bench_vec_repeat ... bench: 83 ns/iter (+/- 3)
After:
test bench_from_elem ... bench: 84 ns/iter (+/- 2)
test bench_set_memory ... bench: 84 ns/iter (+/- 5)
test bench_vec_repeat ... bench: 84 ns/iter (+/- 3)
2013-07-30 02:50:31 -04:00
Erick Tryzelaar
7af56bb921
std: move StrUtil::as_c_str into StrSlice
2013-07-23 16:56:22 -07:00
bors
3514a5af06
auto merge of #7857 : blake2-ppc/rust/fix-test-warnings, r=alexcrichton
...
Fix warnings that only show up when compiling the tests for libstd, libextra and one in librusti. Only trivial changes.
2013-07-18 20:55:38 -07:00
bors
559d2ef925
auto merge of #7842 : thestinger/rust/closure, r=huonw
2013-07-18 08:37:39 -07:00
blake2-ppc
ff9b75f26d
Fix warnings in libstd and librusti tests
2013-07-18 02:18:56 +02:00
Patrick Walton
99b33f7219
librustc: Remove all uses of "copy".
2013-07-17 14:57:51 -07:00
Daniel Micay
0bc204e74d
rm unnecessary stage0 zero_memory
fn
2013-07-17 14:08:54 -04:00
=Mark Sinclair
294999c350
Added overloaded Add and Sub traits for pointer arithmetic
...
Implemented ptr arithmetic for *T and *mut T. Tests passing
2013-07-10 06:34:00 -04:00
Daniel Micay
6f5be9063d
ptr: optimize {swap,replace,read}_ptr
2013-07-09 22:44:11 -04:00
Niko Matsakis
59083d2c6a
Address nits by @catamorphism
2013-07-08 13:55:10 -04:00
Niko Matsakis
ba13482dfa
update ptr intrinsics and rewrite vec routines to be more correct.
...
In particular, it is not valid to go around passing uninitialized or zero'd
memory as arguments. Rust should generally be free to assume that the arguments
it gets are valid input values, but the output of intrinsics::uninit() and
intrinsics::init() are not (e.g., an @T is just null, leading to an error
if we should try to increment the ref count).
2013-07-08 13:53:44 -04:00
Huon Wilson
cdea73cf5b
Convert vec::{as_imm_buf, as_mut_buf} to methods.
2013-07-04 00:46:50 +10:00
Alex Crichton
b29c368674
Removing a lot of usage of '&const'
2013-06-29 08:35:48 -07:00
James Miller
3bc4d1a120
Remove all #[cfg(stage0)]-protected code
...
New snapshot means this can all go. Also removes places that have
comments that say they are workarounds for stage0 errors.
2013-06-21 02:43:02 +12:00
Graydon Hoare
d904c72af8
replace #[inline(always)] with #[inline]. r=burningtree.
2013-06-18 14:48:48 -07:00
Daniel Micay
fbae011ad1
fix the docstring for copy_nonoverlapping_memory
2013-06-11 19:06:01 -04:00
Daniel Micay
107e371bf0
fix the ptr::set_memory docstring
2013-06-11 17:48:44 -04:00
Huon Wilson
98ba91f81b
remove unused import warnings
2013-06-09 02:22:23 +10:00
Daniel Micay
8bcefef2f2
libc: omit memcpy, memmove and memset
...
LLVM provides these functions as intrinsics, and will generate calls to
libc when appropriate. They are exposed in the `ptr` module as
`copy_nonoverlapping_memory`, `copy_memory` and `set_memory`.
2013-06-06 15:18:45 -04:00
Daniel Micay
e900dba28a
rename the Ptr trait to RawPtr
...
Closes #6607
2013-06-03 13:50:29 -04:00
Daniel Micay
454133127a
ptr: split out borrowed pointer utilities
...
The ptr module is intended to be for raw pointers.
Closes #3111
2013-06-02 19:24:33 -04:00
Daniel Micay
042618da7b
ptr: replace unnecessary unsafe code
2013-05-31 11:32:27 -04:00
Daniel Micay
29aba8033a
mv the raw pointer {swap,replace}_ptr to std::ptr
2013-05-31 10:31:26 -04:00
Alex Crichton
007651cd26
Require documentation by default for libstd
...
Adds documentation for various things that I understand.
Adds #[allow(missing_doc)] for lots of things that I don't understand.
2013-05-30 01:02:55 -05:00
Patrick Walton
206ab89629
librustc: Stop reexporting the standard modules from prelude.
2013-05-29 19:04:53 -07:00
Alex Crichton
b04c40bb1c
Silence various warnings throughout test modules
2013-05-28 15:27:35 -05:00
Daniel Micay
e6c04dea03
fix casts on 32-bit
2013-05-27 18:14:00 -04:00
Daniel Micay
d9c0f0f188
add memset32/memset64
2013-05-26 10:26:03 -04:00
Daniel Micay
cf8e9f9aec
make the memcpy/memmove intrinsics higher-level
...
This allows them to make use of the type's alignment, instead of being
pessimistic and assuming it is only 1.
2013-05-26 10:26:03 -04:00
Daniel Micay
7bff0281c7
optimize util::swap, &mut pointers never alias
2013-05-23 23:00:16 -04:00
Daniel Micay
5ba5865e85
swap_ptr: rm equality check
...
This isn't needed semantically, and it's the wrong case to optimize for.
2013-05-23 21:57:37 -04:00
Patrick Walton
0c820d4123
libstd: Rename libcore to libstd and libstd to libextra; update makefiles.
...
This only changes the directory names; it does not change the "real"
metadata names.
2013-05-22 21:57:05 -07:00
Graydon Hoare
dde5860380
Remove some duplicated unused parts of std now that they're present in core.
2011-12-14 18:04:45 -08:00
Graydon Hoare
447414f007
Establish 'core' library separate from 'std'.
2011-12-06 12:13:04 -08:00