mirror of
				https://github.com/bspeice/qadapt
				synced 2025-10-31 09:30:37 -04:00 
			
		
		
		
	Get version 0.4 ready
This commit is contained in:
		| @ -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 | ||||
|  | ||||
| @ -1,5 +1,8 @@ | ||||
| # QADAPT - Helper macros | ||||
|  | ||||
| [](https://crates.io/crates/qadapt-macro) | ||||
| [](https://docs.rs/qadapt-macro/) | ||||
|  | ||||
| Helper macros to use with the QADAPT allocator system | ||||
|  | ||||
| This crate is intended for managing the QADAPT allocator, | ||||
|  | ||||
| @ -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(); | ||||
|  | ||||
		Reference in New Issue
	
	Block a user