-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #135 from Alexhuszagh/writesafe
This introduces numerous different layers of security enhancements: 1. Removal of most unsafe code (according to count-unsafe, the code went from 160 unsafe functions and 3088 unsafe exprs to 8 unsafe functions and 1248 unsafe exprs, However, all the remaining unsafe code has much clearly documented safety guarantees and is isolated into safe abstractions. 2. Clear documentation of the locations where unsafe code is used and at the crate-level documentation so it's clearly visible. A security policy has also been added, with stricter requirements for soundness with PRs. Closes #100.
- Loading branch information
Showing
42 changed files
with
570 additions
and
1,007 deletions.
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 |
---|---|---|
|
@@ -6,6 +6,7 @@ Cargo.lock | |
/build | ||
*.pyc | ||
TODO.md | ||
*.diff | ||
|
||
# Perftools | ||
perf.data | ||
|
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#[macro_use] | ||
mod input; | ||
|
||
use core::mem; | ||
use core::time::Duration; | ||
|
||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
use lexical_write_float::ToLexical; | ||
|
||
// Default random data size. | ||
const COUNT: usize = 1000; | ||
|
||
// BENCHES | ||
|
||
macro_rules! gen_vec { | ||
($exp_mask:expr, $i:ident, $f:ident) => {{ | ||
let mut vec: Vec<$f> = Vec::with_capacity(COUNT); | ||
for _ in 0..COUNT { | ||
let value = fastrand::$i($exp_mask..); | ||
// NOTE: We want mem::transmute, not from_bits because we | ||
// don't want the special handling of from_bits | ||
#[allow(clippy::transmute_int_to_float)] | ||
vec.push(unsafe { mem::transmute::<$i, $f>(value) }); | ||
} | ||
vec | ||
}}; | ||
} | ||
|
||
macro_rules! bench { | ||
($fn:ident, $name:literal) => { | ||
fn $fn(criterion: &mut Criterion) { | ||
let mut group = criterion.benchmark_group($name); | ||
group.measurement_time(Duration::from_secs(5)); | ||
let exp32_mask: u32 = 0x7F800000; | ||
let exp64_mask: u64 = 0x7FF0000000000000; | ||
|
||
let f32_data = gen_vec!(exp32_mask, u32, f32); | ||
let f64_data = gen_vec!(exp64_mask, u64, f64); | ||
|
||
write_float_generator!(group, "f32", f32_data.iter(), format32); | ||
write_float_generator!(group, "f64", f64_data.iter(), format64); | ||
} | ||
}; | ||
} | ||
|
||
bench!(random_special, "random:special"); | ||
criterion_group!(special_benches, random_special); | ||
criterion_main!(special_benches); |
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
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
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
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
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
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
Oops, something went wrong.