-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an example using c-gull and std::unwind::catch_unwind.
- Loading branch information
1 parent
be1cdad
commit cb6562c
Showing
7 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/target | ||
Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[package] | ||
name = "c-gull-unwinding" | ||
version = "0.0.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
[dependencies.libc] | ||
path = "../../c-gull" | ||
default-features = false | ||
features = [ | ||
"take-charge", | ||
"std", | ||
"thread", | ||
"call-main", | ||
"malloc-via-crates", | ||
"threadsafe-setenv" | ||
] | ||
package = "c-gull" | ||
|
||
# This is just an example crate, and not part of the c-ward workspace. | ||
[workspace] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
This crate demonstrates the use of c-gull in "take-charge" mode, and includes | ||
unwinding panic support. | ||
|
||
It's the same as [c-gull-example], but it performs an unwind. | ||
|
||
[c-gull-example]: https://github.com/sunfishcode/c-ward/tree/main/example-crates/c-gull-example#readme |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
fn main() { | ||
// Pass -nostartfiles to the linker. | ||
println!("cargo:rustc-link-arg=-nostartfiles"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//! A simple example using `std::panic::catch_unwind`. | ||
fn main() { | ||
// Panic and catch it. | ||
std::panic::catch_unwind(|| call_do_panic()).unwrap_err(); | ||
|
||
println!("Hello, world!"); | ||
unsafe { | ||
libc::printf("Hello world using libc `printf`!\n\0".as_ptr().cast()); | ||
} | ||
} | ||
|
||
fn call_do_panic() { | ||
do_panic() | ||
} | ||
|
||
fn do_panic() { | ||
panic!("catch me!"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters