Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

book: use abort() over loop {} for panic #38138

Merged
merged 1 commit into from
Jan 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 4 additions & 7 deletions src/doc/book/lang-items.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@ and one for deallocation. A freestanding program that uses the `Box`
sugar for dynamic allocations via `malloc` and `free`:

```rust,ignore
#![feature(lang_items, box_syntax, start, libc)]
#![feature(lang_items, box_syntax, start, libc, core_intrinsics)]
#![no_std]
use core::intrinsics;

extern crate libc;

extern {
fn abort() -> !;
}

#[lang = "owned_box"]
pub struct Box<T>(*mut T);

Expand All @@ -34,7 +31,7 @@ unsafe fn allocate(size: usize, _align: usize) -> *mut u8 {

// Check if `malloc` failed:
if p as usize == 0 {
abort();
intrinsics::abort();
}

p
Expand All @@ -58,7 +55,7 @@ fn main(argc: isize, argv: *const *const u8) -> isize {
}

#[lang = "eh_personality"] extern fn rust_eh_personality() {}
#[lang = "panic_fmt"] extern fn rust_begin_panic() -> ! { loop {} }
#[lang = "panic_fmt"] extern fn rust_begin_panic() -> ! { unsafe { intrinsics::abort() } }
# #[lang = "eh_unwind_resume"] extern fn rust_eh_unwind_resume() {}
# #[no_mangle] pub extern fn rust_eh_register_frames () {}
# #[no_mangle] pub extern fn rust_eh_unregister_frames () {}
Expand Down
10 changes: 6 additions & 4 deletions src/doc/book/no-stdlib.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ The function marked `#[start]` is passed the command line parameters
in the same format as C:

```rust,ignore
#![feature(lang_items)]
#![feature(lang_items, core_intrinsics)]
#![feature(start)]
#![no_std]
use core::intrinsics;

// Pull in the system libc library for what crt0.o likely requires.
extern crate libc;
Expand Down Expand Up @@ -69,7 +70,7 @@ pub extern fn rust_eh_unwind_resume() {
pub extern fn rust_begin_panic(_msg: core::fmt::Arguments,
_file: &'static str,
_line: u32) -> ! {
loop {}
unsafe { intrinsics::abort() }
}
```

Expand All @@ -79,10 +80,11 @@ correct ABI and the correct name, which requires overriding the
compiler's name mangling too:

```rust,ignore
#![feature(lang_items)]
#![feature(lang_items, core_intrinsics)]
#![feature(start)]
#![no_std]
#![no_main]
use core::intrinsics;

// Pull in the system libc library for what crt0.o likely requires.
extern crate libc;
Expand Down Expand Up @@ -112,7 +114,7 @@ pub extern fn rust_eh_unwind_resume() {
pub extern fn rust_begin_panic(_msg: core::fmt::Arguments,
_file: &'static str,
_line: u32) -> ! {
loop {}
unsafe { intrinsics::abort() }
}
```

Expand Down