Skip to content

Commit aacccda

Browse files
committed
---
yaml --- r: 129005 b: refs/heads/master c: 36789fb h: refs/heads/master i: 129003: 2b331d8 v: v3
1 parent f719b74 commit aacccda

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+844
-302
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 171c54296586bd08f0cfd49098515bef045a059b
2+
refs/heads/master: 36789fbbc5568b71c1eee85bcc20ffbdcf79f7a4
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a86d9ad15e339ab343a12513f9c90556f677b9ca
55
refs/heads/try: 961753763fb87ddcbbccaec4ea87648608d19a58

trunk/src/doc/guide-ffi.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,13 @@ Rust code:
263263
264264
~~~~no_run
265265
266+
#[repr(C)]
266267
struct RustObject {
267268
a: i32,
268269
// other members
269270
}
270271
271-
extern fn callback(target: *mut RustObject, a:i32) {
272+
extern "C" fn callback(target: *mut RustObject, a:i32) {
272273
println!("I'm called from C with value {0}", a);
273274
unsafe {
274275
// Update the value in RustObject with the value received from the callback
@@ -506,16 +507,16 @@ to define a block for all windows systems, not just x86 ones.
506507
507508
# Interoperability with foreign code
508509
509-
Rust guarantees that the layout of a `struct` is compatible with the platform's representation in C.
510-
A `#[packed]` attribute is available, which will lay out the struct members without padding.
511-
However, there are currently no guarantees about the layout of an `enum`.
510+
Rust guarantees that the layout of a `struct` is compatible with the platform's representation in C
511+
only if the `#[repr(C)]` attribute is applied to it. `#[repr(C, packed)]` can be used to lay out
512+
struct members without padding. `#[repr(C)]` can also be applied to an enum.
512513
513-
Rust's owned and managed boxes use non-nullable pointers as handles which point to the contained
514+
Rust's owned boxes (`Box<T>`) use non-nullable pointers as handles which point to the contained
514515
object. However, they should not be manually created because they are managed by internal
515-
allocators. References can safely be assumed to be non-nullable pointers directly to the
516-
type. However, breaking the borrow checking or mutability rules is not guaranteed to be safe, so
517-
prefer using raw pointers (`*`) if that's needed because the compiler can't make as many assumptions
518-
about them.
516+
allocators. References can safely be assumed to be non-nullable pointers directly to the type.
517+
However, breaking the borrow checking or mutability rules is not guaranteed to be safe, so prefer
518+
using raw pointers (`*`) if that's needed because the compiler can't make as many assumptions about
519+
them.
519520
520521
Vectors and strings share the same basic memory layout, and utilities are available in the `vec` and
521522
`str` modules for working with C APIs. However, strings are not terminated with `\0`. If you need a

trunk/src/doc/guide.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,8 +1073,8 @@ destructuring `let`.
10731073
## Enums
10741074

10751075
Finally, Rust has a "sum type", an **enum**. Enums are an incredibly useful
1076-
feature of Rust, and are used throughout the standard library. Enums look
1077-
like this:
1076+
feature of Rust, and are used throughout the standard library. This is an enum
1077+
that is provided by the Rust standard library:
10781078

10791079
```{rust}
10801080
enum Ordering {
@@ -1084,9 +1084,8 @@ enum Ordering {
10841084
}
10851085
```
10861086

1087-
This is an enum that is provided by the Rust standard library. An `Ordering`
1088-
can only be _one_ of `Less`, `Equal`, or `Greater` at any given time. Here's
1089-
an example:
1087+
An `Ordering` can only be _one_ of `Less`, `Equal`, or `Greater` at any given
1088+
time. Here's an example:
10901089

10911090
```{rust}
10921091
fn cmp(a: int, b: int) -> Ordering {
@@ -2897,9 +2896,11 @@ pub fn print_hello() {
28972896
}
28982897
```
28992898

2900-
When we include a module like this, we don't need to make the `mod` declaration,
2901-
it's just understood. This helps prevent 'rightward drift': when you end up
2902-
indenting so many times that your code is hard to read.
2899+
When we include a module like this, we don't need to make the `mod` declaration
2900+
in `hello.rs`, because it's already been declared in `lib.rs`. `hello.rs` just
2901+
contains the body of the module which is defined (by the `pub mod hello`) in
2902+
`lib.rs`. This helps prevent 'rightward drift': when you end up indenting so
2903+
many times that your code is hard to read.
29032904

29042905
Finally, make a new directory, `src/goodbye`, and make a new file in it,
29052906
`src/goodbye/mod.rs`:

trunk/src/doc/rust.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,6 +1308,9 @@ struct Cookie;
13081308
let c = [Cookie, Cookie, Cookie, Cookie];
13091309
~~~~
13101310

1311+
The precise memory layout of a structure is not specified. One can specify a
1312+
particular layout using the [`repr` attribute](#ffi-attributes).
1313+
13111314
By using the `struct_inherit` feature gate, structures may use single inheritance. A Structure may only
13121315
inherit from a single other structure, called the _super-struct_. The inheriting structure (sub-struct)
13131316
acts as if all fields in the super-struct were present in the sub-struct. Fields declared in a sub-struct
@@ -1941,6 +1944,23 @@ interpreted:
19411944
- `linkage` - on a static, this specifies the [linkage
19421945
type](http://llvm.org/docs/LangRef.html#linkage-types).
19431946

1947+
On `enum`s:
1948+
1949+
- `repr` - on C-like enums, this sets the underlying type used for
1950+
representation. Takes one argument, which is the primitive
1951+
type this enum should be represented for, or `C`, which specifies that it
1952+
should be the default `enum` size of the C ABI for that platform. Note that
1953+
enum representation in C is undefined, and this may be incorrect when the C
1954+
code is compiled with certain flags.
1955+
1956+
On `struct`s:
1957+
1958+
- `repr` - specifies the representation to use for this struct. Takes a list
1959+
of options. The currently accepted ones are `C` and `packed`, which may be
1960+
combined. `C` will use a C ABI comptible struct layout, and `packed` will
1961+
remove any padding between fields (note that this is very fragile and may
1962+
break platforms which require aligned access).
1963+
19441964
### Miscellaneous attributes
19451965

19461966
- `export_name` - on statics and functions, this determines the name of the
@@ -1958,12 +1978,6 @@ interpreted:
19581978
crate at compile-time and use any syntax extensions or lints that the crate
19591979
defines. They can both be specified, `#[phase(link, plugin)]` to use a crate
19601980
both at runtime and compiletime.
1961-
- `repr` - on C-like enums, this sets the underlying type used for
1962-
representation. Useful for FFI. Takes one argument, which is the primitive
1963-
type this enum should be represented for, or `C`, which specifies that it
1964-
should be the default `enum` size of the C ABI for that platform. Note that
1965-
enum representation in C is undefined, and this may be incorrect when the C
1966-
code is compiled with certain flags.
19671981
- `simd` - on certain tuple structs, derive the arithmetic operators, which
19681982
lower to the target's SIMD instructions, if any; the `simd` feature gate
19691983
is necessary to use this attribute.

trunk/src/libcore/mem.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ use ptr;
1919

2020
pub use intrinsics::transmute;
2121

22+
/// Moves a thing into the void.
23+
///
24+
/// The forget function will take ownership of the provided value but neglect
25+
/// to run any required cleanup or memory management operations on it.
26+
///
27+
/// This function is the unsafe version of the `drop` function because it does
28+
/// not run any destructors.
29+
#[stable]
30+
pub use intrinsics::forget;
31+
2232
/// Returns the size of a type in bytes.
2333
#[inline]
2434
#[stable]
@@ -337,17 +347,6 @@ pub fn replace<T>(dest: &mut T, mut src: T) -> T {
337347
#[stable]
338348
pub fn drop<T>(_x: T) { }
339349

340-
/// Moves a thing into the void.
341-
///
342-
/// The forget function will take ownership of the provided value but neglect
343-
/// to run any required cleanup or memory management operations on it.
344-
///
345-
/// This function is the unsafe version of the `drop` function because it does
346-
/// not run any destructors.
347-
#[inline]
348-
#[stable]
349-
pub unsafe fn forget<T>(thing: T) { intrinsics::forget(thing) }
350-
351350
/// Interprets `src` as `&U`, and then reads `src` without moving the contained
352351
/// value.
353352
///

trunk/src/libcore/simd.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#[experimental]
4141
#[simd]
4242
#[deriving(Show)]
43+
#[repr(C)]
4344
pub struct i8x16(pub i8, pub i8, pub i8, pub i8,
4445
pub i8, pub i8, pub i8, pub i8,
4546
pub i8, pub i8, pub i8, pub i8,
@@ -48,22 +49,26 @@ pub struct i8x16(pub i8, pub i8, pub i8, pub i8,
4849
#[experimental]
4950
#[simd]
5051
#[deriving(Show)]
52+
#[repr(C)]
5153
pub struct i16x8(pub i16, pub i16, pub i16, pub i16,
5254
pub i16, pub i16, pub i16, pub i16);
5355

5456
#[experimental]
5557
#[simd]
5658
#[deriving(Show)]
59+
#[repr(C)]
5760
pub struct i32x4(pub i32, pub i32, pub i32, pub i32);
5861

5962
#[experimental]
6063
#[simd]
6164
#[deriving(Show)]
65+
#[repr(C)]
6266
pub struct i64x2(pub i64, pub i64);
6367

6468
#[experimental]
6569
#[simd]
6670
#[deriving(Show)]
71+
#[repr(C)]
6772
pub struct u8x16(pub u8, pub u8, pub u8, pub u8,
6873
pub u8, pub u8, pub u8, pub u8,
6974
pub u8, pub u8, pub u8, pub u8,
@@ -72,25 +77,30 @@ pub struct u8x16(pub u8, pub u8, pub u8, pub u8,
7277
#[experimental]
7378
#[simd]
7479
#[deriving(Show)]
80+
#[repr(C)]
7581
pub struct u16x8(pub u16, pub u16, pub u16, pub u16,
7682
pub u16, pub u16, pub u16, pub u16);
7783

7884
#[experimental]
7985
#[simd]
8086
#[deriving(Show)]
87+
#[repr(C)]
8188
pub struct u32x4(pub u32, pub u32, pub u32, pub u32);
8289

8390
#[experimental]
8491
#[simd]
8592
#[deriving(Show)]
93+
#[repr(C)]
8694
pub struct u64x2(pub u64, pub u64);
8795

8896
#[experimental]
8997
#[simd]
9098
#[deriving(Show)]
99+
#[repr(C)]
91100
pub struct f32x4(pub f32, pub f32, pub f32, pub f32);
92101

93102
#[experimental]
94103
#[simd]
95104
#[deriving(Show)]
105+
#[repr(C)]
96106
pub struct f64x2(pub f64, pub f64);

trunk/src/libgetopts/lib.rs

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,6 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
571571
}
572572
} else {
573573
let mut j = 1;
574-
let mut last_valid_opt_id = None;
575574
names = Vec::new();
576575
while j < curlen {
577576
let range = cur.as_slice().char_range_at(j);
@@ -584,27 +583,24 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
584583
interpreted correctly
585584
*/
586585

587-
match find_opt(opts.as_slice(), opt.clone()) {
588-
Some(id) => last_valid_opt_id = Some(id),
589-
None => {
590-
let arg_follows =
591-
last_valid_opt_id.is_some() &&
592-
match opts[last_valid_opt_id.unwrap()]
593-
.hasarg {
594-
595-
Yes | Maybe => true,
596-
No => false
597-
};
598-
if arg_follows && j < curlen {
599-
i_arg = Some(cur.as_slice()
600-
.slice(j, curlen).to_string());
601-
break;
602-
} else {
603-
last_valid_opt_id = None;
604-
}
605-
}
606-
}
586+
let opt_id = match find_opt(opts.as_slice(), opt.clone()) {
587+
Some(id) => id,
588+
None => return Err(UnrecognizedOption(opt.to_string()))
589+
};
590+
607591
names.push(opt);
592+
593+
let arg_follows = match opts[opt_id].hasarg {
594+
Yes | Maybe => true,
595+
No => false
596+
};
597+
598+
if arg_follows && range.next < curlen {
599+
i_arg = Some(cur.as_slice()
600+
.slice(range.next, curlen).to_string());
601+
break;
602+
}
603+
608604
j = range.next;
609605
}
610606
}
@@ -617,7 +613,7 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
617613
};
618614
match opts[optid].hasarg {
619615
No => {
620-
if !i_arg.is_none() {
616+
if name_pos == names.len() && !i_arg.is_none() {
621617
return Err(UnexpectedArgument(nm.to_string()));
622618
}
623619
vals.get_mut(optid).push(Given);
@@ -1441,6 +1437,21 @@ mod tests {
14411437

14421438
}
14431439

1440+
#[test]
1441+
fn test_nospace_conflict() {
1442+
let args = vec!("-vvLverbose".to_string(), "-v".to_string() );
1443+
let opts = vec!(optmulti("L", "", "library directory", "LIB"),
1444+
optflagmulti("v", "verbose", "Verbose"));
1445+
let matches = &match getopts(args.as_slice(), opts.as_slice()) {
1446+
result::Ok(m) => m,
1447+
result::Err(e) => fail!( "{}", e )
1448+
};
1449+
assert!(matches.opts_present(["L".to_string()]));
1450+
assert_eq!(matches.opts_str(["L".to_string()]).unwrap(), "verbose".to_string());
1451+
assert!(matches.opts_present(["v".to_string()]));
1452+
assert_eq!(3, matches.opt_count("v"));
1453+
}
1454+
14441455
#[test]
14451456
fn test_long_to_short() {
14461457
let mut short = Opt {

0 commit comments

Comments
 (0)