Skip to content

Commit 510cc35

Browse files
authored
Merge pull request #34 from linxGnu/update_mimalloc
NO-ISSUE Bump to latest mimalloc, adding tests, update directive condition
2 parents 599a628 + e4bfc96 commit 510cc35

File tree

4 files changed

+41
-5
lines changed

4 files changed

+41
-5
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ members = ["libmimalloc-sys", "libmimalloc-sys/sys-test"]
2020
travis-ci = { repository = "purpleprotocol/mimalloc_rust" }
2121

2222
[dependencies]
23-
libmimalloc-sys = { path = "libmimalloc-sys", version = "0.1.15", default-features = false }
23+
libmimalloc-sys = { path = "libmimalloc-sys", version = "0.1.16", default-features = false }
2424

2525
[features]
2626
default = ["secure"]

libmimalloc-sys/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "libmimalloc-sys"
3-
version = "0.1.15"
3+
version = "0.1.16"
44
authors = ["Octavian Oncescu <octavonce@gmail.com>"]
55
edition = "2018"
66
repository = "https://github.com/purpleprotocol/mimalloc_rust/tree/master/libmimalloc-sys"

src/lib.rs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ unsafe impl GlobalAlloc for MiMalloc {
6767
if layout.align() <= MIN_ALIGN && layout.align() <= layout.size() {
6868
mi_malloc(layout.size()) as *mut u8
6969
} else {
70-
if cfg!(target_os = "macos") && layout.align() > (1 << 31) {
70+
#[cfg(target_os = "macos")]
71+
if layout.align() > (1 << 31) {
7172
return core::ptr::null_mut();
7273
}
7374

@@ -80,7 +81,8 @@ unsafe impl GlobalAlloc for MiMalloc {
8081
if layout.align() <= MIN_ALIGN && layout.align() <= layout.size() {
8182
mi_zalloc(layout.size()) as *mut u8
8283
} else {
83-
if cfg!(target_os = "macos") && layout.align() > (1 << 31) {
84+
#[cfg(target_os = "macos")]
85+
if layout.align() > (1 << 31) {
8486
return core::ptr::null_mut();
8587
}
8688

@@ -118,6 +120,17 @@ mod tests {
118120
}
119121
}
120122

123+
#[test]
124+
fn it_frees_allocated_big_memory() {
125+
unsafe {
126+
let layout = Layout::from_size_align(1 << 20, 32).unwrap();
127+
let alloc = MiMalloc;
128+
129+
let ptr = alloc.alloc(layout);
130+
alloc.dealloc(ptr, layout);
131+
}
132+
}
133+
121134
#[test]
122135
fn it_frees_zero_allocated_memory() {
123136
unsafe {
@@ -129,6 +142,17 @@ mod tests {
129142
}
130143
}
131144

145+
#[test]
146+
fn it_frees_zero_allocated_big_memory() {
147+
unsafe {
148+
let layout = Layout::from_size_align(1 << 20, 32).unwrap();
149+
let alloc = MiMalloc;
150+
151+
let ptr = alloc.alloc_zeroed(layout);
152+
alloc.dealloc(ptr, layout);
153+
}
154+
}
155+
132156
#[test]
133157
fn it_frees_reallocated_memory() {
134158
unsafe {
@@ -140,4 +164,16 @@ mod tests {
140164
alloc.dealloc(ptr, layout);
141165
}
142166
}
167+
168+
#[test]
169+
fn it_frees_reallocated_big_memory() {
170+
unsafe {
171+
let layout = Layout::from_size_align(1 << 20, 32).unwrap();
172+
let alloc = MiMalloc;
173+
174+
let ptr = alloc.alloc(layout);
175+
let ptr = alloc.realloc(ptr, layout, 2 << 20);
176+
alloc.dealloc(ptr, layout);
177+
}
178+
}
143179
}

0 commit comments

Comments
 (0)