Skip to content

Commit

Permalink
Merge pull request #27 from gnzlbg/utils
Browse files Browse the repository at this point in the history
move mallocx_align to jemalloc-sys and expose it via the ffi module
  • Loading branch information
alexcrichton authored Nov 28, 2017
2 parents 56559c7 + c652a34 commit b95133a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 8 additions & 0 deletions jemalloc-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,11 @@ pub extern "C" fn pthread_atfork(_prefork: *mut u8,
-> i32 {
0
}

/// Computes `flags` from `align`.
///
/// Equivalent to the MALLOCX_ALIGN(a) macro.
#[inline]
pub fn MALLOCX_ALIGN(aling: usize) -> c_int {
aling.trailing_zeros() as c_int
}
7 changes: 1 addition & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ const MIN_ALIGN: usize = 8;
target_arch = "sparc64")))]
const MIN_ALIGN: usize = 16;

// MALLOCX_ALIGN(a) macro
fn mallocx_align(a: usize) -> c_int {
a.trailing_zeros() as c_int
}

fn layout_to_flags(layout: &Layout) -> c_int {
// If our alignment is less than the minimum alignment they we may not
// have to pass special flags asking for a higher alignment. If the
Expand All @@ -59,7 +54,7 @@ fn layout_to_flags(layout: &Layout) -> c_int {
if layout.align() <= MIN_ALIGN && layout.align() <= layout.size() {
0
} else {
mallocx_align(layout.align())
ffi::MALLOCX_ALIGN(layout.align())
}
}

Expand Down

0 comments on commit b95133a

Please sign in to comment.