Skip to content

Commit 1290db8

Browse files
committed
---
yaml --- r: 148825 b: refs/heads/try2 c: dce61c9 h: refs/heads/master i: 148823: ebc9cb6 v: v3
1 parent 47caec6 commit 1290db8

File tree

4 files changed

+145
-55
lines changed

4 files changed

+145
-55
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: c19a7b68577f28547bdfb357798d05163ccb6824
8+
refs/heads/try2: dce61c980e0f5e18972caa22e0b78995f0501f51
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/etc/zsh/_rust

Lines changed: 70 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,80 +5,110 @@ local -a _rustc_opts_switches _rustc_opts_lint _rustc_opts_debug
55
typeset -A opt_args
66

77
_rustc_opts_switches=(
8+
--android-cross-path'[The path to the Android NDK]'
9+
--ar'[Program to use for managing archives instead of the default.]'
810
--bin'[Compile an executable crate (default)]'
911
-c'[Compile and assemble, but do not link]'
1012
--cfg'[Configure the compilation environment]'
13+
--crate-id'[Output the crate id and exit]'
14+
--crate-file-name'[Output the file(s) that would be written if compilation continued and exit]'
15+
--crate-name'[Output the crate name and exit]'
16+
--dep-info'[Output dependency info to <filename> after compiling]'
17+
--dylib'[Compile a dynamic library crate]'
1118
--emit-llvm'[Produce an LLVM bitcode file]'
1219
{-h,--help}'[Display this message]'
1320
-L'[Add a directory to the library search path]'
1421
--lib'[Compile a library crate]'
1522
--linker'[Program to use for linking instead of the default.]'
1623
--link-args'[FLAGS is a space-separated list of flags passed to the linker]'
24+
--llvm-args'[A list of arguments to pass to llvm, comma separated]'
1725
--ls'[List the symbols defined by a library crate]'
26+
--no-analysis'[Parse and expand the output, but run no analysis or produce output]'
27+
--no-rpath'[Disables setting the rpath in libs/exes]'
1828
--no-trans'[Run all passes except translation; no output]'
1929
-O'[Equivalent to --opt-level=2]'
2030
-o'[Write output to <filename>]'
2131
--opt-level'[Optimize with possible levels 0-3]'
2232
--out-dir'[Write output to compiler-chosen filename in <dir>]'
2333
--parse-only'[Parse only; do not compile, assemble, or link]'
34+
--passes'[Comma or space separated list of pass names to use]'
2435
--pretty'[Pretty-print the input instead of compiling]'
36+
--rlib'[Compile a rust library crate as an rlib file]'
2537
-S'[Compile only; do not assemble or link]'
2638
--save-temps'[Write intermediate files (.bc, .opt.bc, .o) in addition to normal output]'
39+
--staticlib'[Compile a static library crate]'
2740
--sysroot'[Override the system root]'
2841
--test'[Build a test harness]'
2942
--target'[Target triple cpu-manufacturer-kernel\[-os\] to compile]'
3043
--target-cpu'[Select target processor (llc -mcpu=help for details)]'
3144
--target-feature'[Target specific attributes (llc -mattr=help for details)]'
32-
--android-cross-path'[The path to the Android NDK]'
3345
{-v,--version}'[Print version info and exit]'
3446
)
3547
_rustc_opts_lint=(
36-
'path-statement[path statements with no effect]'
37-
'missing-trait-doc[detects missing documentation for traits]'
38-
'missing-struct-doc[detects missing documentation for structs]'
48+
'attribute-usage[detects bad use of attributes]'
3949
'ctypes[proper use of std::libc types in foreign modules]'
40-
"unused-mut[detect mut variables which don't need to be mutable]"
41-
'unused-imports[imports that are never used]'
42-
'heap-memory[use of any (~ type or @ type) heap memory]'
43-
'default-methods[allow default methods]'
44-
'unused-variable[detect variables which are not used in any way]'
4550
'dead-assignment[detect assignments that will never be read]'
46-
'unrecognized-lint[unrecognized lint attribute]'
47-
'type-limits[comparisons made useless by limits of the types involved]'
48-
'unused-unsafe[unnecessary use of an `unsafe` block]'
49-
'while-true[suggest using loop { } instead of while(true) { }]'
50-
'non-camel-case-types[types, variants and traits should have camel case names]'
51+
'dead-code[detect piece of code that will never be used]'
52+
'default-type-param-usage[prevents explicitly setting a type parameter with a default]'
53+
'deprecated[detects use of #\[deprecated\] items]'
54+
'experimental[detects use of #\[experimental\] items]'
55+
'heap-memory[use of any (~ type or @ type) heap memory]'
5156
'managed-heap-memory[use of managed (@ type) heap memory]'
52-
'unnecessary-allocation[detects unnecessary allocations that can be eliminated]'
57+
'missing-doc[detects missing documentation for public members]'
58+
'non-camel-case-types[types, variants and traits should have camel case names]'
59+
'non-uppercase-pattern-statics[static constants in match patterns should be all caps]'
60+
'non-uppercase-statics[static constants should have uppercase identifiers]'
5361
'owned-heap-memory[use of owned (~ type) heap memory]'
62+
'path-statement[path statements with no effect]'
63+
'type-limits[comparisons made useless by limits of the types involved]'
64+
'type-overflow[literal out of range for its type]'
65+
'unknown-crate-type[unknown crate type found in #\[crate_type\] directive]'
66+
'unknown-features[unknown features found in crate-level #\[feature\] directives]'
67+
'unnecessary-allocation[detects unnecessary allocations that can be eliminated]'
68+
'unnecessary-parens[`if`, `match`, `while` and `return` do not need parentheses]'
69+
'unnecessary-qualification[detects unnecessarily qualified names]'
70+
'unnecessary-typecast[detects unnecessary type casts, that can be removed]'
71+
'unreachable-code[detects unreachable code]'
72+
'unrecognized-lint[unrecognized lint attribute]'
73+
'unsafe-block[usage of an `unsafe` block]'
74+
'unstable[detects use of #\[unstable\] items (incl. items with no stability attribute)]'
75+
'unused-imports[imports that are never used]'
76+
'unused-must-use[unused result of an type flagged as #\[must_use\]]'
77+
"unused-mut[detect mut variables which don't need to be mutable]"
78+
'unused-result[unused result of an expression in a statement]'
79+
'unused-unsafe[unnecessary use of an `unsafe` block]'
80+
'unused-variable[detect variables which are not used in any way]'
81+
'warnings[mass-change the level for lints which produce warnings]'
82+
'while-true[suggest using `loop { }` instead of `while true { }`]'
5483
)
5584

