Skip to content

Add a no_prefix feature #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ default = ["bg_thread"]
profiling = ["jemalloc-sys/profiling"]
debug = ["jemalloc-sys/debug"]
bg_thread = ["jemalloc-sys/bg_thread"]
no_prefix = ["jemalloc-sys/no_prefix"]
1 change: 1 addition & 0 deletions jemalloc-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ default = ["bg_thread"]
profiling = []
debug = []
bg_thread = []
no_prefix = []
18 changes: 16 additions & 2 deletions jemalloc-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,29 @@ fn main() {
cmd.arg("--with-malloc-conf=background_thread:false");
}

cmd.arg("--with-jemalloc-prefix=_rjem_");
let mut use_prefix = !env::var_os("CARGO_FEATURE_NO_PREFIX").is_some();
if !use_prefix &&
(target.contains("android")
|| target.contains("dragonfly")
|| target.contains("musl")
|| target.contains("darwin"))
{
println!("ignoring no_prefix feature on unsupported platform");
use_prefix = true;
}

if use_prefix {
cmd.arg("--with-jemalloc-prefix=_rjem_");
println!("cargo:rustc-cfg=prefixed");
}

if env::var_os("CARGO_FEATURE_DEBUG").is_some() {
println!("CARGO_FEATURE_DEBUG set");
cmd.arg("--enable-debug");
}

if env::var_os("CARGO_FEATURE_PROFILING").is_some() {
println!("CARGO_FEATURE_PROFILING set set");
println!("CARGO_FEATURE_PROFILING set");
cmd.arg("--enable-prof");
}
cmd.arg(format!("--host={}", gnu_target(&target)));
Expand Down
36 changes: 18 additions & 18 deletions jemalloc-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,48 +18,48 @@ pub const MALLOCX_ZERO: c_int = 0x40;

extern "C" {
// Standard API
#[link_name = "_rjem_malloc"]
#[cfg_attr(prefixed, link_name = "_rjem_malloc")]
pub fn malloc(size: size_t) -> *mut c_void;
#[link_name = "_rjem_calloc"]
#[cfg_attr(prefixed, link_name = "_rjem_calloc")]
pub fn calloc(number: size_t, size: size_t) -> *mut c_void;
#[link_name = "_rjem_posix_memalign"]
#[cfg_attr(prefixed, link_name = "_rjem_posix_memalign")]
pub fn posix_memalign(ptr: *mut *mut c_void, alignment: size_t, size: size_t) -> c_int;
#[link_name = "_rjem_aligned_alloc"]
#[cfg_attr(prefixed, link_name = "_rjem_aligned_alloc")]
pub fn aligned_alloc(alignment: size_t, size: size_t) -> *mut c_void;
#[link_name = "_rjem_realloc"]
#[cfg_attr(prefixed, link_name = "_rjem_realloc")]
pub fn realloc(ptr: *mut c_void, size: size_t) -> *mut c_void;
#[link_name = "_rjem_free"]
#[cfg_attr(prefixed, link_name = "_rjem_free")]
pub fn free(ptr: *mut c_void);

// Non-standard API
#[link_name = "_rjem_mallocx"]
#[cfg_attr(prefixed, link_name = "_rjem_mallocx")]
pub fn mallocx(size: size_t, flags: c_int) -> *mut c_void;
#[link_name = "_rjem_rallocx"]
#[cfg_attr(prefixed, link_name = "_rjem_rallocx")]
pub fn rallocx(ptr: *mut c_void, size: size_t, flags: c_int) -> *mut c_void;
#[link_name = "_rjem_xallocx"]
#[cfg_attr(prefixed, link_name = "_rjem_xallocx")]
pub fn xallocx(ptr: *mut c_void, size: size_t, extra: size_t, flags: c_int) -> size_t;
#[link_name = "_rjem_sallocx"]
#[cfg_attr(prefixed, link_name = "_rjem_sallocx")]
pub fn sallocx(ptr: *const c_void, flags: c_int) -> size_t;
#[link_name = "_rjem_dallocx"]
#[cfg_attr(prefixed, link_name = "_rjem_dallocx")]
pub fn dallocx(ptr: *mut c_void, flags: c_int);
#[link_name = "_rjem_sdallocx"]
#[cfg_attr(prefixed, link_name = "_rjem_sdallocx")]
pub fn sdallocx(ptr: *mut c_void, size: size_t, flags: c_int);
#[link_name = "_rjem_nallocx"]
#[cfg_attr(prefixed, link_name = "_rjem_nallocx")]
pub fn nallocx(size: size_t, flags: c_int) -> size_t;
#[link_name = "_rjem_malloc_usable_size"]
#[cfg_attr(prefixed, link_name = "_rjem_malloc_usable_size")]
pub fn malloc_usable_size(ptr: *const c_void) -> size_t;

// mallctl
#[link_name = "_rjem_mallctl"]
#[cfg_attr(prefixed, link_name = "_rjem_mallctl")]
pub fn mallctl(name: *const c_char,
oldp: *mut c_void,
oldpenp: *mut size_t,
newp: *mut c_void,
newlen: size_t)
-> c_int;
#[link_name = "_rjem_mallctlnametomib"]
#[cfg_attr(prefixed, link_name = "_rjem_mallctlnametomib")]
pub fn mallctlnametomib(name: *const c_char, mibp: *mut size_t, miblenp: *mut size_t) -> c_int;
#[link_name = "_rjem_mallctlbymib"]
#[cfg_attr(prefixed, link_name = "_rjem_mallctlbymib")]
pub fn mallctlbymib(mib: *const size_t,
miblen: size_t,
oldp: *mut c_void,
Expand All @@ -69,7 +69,7 @@ extern "C" {
-> c_int;

// stats
#[link_name = "_rjem_malloc_stats_print"]
#[cfg_attr(prefixed, link_name = "_rjem_malloc_stats_print")]
pub fn malloc_stats_print(write_cb: extern "C" fn(*mut c_void, *const c_char),
cbopaque: *mut c_void,
opts: *const c_char);
Expand Down