Skip to content

Commit 14a54e2

Browse files
committed
cargo fmt and warning removal
1 parent 940479c commit 14a54e2

File tree

2 files changed

+36
-39
lines changed

2 files changed

+36
-39
lines changed

libmimalloc-sys/src/lib.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,35 @@
33
use libc::{c_void, size_t};
44

55
extern "C" {
6-
pub fn mi_zalloc(size: size_t) -> *const c_void;
7-
pub fn mi_malloc(size: size_t) -> *const c_void;
8-
pub fn mi_realloc(p: *const c_void, size: size_t) -> *const c_void;
9-
pub fn mi_zalloc_aligned(size: size_t, alignment: size_t) -> *const c_void;
10-
pub fn mi_malloc_aligned(size: size_t, alignment: size_t) -> *const c_void;
11-
pub fn mi_realloc_aligned(p: *const c_void, size: size_t, alignment: size_t) -> *const c_void;
12-
pub fn mi_free(p: *const c_void) -> c_void;
6+
pub fn mi_zalloc(size: size_t) -> *const c_void;
7+
pub fn mi_malloc(size: size_t) -> *const c_void;
8+
pub fn mi_realloc(p: *const c_void, size: size_t) -> *const c_void;
9+
pub fn mi_zalloc_aligned(size: size_t, alignment: size_t) -> *const c_void;
10+
pub fn mi_malloc_aligned(size: size_t, alignment: size_t) -> *const c_void;
11+
pub fn mi_realloc_aligned(p: *const c_void, size: size_t, alignment: size_t) -> *const c_void;
12+
pub fn mi_free(p: *const c_void) -> c_void;
1313
}
1414

1515
#[cfg(test)]
1616
mod tests {
17-
use super::*;
17+
use super::*;
1818

19-
#[test]
20-
fn it_frees_memory_malloc() {
21-
let ptr = unsafe { mi_malloc_aligned(8, 8) } as *mut u8;
22-
unsafe { mi_free(ptr as *const c_void) };
23-
}
19+
#[test]
20+
fn it_frees_memory_malloc() {
21+
let ptr = unsafe { mi_malloc_aligned(8, 8) } as *mut u8;
22+
unsafe { mi_free(ptr as *const c_void) };
23+
}
2424

25-
#[test]
26-
fn it_frees_memory_zalloc() {
27-
let ptr = unsafe { mi_zalloc_aligned(8, 8) } as *mut u8;
28-
unsafe { mi_free(ptr as *const c_void) };
29-
}
25+
#[test]
26+
fn it_frees_memory_zalloc() {
27+
let ptr = unsafe { mi_zalloc_aligned(8, 8) } as *mut u8;
28+
unsafe { mi_free(ptr as *const c_void) };
29+
}
3030

31-
#[test]
32-
fn it_frees_memory_realloc() {
33-
let ptr = unsafe { mi_malloc_aligned(8, 8) } as *mut u8;
34-
let ptr = unsafe { mi_realloc_aligned(ptr as *const c_void, 8, 8) } as *mut u8;
35-
unsafe { mi_free(ptr as *const c_void) };
36-
}
37-
}
31+
#[test]
32+
fn it_frees_memory_realloc() {
33+
let ptr = unsafe { mi_malloc_aligned(8, 8) } as *mut u8;
34+
let ptr = unsafe { mi_realloc_aligned(ptr as *const c_void, 8, 8) } as *mut u8;
35+
unsafe { mi_free(ptr as *const c_void) };
36+
}
37+
}

src/lib.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44

55
//! A drop-in global allocator wrapper around the [mimalloc](https://github.com/microsoft/mimalloc) allocator.
66
//! Mimalloc is a general purpose, performance oriented allocator built by Microsoft.
7-
//!
7+
//!
88
//! ## Usage
99
//! ```rust,ignore
1010
//! use mimalloc::MiMalloc;
1111
//!
1212
//! #[global_allocator]
1313
//! static GLOBAL: MiMalloc = MiMalloc;
1414
//! ```
15-
//!
15+
//!
1616
//! ## Usage without secure mode
1717
//! By default this library builds mimalloc in secure mode. This means that
1818
//! heap allocations are encrypted, but this results in a 3% increase in overhead.
19-
//!
19+
//!
2020
//! To disable secure mode, in `Cargo.toml`:
2121
//! ```rust,ignore
2222
//! [dependencies]
@@ -26,9 +26,8 @@
2626
extern crate libmimalloc_sys as ffi;
2727

2828
use core::alloc::{GlobalAlloc, Layout};
29-
use core::ptr;
30-
use libc::c_void;
3129
use ffi::*;
30+
use libc::c_void;
3231

3332
// Copied from https://github.com/rust-lang/rust/blob/master/src/libstd/sys_common/alloc.rs
3433
#[cfg(all(any(
@@ -52,7 +51,7 @@ const MIN_ALIGN: usize = 8;
5251
const MIN_ALIGN: usize = 16;
5352

5453
/// Drop-in mimalloc global allocator.
55-
///
54+
///
5655
/// ## Usage
5756
/// ```rust,ignore
5857
/// use mimalloc::MiMalloc;
@@ -68,10 +67,9 @@ unsafe impl GlobalAlloc for MiMalloc {
6867
if layout.align() <= MIN_ALIGN && layout.align() <= layout.size() {
6968
mi_malloc(layout.size()) as *mut u8
7069
} else {
71-
#[cfg(target_os = "macos")]
72-
{
70+
if cfg!(target_os = "macos") {
7371
if layout.align() > (1 << 31) {
74-
return ptr::null_mut()
72+
return core::ptr::null_mut();
7573
}
7674
}
7775

@@ -84,17 +82,16 @@ unsafe impl GlobalAlloc for MiMalloc {
8482
if layout.align() <= MIN_ALIGN && layout.align() <= layout.size() {
8583
mi_zalloc(layout.size()) as *mut u8
8684
} else {
87-
#[cfg(target_os = "macos")]
88-
{
85+
if cfg!(target_os = "macos") {
8986
if layout.align() > (1 << 31) {
90-
return ptr::null_mut()
87+
return core::ptr::null_mut();
9188
}
9289
}
9390

9491
mi_zalloc_aligned(layout.size(), layout.align()) as *mut u8
9592
}
9693
}
97-
94+
9895
#[inline]
9996
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
10097
mi_free(ptr as *const c_void);
@@ -147,4 +144,4 @@ mod tests {
147144
alloc.dealloc(ptr, layout);
148145
}
149146
}
150-
}
147+
}

0 commit comments

Comments
 (0)