5685
_rustc_opts_debug=(
57-
'verbose:in general, enable more debug printouts'
58-
'time-passes:measure time of each rustc pass'
59-
'count-llvm-insns:count where LLVM instrs originate'
60-
'time-llvm-passes:measure time of each LLVM pass'
61-
'trans-stats:gather trans statistics'
62-
'asm-comments:generate comments into the assembly (may change behavior)'
63-
'no-verify:skip LLVM verification'
64-
'trace:emit trace logs'
65-
'coherence:perform coherence checking'
66-
'borrowck-stats:gather borrowck statistics'
67-
"borrowck-note-pure:note where purity is req'd"
68-
"borrowck-note-loan:note where loans are req'd"
69-
'no-landing-pads:omit landing pads for unwinding'
70-
'debug-llvm:enable debug output from LLVM'
71-
'count-type-sizes:count the sizes of aggregate types'
72-
'meta-stats:gather metadata statistics'
73-
'no-opt:do not optimize, even if -O is passed'
74-
'print-link-args:Print the arguments passed to the linker'
75-
'gc:Garbage collect shared data (experimental)'
76-
'jit:Execute using JIT (experimental)'
77-
'extra-debug-info:Extra debugging info (experimental)'
78-
'debug-info:Produce debug info (experimental)'
79-
'static:Use or produce static libraries or binaries (experimental)'
80-
'no-debug-borrows:do not show where borrow checks fail'
81-
'lint-llvm:Run the LLVM lint pass on the pre-optimization IR'
86+
'asm-comments[generate comments into the assembly (may change behavior)]'
87+
'borrowck-stats[gather borrowck statistics]'
88+
'count-llvm-insns[count where LLVM instrs originate]'
89+
'count-type-sizes[count the sizes of aggregate types]'
90+
'debug-info[Produce debug info (experimental)]'
91+
'debug-llvm[enable debug output from LLVM]'
92+
'extra-debug-info[Extra debugging info (experimental)]'
93+
'gc[Garbage collect shared data (experimental)]'
94+
'gen-crate-map[Force generation of a toplevel crate map]'
95+
'lto[Perform LLVM link-time optimizations]'
96+
'meta-stats[gather metadata statistics]'
97+
"no-integrated-as[Use external assembler rather than LLVM's integrated one]"
98+
'no-landing-pads[omit landing pads for unwinding]'
99+
'no-opt[do not optimize, even if -O is passed]'
100+
"no-prepopulate-passes[Don't pre-populate the pass managers with a list of passes, only use the passes from --passes]"
101+
"no-vectorize-loops[Don't run the loop vectorization optimization passes]"
102+
"no-vectorize-slp[Don't run LLVM's SLP vectorization passes]"
103+
'no-verify[skip LLVM verification]'
104+
'prefer-dynamic[Prefer dynamic linking to static linking]'
105+
'print-link-args[Print the arguments passed to the linker]'
106+
'print-llvm-passes[Prints the llvm optimization passes being run]'
107+
'soft-float[Generate software floating point library calls]'
108+
'time-llvm-passes[measure time of each LLVM pass]'
109+
'time-passes[measure time of each rustc pass]'
110+
'trans-stats[gather trans statistics]'
111+
'verbose[in general, enable more debug printouts]'
82112
)
83113

