From 7d1366d56e8b4857382740f293d8ae58fd97f1a4 Mon Sep 17 00:00:00 2001 From: Nathaniel Daniel Date: Thu, 16 May 2024 17:50:46 -0700 Subject: [PATCH 1/3] Expose version function --- Cargo.toml | 1 + src/extended.rs | 21 +++++++++++++++++++++ src/lib.rs | 3 +++ 3 files changed, 25 insertions(+) create mode 100644 src/extended.rs 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..3a27f1f --- /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); + } +} \ No newline at end of file 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::*; From e1b2306728ac67354d2301bc040d877bb31cd391 Mon Sep 17 00:00:00 2001 From: Nathaniel Daniel Date: Thu, 16 May 2024 17:56:16 -0700 Subject: [PATCH 2/3] Run cargo fmt --- src/extended.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/extended.rs b/src/extended.rs index 3a27f1f..9b6a9a0 100644 --- a/src/extended.rs +++ b/src/extended.rs @@ -2,7 +2,7 @@ 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 } @@ -12,10 +12,10 @@ impl MiMalloc { #[cfg(test)] mod test { use super::*; - + #[test] fn it_gets_version() { let version = MiMalloc.version(); assert!(version != 0); } -} \ No newline at end of file +} From 7a15df134eeb87379bb67b65aa4fdf2d76935e16 Mon Sep 17 00:00:00 2001 From: Nathaniel Daniel Date: Thu, 16 May 2024 17:57:15 -0700 Subject: [PATCH 3/3] Test extended feature on ci --- .github/workflows/ci.yml | 9 +++++++++ 1 file changed, 9 insertions(+) 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