1
0
mirror of https://github.com/bspeice/qadapt synced 2025-07-01 13:56:14 -04:00

Get version 0.4 ready

This commit is contained in:
2018-11-15 20:16:49 -05:00
parent 398b1395a0
commit 8b4ebe8c88
7 changed files with 53 additions and 26 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "qadapt-macro"
version = "0.3.0"
version = "0.4.0"
authors = ["Bradlee Speice <bradlee@speice.io>"]
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

View File

@ -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,

View File

@ -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<TokenTree> = Vec::new();
let mut item_iter = item.into_iter();