From 8b4ebe8c8857c922103e822d94f633e131cf0fcc Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Thu, 15 Nov 2018 20:16:49 -0500 Subject: [PATCH] Get version 0.4 ready --- Cargo.toml | 7 +++++-- README.md | 3 +++ qadapt-macro/Cargo.toml | 5 ++++- qadapt-macro/README.md | 3 +++ qadapt-macro/src/lib.rs | 22 ++++++++++++++++++++++ src/lib.rs | 4 +--- tests/allocations.rs | 35 +++++++++++++++-------------------- 7 files changed, 53 insertions(+), 26 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 36cc0b4..ecc2079 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "qadapt" -version = "0.3.0" +version = "0.4.0" authors = ["Bradlee Speice "] description = "The Quick And Dirty Allocation Profiling Tool" license = "Apache-2.0" @@ -14,9 +14,12 @@ categories = [ ] repository = "https://github.com/bspeice/qadapt.git" +[badges] +maintenance = { status = "actively-maintained" } + [dependencies] libc = "0.2" spin = "0.4" thread-id = "3.3" -qadapt-macro = { version = "0.3.0", path = "./qadapt-macro" } \ No newline at end of file +qadapt-macro = { version = "0.4.0", path = "./qadapt-macro" } \ No newline at end of file diff --git a/README.md b/README.md index a759da9..40b7f3d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,9 @@ The Quick And Dirty Allocation Profiling Tool ============================================= +[![crates.io](https://img.shields.io/crates/v/qadapt.svg)](https://crates.io/crates/qadapt) +[![docs.rs](https://docs.rs/qadapt/badge.svg)](https://docs.rs/qadapt/) + This allocator is a helper for writing high-performance code that is allocation/drop free; for functions annotated with `#[allocate_panic]`, QADAPT will detect when allocations/drops happen during their execution (and execution of any functions they call) and throw a diff --git a/qadapt-macro/Cargo.toml b/qadapt-macro/Cargo.toml index 847fa28..ea76003 100644 --- a/qadapt-macro/Cargo.toml +++ b/qadapt-macro/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "qadapt-macro" -version = "0.3.0" +version = "0.4.0" authors = ["Bradlee Speice "] description = "The Quick And Dirty Allocation Profiling Tool - Support Macros" license = "Apache-2.0" @@ -14,5 +14,8 @@ categories = [ ] repository = "https://github.com/bspeice/qadapt.git" +[badges] +maintenance = { static = "actively-maintained" } + [lib] proc-macro = true diff --git a/qadapt-macro/README.md b/qadapt-macro/README.md index 424e993..2cfb93b 100644 --- a/qadapt-macro/README.md +++ b/qadapt-macro/README.md @@ -1,5 +1,8 @@ # QADAPT - Helper macros +[![crates.io](https://img.shields.io/crates/v/qadapt-macro.svg)](https://crates.io/crates/qadapt-macro) +[![docs.rs](https://docs.rs/dtparse/qadapt-macro.svg)](https://docs.rs/qadapt-macro/) + Helper macros to use with the QADAPT allocator system This crate is intended for managing the QADAPT allocator, diff --git a/qadapt-macro/src/lib.rs b/qadapt-macro/src/lib.rs index c236034..b2a7951 100644 --- a/qadapt-macro/src/lib.rs +++ b/qadapt-macro/src/lib.rs @@ -106,6 +106,18 @@ fn protected_body(fn_body: Group) -> TokenTree { )) } +fn contains_return(ts: TokenStream) -> bool { + for tt in ts.into_iter() { + match tt { + TokenTree::Group(ref g) => if contains_return(g.stream()) { return true }, + TokenTree::Ident(ref i) if i.to_string() == "return" => return true, + _ => (), + } + } + + false +} + /// Set up the QADAPT allocator to trigger a panic if any allocations happen during /// calls to this function. /// @@ -114,6 +126,16 @@ fn protected_body(fn_body: Group) -> TokenTree { /// separate thread, QADAPT will not trigger a panic. #[proc_macro_attribute] pub fn allocate_panic(_attr: TokenStream, item: TokenStream) -> TokenStream { + if contains_return(item.clone()) { + let mut iter = item.clone().into_iter(); + iter.next(); + let fn_name = iter.next().unwrap(); + eprintln!("QADAPT does not currently support `return` \ + statements in functions. Function named `{}` \ + DOES NOT have allocation guards in place.", fn_name); + return item; + } + let mut protected_fn: Vec = Vec::new(); let mut item_iter = item.into_iter(); diff --git a/src/lib.rs b/src/lib.rs index 9410835..6c93c39 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -131,7 +131,7 @@ unsafe impl GlobalAlloc for QADAPT { } } - unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) { + unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { if alloc_immediate() { return free(ptr as *mut c_void); } @@ -148,13 +148,11 @@ unsafe impl GlobalAlloc for QADAPT { // Tripped a bad dealloc, but make sure further memory access during unwind // doesn't have issues PROTECTION_LEVEL.with(|v| *v.write() = 0); - /* panic!( "Unexpected deallocation for size {}, protection level: {}", layout.size(), v ) - */ } _ => (), } diff --git a/tests/allocations.rs b/tests/allocations.rs index 1547832..5f0388d 100644 --- a/tests/allocations.rs +++ b/tests/allocations.rs @@ -1,4 +1,3 @@ -#![feature(asm)] extern crate qadapt; use qadapt::enter_protected; @@ -9,16 +8,11 @@ use qadapt::QADAPT; #[global_allocator] static Q: QADAPT = QADAPT; -pub fn black_box(dummy: T) -> T { - // Taken from test lib, need to mark the arg as non-introspectable - unsafe { asm!("" : : "r"(&dummy)) } - dummy -} - #[test] fn test_copy() { enter_protected(); - black_box(0u8); + let v = 0u8; + let v2 = v; exit_protected(); } @@ -41,16 +35,8 @@ fn unit_result(b: bool) -> Result<(), ()> { #[test] fn test_unit_result() { enter_protected(); - #[allow(unused)] - { - black_box(unit_result(true)); - } - black_box(unit_result(true)).unwrap(); - #[allow(unused)] - { - black_box(unit_result(false)); - } - black_box(unit_result(false)).unwrap_err(); + unit_result(true).unwrap(); + unit_result(false).unwrap_err(); exit_protected(); } @@ -80,14 +66,14 @@ fn test_vec_push_capacity() { #[test] fn test_vec_with_zero() { enter_protected(); - let _v: Vec = black_box(Vec::with_capacity(0)); + let _v: Vec = Vec::with_capacity(0); exit_protected(); } #[test] fn test_vec_new() { enter_protected(); - let _v: Vec = black_box(Vec::new()); + let _v: Vec = Vec::new(); exit_protected(); } @@ -110,3 +96,12 @@ fn exit_too_often() { exit_protected(); exit_protected(); } + +#[test] +#[should_panic] +fn intentional_drop() { + let v: Vec<()> = Vec::new(); + let v = Box::new(v); + enter_protected(); + drop(v); +}