diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b077a81..a931ec0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,6 +50,15 @@ jobs: - name: Test libmimalloc-sys crate bindings (no secure) run: cargo run -p libmimalloc-sys-test + + - name: Build (extended) + run: cargo build --features extended + + - name: Test (extended) + run: cargo test --features extended + + - name: Test libmimalloc-sys crate bindings (extended) + run: cargo run --features extended -p libmimalloc-sys-test lint: name: Rustfmt / Clippy diff --git a/Cargo.toml b/Cargo.toml index 3b3c137..993e9f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,3 +31,4 @@ debug = ["libmimalloc-sys/debug"] debug_in_debug = ["libmimalloc-sys/debug_in_debug"] local_dynamic_tls = ["libmimalloc-sys/local_dynamic_tls"] no_thp = ["libmimalloc-sys/no_thp"] +extended = ["libmimalloc-sys/extended"] diff --git a/src/extended.rs b/src/extended.rs new file mode 100644 index 0000000..9b6a9a0 --- /dev/null +++ b/src/extended.rs @@ -0,0 +1,21 @@ +use crate::MiMalloc; + +impl MiMalloc { + /// Get the mimalloc version. + /// + /// For mimalloc version 1.8.6, this will return 186. + pub fn version(&self) -> u32 { + unsafe { ffi::mi_version() as u32 } + } +} + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn it_gets_version() { + let version = MiMalloc.version(); + assert!(version != 0); + } +} diff --git a/src/lib.rs b/src/lib.rs index 8943907..fffab98 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,6 +25,9 @@ extern crate libmimalloc_sys as ffi; +#[cfg(feature = "extended")] +mod extended; + use core::alloc::{GlobalAlloc, Layout}; use core::ffi::c_void; use ffi::*;