From c652a34f4ea2dcb5178b927f1521455df40ceb86 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 23 Nov 2017 13:29:19 +0100 Subject: [PATCH] [jemalloc-sys] expose mallocx_align, equivalent to MALLOCX_ALIGN macro --- jemalloc-sys/src/lib.rs | 8 ++++++++ src/lib.rs | 7 +------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/jemalloc-sys/src/lib.rs b/jemalloc-sys/src/lib.rs index f34c77af00..51a2d089e9 100644 --- a/jemalloc-sys/src/lib.rs +++ b/jemalloc-sys/src/lib.rs @@ -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 +} diff --git a/src/lib.rs b/src/lib.rs index 009696a359..185e6e23e1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 @@ -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()) } }