84114
_rustc_opts_fun_lint(){

branches/try2/src/libstd/c_str.rs

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ use iter::{Iterator, range};
6868
use libc;
6969
use kinds::marker;
7070
use ops::Drop;
71+
use cmp::Eq;
72+
use clone::Clone;
7173
use option::{Option, Some, None};
7274
use ptr::RawPtr;
7375
use ptr;
@@ -76,6 +78,7 @@ use str;
7678
use vec::{CloneableVector, ImmutableVector, MutableVector};
7779
use vec;
7880
use unstable::intrinsics;
81+
use rt::global_heap::malloc_raw;
7982

8083
/// Resolution options for the `null_byte` condition
8184
pub enum NullByteResolution {
@@ -99,6 +102,36 @@ pub struct CString {
99102
priv owns_buffer_: bool,
100103
}
101104

105+
impl Clone for CString {
106+
/// Clone this CString into a new, uniquely owned CString. For safety
107+
/// reasons, this is always a deep clone, rather than the usual shallow
108+
/// clone.
109+
fn clone(&self) -> CString {
110+
if self.buf.is_null() {
111+
CString { buf: self.buf, owns_buffer_: self.owns_buffer_ }
112+
} else {
113+
let len = self.len() + 1;
114+
let buf = unsafe { malloc_raw(len) } as *mut libc::c_char;
115+
unsafe { ptr::copy_nonoverlapping_memory(buf, self.buf, len); }
116+
CString { buf: buf as *libc::c_char, owns_buffer_: true }
117+
}
118+
}
119+
}
120+
121+
impl Eq for CString {
122+
fn eq(&self, other: &CString) -> bool {
123+
if self.buf as uint == other.buf as uint {
124+
true
125+
} else if self.buf.is_null() || other.buf.is_null() {
126+
false
127+
} else {
128+
unsafe {
129+
libc::strcmp(self.buf, other.buf) == 0
130+
}
131+
}
132+
}
133+
}
134+
102135
impl CString {
103136
/// Create a C String from a pointer.
104137
pub unsafe fn new(buf: *libc::c_char, owns_buffer: bool) -> CString {
@@ -287,10 +320,7 @@ impl<'a> ToCStr for &'a [u8] {
287320

288321
unsafe fn to_c_str_unchecked(&self) -> CString {
289322
let self_len = self.len();
290-
let buf = libc::malloc(self_len as libc::size_t + 1) as *mut u8;
291-
if buf.is_null() {
292-
fail!("failed to allocate memory!");
293-
}
323+
let buf = malloc_raw(self_len + 1);
294324

295325
ptr::copy_memory(buf, self.as_ptr(), self_len);
296326
*ptr::mut_offset(buf, self_len as int) = 0;
@@ -598,6 +628,44 @@ mod tests {
598628
let c_str = unsafe { CString::new(ptr::null(), false) };
599629
c_str.iter();
600630
}
631+
632+
#[test]
633+
fn test_clone() {
634+
let a = "hello".to_c_str();
635+
let b = a.clone();
636+
assert!(a == b);
637+
}
638+
639+
#[test]
640+
fn test_clone_noleak() {
641+
fn foo(f: |c: &CString|) {
642+
let s = ~"test";
643+
let c = s.to_c_str();
644+
// give the closure a non-owned CString
645+
let mut c_ = c.with_ref(|c| unsafe { CString::new(c, false) } );
646+
f(&c_);
647+
// muck with the buffer for later printing
648+
c_.with_mut_ref(|c| unsafe { *c = 'X' as libc::c_char } );
649+
}
650+
651+
let mut c_: Option<CString> = None;
652+
foo(|c| {
653+
c_ = Some(c.clone());
654+
c.clone();
655+
// force a copy, reading the memory
656+
c.as_bytes().to_owned();
657+
});
658+
let c_ = c_.unwrap();
659+
// force a copy, reading the memory
660+
c_.as_bytes().to_owned();
661+
}
662+
663+
#[test]
664+
fn test_clone_eq_null() {
665+
let x = unsafe { CString::new(ptr::null(), false) };
666+
let y = x.clone();
667+
assert!(x == y);
668+
}
601669
}
602670

603671
#[cfg(test)]

branches/try2/src/test/run-pass/issue-8498.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,28 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// xfail-test
12-
1311
pub fn main() {
14-
// This is ok
1512
match &[(~5,~7)] {
1613
ps => {
1714
let (ref y, _) = ps[0];
18-
println!("1. y = {}", **y);
1915
assert!(**y == 5);
2016
}
2117
}
2218

23-
// This is not entirely ok
2419
match Some(&[(~5,)]) {
2520
Some(ps) => {
2621
let (ref y,) = ps[0];
27-
println!("2. y = {}", **y);
28-
if **y != 5 { println!("sadness"); }
22+
assert!(**y == 5);
2923
}
3024
None => ()
3125
}
3226

33-
// This is not ok
3427
match Some(&[(~5,~7)]) {
3528
Some(ps) => {
3629
let (ref y, ref z) = ps[0];
37-
println!("3. y = {} z = {}", **y, **z);
3830
assert!(**y == 5);
31+
assert!(**z == 7);
3932
}
4033
None => ()
4134
}
4235
}
43-

0 commit comments

Comments
 (0)