-
Notifications
You must be signed in to change notification settings - Fork 59
Support panicking and make unsupported platforms a nop #5
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
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
05f08bd
Handle panics inside the grown stack
oli-obk 34859d8
Implement nop for unsupported platforms
oli-obk d6f75d3
Mention supported platforms
oli-obk fc16748
Properly implement "unsupported target support"
oli-obk f321d87
Use `AssertUnwindSafe` instead of trait bounds
oli-obk 93b6cdc
Breaking change is no more
oli-obk 39d678c
Prefer `Option` over magical "0" stack sizes
oli-obk 9f97d52
Properly build fallback code
oli-obk 464c387
Iniline-define the `fallback` module and use proper arguments to the …
oli-obk 30b32ea
Exponentially grow the stack and never throw away the largest stack e…
oli-obk 735492c
Add non-linux-apple-win fallback
oli-obk fadf7dd
Also add a test for non-panicking recursion
oli-obk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "stacker" | ||
version = "0.1.3" | ||
version = "0.1.4" | ||
authors = ["Alex Crichton <[email protected]>"] | ||
build = "build.rs" | ||
license = "MIT/Apache-2.0" | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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,27 @@ | ||
extern crate stacker; | ||
|
||
const RED_ZONE: usize = 100*1024; // 100k | ||
const STACK_PER_RECURSION: usize = 1 * 1024 * 1024; // 1MB | ||
|
||
pub fn ensure_sufficient_stack<R, F: FnOnce() -> R + std::panic::UnwindSafe>( | ||
f: F | ||
) -> R { | ||
stacker::maybe_grow(RED_ZONE, STACK_PER_RECURSION, f) | ||
} | ||
|
||
#[inline(never)] | ||
fn recurse(n: usize) { | ||
let x = [42u8; 50000]; | ||
if n == 0 { | ||
panic!("an inconvenient time"); | ||
} else { | ||
ensure_sufficient_stack(|| recurse(n - 1)); | ||
} | ||
drop(x); | ||
} | ||
|
||
#[test] | ||
#[should_panic] | ||
fn foo() { | ||
recurse(10000); | ||
} |
This file contains hidden or 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,24 @@ | ||
extern crate stacker; | ||
|
||
const RED_ZONE: usize = 100*1024; // 100k | ||
const STACK_PER_RECURSION: usize = 1 * 1024 * 1024; // 1MB | ||
|
||
pub fn ensure_sufficient_stack<R, F: FnOnce() -> R + std::panic::UnwindSafe>( | ||
f: F | ||
) -> R { | ||
stacker::maybe_grow(RED_ZONE, STACK_PER_RECURSION, f) | ||
} | ||
|
||
#[inline(never)] | ||
fn recurse(n: usize) { | ||
let x = [42u8; 50000]; | ||
if n != 0 { | ||
ensure_sufficient_stack(|| recurse(n - 1)); | ||
} | ||
drop(x); | ||
} | ||
|
||
#[test] | ||
fn foo() { | ||
recurse(10000); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.