Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Fix linking on Rust versions that unprefix jemalloc #46

Merged
merged 4 commits into from
Feb 22, 2016
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
14 changes: 11 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
language: rust
rust: nightly
rust:
# Jemalloc prefixing change between these two versions
- nightly-2016-02-14
- nightly-2016-02-17

- nightly
- beta
- stable

notifications:
webhooks: http://build.servo.org:54856/travis

script:
- cargo test
- "[ $TRAVIS_RUST_VERSION = nightly ] || cargo test --features unstable"
- "[ $TRAVIS_RUST_VERSION = nightly ] || cargo test --manifest-path plugin/Cargo.toml"
- "[ $TRAVIS_RUST_VERSION != nightly ] || cargo test --features unstable"
- "[ $TRAVIS_RUST_VERSION != nightly ] || cargo test --manifest-path plugin/Cargo.toml"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't test unstable and plugin on nightly-* though, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but the point of having these two dated version is to test the build script’s version parsing and the linking to je_malloc_usable_size. These versions are not special as far as the unstable feature and the plugin are concerned.


4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ authors = [ "The Servo Project Developers" ]
description = "Infrastructure for measuring the total runtime size of an object on the heap"
license = "MPL-2.0"
repository = "https://github.com/servo/heapsize"
build = "build.rs"

[build-dependencies]
regex = "0.1"

[features]
unstable = []
26 changes: 26 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
extern crate regex;

use std::env::var;
use std::process::Command;
use std::str;

fn main() {
let version_line = Command::new(var("RUSTC").unwrap_or("rustc".into()))
.arg("--version")
.output()
.unwrap()
.stdout;
let captures = regex::Regex::new(r"rustc (\d+)\.(\d+)\.(\d+).+(\d{4}-\d{2}-\d{2})\)")
.unwrap()
.captures(str::from_utf8(&version_line).unwrap())
.unwrap();
let version = (
captures[1].parse::<u32>().unwrap(),
captures[2].parse::<u32>().unwrap(),
captures[3].parse::<u32>().unwrap(),
&captures[4],
);
if version < (1, 8, 0, "2016-02-14") {
println!("cargo:rustc-cfg=prefixed_jemalloc");
}
}
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use std::rc::Rc;

#[cfg(not(target_os = "windows"))]
extern {
#[cfg_attr(any(prefixed_jemalloc, target_os = "macos", target_os = "android"), link_name = "je_malloc_usable_size")]
// Get the size of a heap block.
//
// Ideally Rust would expose a function like this in std::rt::heap, which would avoid the
Expand All @@ -29,7 +30,7 @@ extern {
// platforms `JEMALLOC_USABLE_SIZE_CONST` is `const` and on some it is empty. But in practice
// this function doesn't modify the contents of the block that `ptr` points to, so we use
// `*const c_void` here.
fn je_malloc_usable_size(ptr: *const c_void) -> usize;
fn malloc_usable_size(ptr: *const c_void) -> usize;
}

/// A wrapper for je_malloc_usable_size that handles `EMPTY` and returns `usize`.
Expand All @@ -42,7 +43,7 @@ pub unsafe fn heap_size_of(ptr: *const c_void) -> usize {
if ptr == 0x01 as *const c_void {
0
} else {
je_malloc_usable_size(ptr)
malloc_usable_size(ptr)
}
}

Expand Down