-
Notifications
You must be signed in to change notification settings - Fork 214
Add custom-fallback
Backend
#684
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
Open
bushrat011899
wants to merge
7
commits into
rust-random:master
Choose a base branch
from
bushrat011899:custom_fallback_v2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
92b8034
Add `custom-fallback` feature
bushrat011899 d30f559
Address CI failures
bushrat011899 63b9e5f
Address further CI failures
bushrat011899 17d7d58
Another round of CI failures
bushrat011899 7b98ff7
Sanitize `set_backend` macro and test in CI
bushrat011899 ca81b68
`cargo fmt`
bushrat011899 f4d8a45
Properly set working directory for fallback_test
bushrat011899 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
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 |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
**/*.rs.bk | ||
nopanic_check/Cargo.lock | ||
nopanic_check/target/ | ||
fallback_test/Cargo.lock | ||
fallback_test/target/ |
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,19 @@ | ||
[package] | ||
name = "fallback_test" | ||
description = "Test crate for assessing the custom-fallback feature" | ||
version = "0.1.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
[dependencies] | ||
getrandom = { path = "..", default-features = false } | ||
|
||
[features] | ||
fallback = ["getrandom/custom-fallback"] | ||
fail-double-definition = ["fallback"] | ||
|
||
[profile.release] | ||
panic = "abort" | ||
|
||
[profile.dev] | ||
panic = "abort" |
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,56 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
#[panic_handler] | ||
fn handle(_info: &core::panic::PanicInfo) -> ! { | ||
loop {} | ||
} | ||
|
||
use getrandom::{Backend, Error}; | ||
|
||
/// This implementation fills using a constant value of 4. | ||
/// | ||
/// WARNING: this custom implementation is for testing purposes ONLY! | ||
struct ConstantBackend; | ||
|
||
unsafe impl Backend for ConstantBackend { | ||
#[inline] | ||
fn fill_uninit(dest: &mut [core::mem::MaybeUninit<u8>]) -> Result<(), Error> { | ||
for out in dest { | ||
// Chosen by fair dice roll | ||
out.write(4); | ||
} | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
#[cfg(feature = "fallback")] | ||
const _: () = { | ||
getrandom::set_backend!(ConstantBackend); | ||
}; | ||
|
||
// This second call will cause the following compile-time error: | ||
/* | ||
error: symbol `__getrandom_v03_fallback_fill_uninit` is already defined | ||
--> src\main.rs:43:1 | ||
| | ||
43 | getrandom::set_backend!(ConstantBackend); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: this error originates in the macro `getrandom::set_backend` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: could not compile `fallback_test` (bin "fallback_test") due to 1 previous error | ||
*/ | ||
#[cfg(feature = "fail-double-definition")] | ||
const _: () = { | ||
getrandom::set_backend!(ConstantBackend); | ||
}; | ||
|
||
#[no_mangle] | ||
pub extern "C" fn _start() { | ||
let mut dest = [0u8; 13]; | ||
let result = getrandom::fill(&mut dest); | ||
assert!(result.is_ok()); | ||
assert_eq!(dest, [4; 13]); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change the documentation to say that this feature should only be enabled by a crate which provides a custom fallback.