1
0
mirror of https://github.com/bspeice/qadapt synced 2024-12-03 19:28:10 -05:00

Merge pull request #9 from bspeice/deprecation

Mark everything deprecated
This commit is contained in:
bspeice 2019-02-11 00:25:43 -05:00 committed by GitHub
commit 963d634923
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 72 additions and 8 deletions

View File

@ -1,4 +1,10 @@
# Version 1.1.0 # Version 1.0.3
- Mark the crate deprecated; [alloc-counter](https://crates.io/crates/alloc_counter)
does a better job at solving the problems QADAPT was driven for, and I'll be putting
my effort towards improving it instead.
# Version 1.0.2
- Don't panic if calling guarded code and QADAPT isn't the allocator; - Don't panic if calling guarded code and QADAPT isn't the allocator;
Instead, let code determine at runtime whether or not QADAPT is enabled Instead, let code determine at runtime whether or not QADAPT is enabled

View File

@ -9,6 +9,8 @@
--- ---
## `debug_assert!` for your memory usage ## `debug_assert!` for your memory usage
**Please note**: This crate has been deprecated in favor of [alloc-counter](https://crates.io/crates/alloc_counter).
This allocator is a helper for writing high-performance code that is memory-sensitive; This allocator is a helper for writing high-performance code that is memory-sensitive;
a thread panic will be triggered if a function annotated with `#[no_alloc]`, a thread panic will be triggered if a function annotated with `#[no_alloc]`,
or code inside an `assert_no_alloc!` macro interacts with the allocator in any way. or code inside an `assert_no_alloc!` macro interacts with the allocator in any way.
@ -26,18 +28,31 @@ circumstance causing your application to crash.
Actually making use of QADAPT is straight-forward. To set up the allocator, Actually making use of QADAPT is straight-forward. To set up the allocator,
place the following snippet in either your program binaries (main.rs) or tests: place the following snippet in either your program binaries (main.rs) or tests:
```rust,ignore ```rust
use qadapt::QADAPT; use qadapt::QADAPT;
#[global_allocator] #[global_allocator]
static Q: QADAPT = QADAPT; static Q: QADAPT = QADAPT;
fn main() {
# // Because `debug_assertions` are on for doctests in release mode
# // we have to add an extra guard.
# if qadapt::is_active() {
assert!(qadapt::is_active());
# }
}
``` ```
After that, there are two ways of telling QADAPT that it should trigger a panic: After that, there are two ways of telling QADAPT that it should trigger a panic:
1. Annotate functions with the `#[no_alloc]` proc macro: 1. Annotate functions with the `#[no_alloc]` proc macro:
```rust,no_run ```rust
use qadapt::no_alloc; use qadapt::no_alloc;
use qadapt::QADAPT;
use std::panic::catch_unwind;
#[global_allocator]
static Q: QADAPT = QADAPT;
// This function is fine, there are no allocations here // This function is fine, there are no allocations here
#[no_alloc] #[no_alloc]
@ -53,15 +68,23 @@ fn does_panic() -> Box<u32> {
fn main() { fn main() {
do_math(); do_math();
does_panic();
let err = catch_unwind(|| does_panic());
# if qadapt::is_active() {
assert!(err.is_err());
# }
} }
``` ```
2. Evaluate expressions with the `assert_no_alloc!` macro 2. Evaluate expressions with the `assert_no_alloc!` macro
```rust,no_run ```rust
use qadapt::assert_no_alloc; use qadapt::assert_no_alloc;
use qadapt::QADAPT;
fn do_work() { #[global_allocator]
static Q: QADAPT = QADAPT;
fn main() {
// This code is allowed to trigger an allocation // This code is allowed to trigger an allocation
let b = Box::new(8); let b = Box::new(8);
@ -69,3 +92,4 @@ fn do_work() {
let x = assert_no_alloc!(*b + 2); let x = assert_no_alloc!(*b + 2);
assert_eq!(x, 10); assert_eq!(x, 10);
} }
```

View File

@ -1,6 +1,6 @@
[package] [package]
name = "qadapt-macro" name = "qadapt-macro"
version = "1.0.2" version = "1.0.3"
authors = ["Bradlee Speice <bradlee@speice.io>"] authors = ["Bradlee Speice <bradlee@speice.io>"]
description = "The Quick And Dirty Allocation Profiling Tool - Support Macros" description = "The Quick And Dirty Allocation Profiling Tool - Support Macros"
license = "Apache-2.0" license = "Apache-2.0"
@ -16,7 +16,7 @@ repository = "https://github.com/bspeice/qadapt.git"
edition = "2018" edition = "2018"
[badges] [badges]
maintenance = { status = "actively-developed" } maintenance = { status = "deprecated" }
[lib] [lib]
proc-macro = true proc-macro = true

View File

@ -5,5 +5,7 @@
Helper macro for the QADAPT allocator. Helper macro for the QADAPT allocator.
**Please note**: This crate has been deprecated in favor of [alloc-counter](https://crates.io/crates/alloc_counter)
This crate is intended for managing the QADAPT allocator, This crate is intended for managing the QADAPT allocator,
and is unusable on its own. and is unusable on its own.

View File

@ -1,5 +1,7 @@
//! Helper macros to use with the QADAPT allocator system //! Helper macros to use with the QADAPT allocator system
//! //!
//! **Please note**: This crate has been deprecated in favor of [alloc-counter](https://crates.io/crates/alloc_counter)
//!
//! This crate is intended for managing the QADAPT allocator, //! This crate is intended for managing the QADAPT allocator,
//! and is unusable on its own. //! and is unusable on its own.
//! //!
@ -155,6 +157,10 @@ fn escape_return(ts: TokenStream) -> TokenStream {
/// separate thread, or defers allocations via closure/Future, those results /// separate thread, or defers allocations via closure/Future, those results
/// will not trigger an error. /// will not trigger an error.
#[proc_macro_attribute] #[proc_macro_attribute]
#[deprecated(
since = "1.0.3",
note = "Please use the `alloc_counter` crate instead."
)]
pub fn no_alloc(_attr: TokenStream, item: TokenStream) -> TokenStream { pub fn no_alloc(_attr: TokenStream, item: TokenStream) -> TokenStream {
let mut protected_fn: Vec<TokenTree> = Vec::new(); let mut protected_fn: Vec<TokenTree> = Vec::new();
let mut item_iter = item.into_iter(); let mut item_iter = item.into_iter();

View File

@ -1,5 +1,7 @@
//! ## `debug_assert!` for your memory usage //! ## `debug_assert!` for your memory usage
//! //!
//! **Please note**: This crate has been deprecated in favor of [alloc-counter](https://crates.io/crates/alloc_counter).
//!
//! This allocator is a helper for writing high-performance code that is memory-sensitive; //! This allocator is a helper for writing high-performance code that is memory-sensitive;
//! a thread panic will be triggered if a function annotated with `#[no_alloc]`, //! a thread panic will be triggered if a function annotated with `#[no_alloc]`,
//! or code inside an `assert_no_alloc!` macro interacts with the allocator in any way. //! or code inside an `assert_no_alloc!` macro interacts with the allocator in any way.
@ -120,6 +122,10 @@ static INTERNAL_ALLOCATION: RwLock<usize> = RwLock::new(usize::max_value());
/// # } /// # }
/// } /// }
/// ``` /// ```
#[deprecated(
since = "1.0.3",
note = "Please use the `alloc_counter` crate instead."
)]
pub struct QADAPT; pub struct QADAPT;
static SYSTEM_ALLOC: System = System; static SYSTEM_ALLOC: System = System;
@ -150,6 +156,10 @@ static SYSTEM_ALLOC: System = System;
/// // It's now safe to allocate/drop again /// // It's now safe to allocate/drop again
/// let z = Box::new(y); /// let z = Box::new(y);
/// } /// }
#[deprecated(
since = "1.0.3",
note = "Please use the `alloc_counter` crate instead."
)]
pub fn enter_protected() { pub fn enter_protected() {
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
{ {
@ -191,6 +201,10 @@ pub fn enter_protected() {
/// // It's now safe to allocate/drop again /// // It's now safe to allocate/drop again
/// let z = Box::new(y); /// let z = Box::new(y);
/// } /// }
#[deprecated(
since = "1.0.3",
note = "Please use the `alloc_counter` crate instead."
)]
pub fn exit_protected() { pub fn exit_protected() {
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
{ {
@ -259,6 +273,10 @@ pub fn exit_protected() {
/// # } /// # }
/// } /// }
#[macro_export] #[macro_export]
#[deprecated(
since = "1.0.3",
note = "Please use the `alloc_counter` crate instead."
)]
macro_rules! assert_no_alloc { macro_rules! assert_no_alloc {
($e:expr) => {{ ($e:expr) => {{
::qadapt::enter_protected(); ::qadapt::enter_protected();
@ -298,6 +316,10 @@ macro_rules! assert_no_alloc {
/// ///
/// // It's now safe to allocate/drop /// // It's now safe to allocate/drop
/// } /// }
#[deprecated(
since = "1.0.3",
note = "Please use the `alloc_counter` crate instead."
)]
pub fn protection_level() -> usize { pub fn protection_level() -> usize {
PROTECTION_LEVEL.try_with(|v| *v.read()).unwrap_or(0) PROTECTION_LEVEL.try_with(|v| *v.read()).unwrap_or(0)
} }
@ -324,6 +346,10 @@ pub fn protection_level() -> usize {
/// # } /// # }
/// } /// }
/// ``` /// ```
#[deprecated(
since = "1.0.3",
note = "Please use the `alloc_counter` crate instead."
)]
pub fn is_active() -> bool { pub fn is_active() -> bool {
if cfg!(debug_assertions) { if cfg!(debug_assertions) {
// Because there are heap allocations that happen before `fn main()`, // Because there are heap allocations that happen before `fn main()`,