Skip to content

Commit 9b18088

Browse files
committed
---
yaml --- r: 227726 b: refs/heads/try c: fd874cd h: refs/heads/master v: v3
1 parent 83e640e commit 9b18088

File tree

8 files changed

+98
-23
lines changed

8 files changed

+98
-23
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: aca2057ed5fb7af3f8905b2bc01f72fa001c35c8
33
refs/heads/snap-stage3: 1af31d4974e33027a68126fa5a5a3c2c6491824f
4-
refs/heads/try: 8193133f3548390559936fdaf377f5ef951ffd29
4+
refs/heads/try: fd874cd02e3a17b0050467559da0ed053f9dbe3a
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
66
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
77
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try/src/doc/trpl/ffi.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,3 +530,37 @@ The `extern` makes this function adhere to the C calling convention, as
530530
discussed above in "[Foreign Calling
531531
Conventions](ffi.html#foreign-calling-conventions)". The `no_mangle`
532532
attribute turns off Rust's name mangling, so that it is easier to link to.
533+
534+
# FFI and panics
535+
536+
It’s important to be mindful of `panic!`s when working with FFI. This code,
537+
when called from C, will `abort`:
538+
539+
```rust
540+
#[no_mangle]
541+
pub extern fn oh_no() -> ! {
542+
panic!("Oops!");
543+
}
544+
# fn main() {}
545+
```
546+
547+
If you’re writing code that may panic, you should run it in another thread,
548+
so that the panic doesn’t bubble up to C:
549+
550+
```rust
551+
use std::thread;
552+
553+
#[no_mangle]
554+
pub extern fn oh_no() -> i32 {
555+
let h = thread::spawn(|| {
556+
panic!("Oops!");
557+
});
558+
559+
match h.join() {
560+
Ok(_) => 1,
561+
Err(_) => 0,
562+
}
563+
}
564+
# fn main() {}
565+
```
566+

branches/try/src/libcore/num/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,14 +1372,13 @@ macro_rules! from_str_float_impl {
13721372
/// This function accepts strings such as
13731373
///
13741374
/// * '3.14'
1375-
/// * '+3.14', equivalent to '3.14'
13761375
/// * '-3.14'
13771376
/// * '2.5E10', or equivalently, '2.5e10'
13781377
/// * '2.5E-10'
13791378
/// * '.' (understood as 0)
13801379
/// * '5.'
13811380
/// * '.5', or, equivalently, '0.5'
1382-
/// * '+inf', 'inf', '-inf', 'NaN'
1381+
/// * 'inf', '-inf', 'NaN'
13831382
///
13841383
/// Leading and trailing whitespace represent an error.
13851384
///

branches/try/src/liblibc/lib.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5493,17 +5493,17 @@ pub mod funcs {
54935493
pub fn dup2(src: c_int, dst: c_int) -> c_int;
54945494
#[link_name = "_execv"]
54955495
pub fn execv(prog: *const c_char,
5496-
argv: *mut *const c_char) -> intptr_t;
5496+
argv: *const *const c_char) -> intptr_t;
54975497
#[link_name = "_execve"]
5498-
pub fn execve(prog: *const c_char, argv: *mut *const c_char,
5499-
envp: *mut *const c_char)
5498+
pub fn execve(prog: *const c_char, argv: *const *const c_char,
5499+
envp: *const *const c_char)
55005500
-> c_int;
55015501
#[link_name = "_execvp"]
55025502
pub fn execvp(c: *const c_char,
5503-
argv: *mut *const c_char) -> c_int;
5503+
argv: *const *const c_char) -> c_int;
55045504
#[link_name = "_execvpe"]
5505-
pub fn execvpe(c: *const c_char, argv: *mut *const c_char,
5506-
envp: *mut *const c_char) -> c_int;
5505+
pub fn execvpe(c: *const c_char, argv: *const *const c_char,
5506+
envp: *const *const c_char) -> c_int;
55075507
#[link_name = "_getcwd"]
55085508
pub fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char;
55095509
#[link_name = "_getpid"]
@@ -5687,12 +5687,12 @@ pub mod funcs {
56875687
pub fn dup(fd: c_int) -> c_int;
56885688
pub fn dup2(src: c_int, dst: c_int) -> c_int;
56895689
pub fn execv(prog: *const c_char,
5690-
argv: *mut *const c_char) -> c_int;
5691-
pub fn execve(prog: *const c_char, argv: *mut *const c_char,
5692-
envp: *mut *const c_char)
5690+
argv: *const *const c_char) -> c_int;
5691+
pub fn execve(prog: *const c_char, argv: *const *const c_char,
5692+
envp: *const *const c_char)
56935693
-> c_int;
56945694
pub fn execvp(c: *const c_char,
5695-
argv: *mut *const c_char) -> c_int;
5695+
argv: *const *const c_char) -> c_int;
56965696
pub fn fork() -> pid_t;
56975697
pub fn fpathconf(filedes: c_int, name: c_int) -> c_long;
56985698
pub fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char;
@@ -5702,7 +5702,9 @@ pub mod funcs {
57025702
pub fn getgroups(ngroups_max: c_int, groups: *mut gid_t)
57035703
-> c_int;
57045704
pub fn getlogin() -> *mut c_char;
5705-
pub fn getopt(argc: c_int, argv: *mut *const c_char,
5705+
// GNU getopt(3) modifies its arguments despite the
5706+
// char * const [] prototype; see the manpage.
5707+
pub fn getopt(argc: c_int, argv: *mut *mut c_char,
57065708
optstr: *const c_char) -> c_int;
57075709
pub fn getpgrp() -> pid_t;
57085710
pub fn getpid() -> pid_t;
@@ -5752,19 +5754,19 @@ pub mod funcs {
57525754
pub fn dup(fd: c_int) -> c_int;
57535755
pub fn dup2(src: c_int, dst: c_int) -> c_int;
57545756
pub fn execv(prog: *const c_char,
5755-
argv: *mut *const c_char) -> c_int;
5756-
pub fn execve(prog: *const c_char, argv: *mut *const c_char,
5757-
envp: *mut *const c_char)
5757+
argv: *const *const c_char) -> c_int;
5758+
pub fn execve(prog: *const c_char, argv: *const *const c_char,
5759+
envp: *const *const c_char)
57585760
-> c_int;
57595761
pub fn execvp(c: *const c_char,
5760-
argv: *mut *const c_char) -> c_int;
5762+
argv: *const *const c_char) -> c_int;
57615763
pub fn fork() -> pid_t;
57625764
pub fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char;
57635765
pub fn getegid() -> gid_t;
57645766
pub fn geteuid() -> uid_t;
57655767
pub fn getgid() -> gid_t;
57665768
pub fn getlogin() -> *mut c_char;
5767-
pub fn getopt(argc: c_int, argv: *mut *const c_char,
5769+
pub fn getopt(argc: c_int, argv: *const *const c_char,
57685770
optstr: *const c_char) -> c_int;
57695771
pub fn getuid() -> uid_t;
57705772
pub fn getsid(pid: pid_t) -> pid_t;

branches/try/src/libstd/io/error.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ pub struct Error {
3737
repr: Repr,
3838
}
3939

40-
#[derive(Debug)]
4140
enum Repr {
4241
Os(i32),
4342
Custom(Box<Custom>),
@@ -240,6 +239,17 @@ impl Error {
240239
}
241240
}
242241

242+
impl fmt::Debug for Repr {
243+
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
244+
match self {
245+
&Repr::Os(ref code) =>
246+
fmt.debug_struct("Os").field("code", code)
247+
.field("message", &sys::os::error_string(*code)).finish(),
248+
&Repr::Custom(ref c) => fmt.debug_tuple("Custom").field(c).finish(),
249+
}
250+
}
251+
}
252+
243253
#[stable(feature = "rust1", since = "1.0.0")]
244254
impl fmt::Display for Error {
245255
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
@@ -282,6 +292,16 @@ mod test {
282292
use error;
283293
use error::Error as error_Error;
284294
use fmt;
295+
use sys::os::error_string;
296+
297+
#[test]
298+
fn test_debug_error() {
299+
let code = 6;
300+
let msg = error_string(code);
301+
let err = Error { repr: super::Repr::Os(code) };
302+
let expected = format!("Error {{ repr: Os {{ code: {:?}, message: {:?} }} }}", code, msg);
303+
assert_eq!(format!("{:?}", err), expected);
304+
}
285305

286306
#[test]
287307
fn test_downcasting() {

branches/try/src/libstd/net/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ mod udp;
3030
mod parser;
3131
#[cfg(test)] mod test;
3232

33-
/// Possible values which can be passed to the `shutdown` method of `TcpStream`
34-
/// and `UdpSocket`.
33+
/// Possible values which can be passed to the `shutdown` method of `TcpStream`.
3534
#[derive(Copy, Clone, PartialEq, Debug)]
3635
#[stable(feature = "rust1", since = "1.0.0")]
3736
pub enum Shutdown {

branches/try/src/libstd/sys/unix/process.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ impl Process {
313313
if !envp.is_null() {
314314
*sys::os::environ() = envp as *const _;
315315
}
316-
let _ = libc::execvp(*argv, argv as *mut _);
316+
let _ = libc::execvp(*argv, argv);
317317
fail(&mut output)
318318
}
319319

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
trait Tup {
12+
type T0;
13+
type T1;
14+
}
15+
16+
impl Tup for isize {
17+
type T0 = f32;
18+
type T1 = ();
19+
}
20+
21+
fn main() {}

0 commit comments

Comments
 (0)