Skip to content

Commit b95133a

Browse files
authored
Merge pull request gnzlbg#27 from gnzlbg/utils
move mallocx_align to jemalloc-sys and expose it via the ffi module
2 parents 56559c7 + c652a34 commit b95133a

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

jemalloc-sys/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,11 @@ pub extern "C" fn pthread_atfork(_prefork: *mut u8,
8787
-> i32 {
8888
0
8989
}
90+
91+
/// Computes `flags` from `align`.
92+
///
93+
/// Equivalent to the MALLOCX_ALIGN(a) macro.
94+
#[inline]
95+
pub fn MALLOCX_ALIGN(aling: usize) -> c_int {
96+
aling.trailing_zeros() as c_int
97+
}

src/lib.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ const MIN_ALIGN: usize = 8;
4545
target_arch = "sparc64")))]
4646
const MIN_ALIGN: usize = 16;
4747

48-
// MALLOCX_ALIGN(a) macro
49-
fn mallocx_align(a: usize) -> c_int {
50-
a.trailing_zeros() as c_int
51-
}
52-
5348
fn layout_to_flags(layout: &Layout) -> c_int {
5449
// If our alignment is less than the minimum alignment they we may not
5550
// have to pass special flags asking for a higher alignment. If the
@@ -59,7 +54,7 @@ fn layout_to_flags(layout: &Layout) -> c_int {
5954
if layout.align() <= MIN_ALIGN && layout.align() <= layout.size() {
6055
0
6156
} else {
62-
mallocx_align(layout.align())
57+
ffi::MALLOCX_ALIGN(layout.align())
6358
}
6459
}
6560

0 commit comments

Comments
 (0)