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

Commit d17c7b4

Browse files
author
bors-servo
committed
Auto merge of #46 - servo:je2, r=SimonSapin
Fix linking on Rust versions that unprefix jemalloc Fixes #43, fixes #44. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/heapsize/46) <!-- Reviewable:end -->
2 parents 7913872 + e7a98e3 commit d17c7b4

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed

.travis.yml

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
language: rust
2-
rust: nightly
2+
rust:
3+
# Jemalloc prefixing change between these two versions
4+
- nightly-2016-02-14
5+
- nightly-2016-02-17
6+
7+
- nightly
8+
- beta
9+
- stable
10+
311
notifications:
412
webhooks: http://build.servo.org:54856/travis
513

Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ authors = [ "The Servo Project Developers" ]
55
description = "Infrastructure for measuring the total runtime size of an object on the heap"
66
license = "MPL-2.0"
77
repository = "https://github.com/servo/heapsize"
8+
build = "build.rs"
9+
10+
[build-dependencies]
11+
regex = "0.1"
812

913
[features]
1014
unstable = []

build.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
extern crate regex;
2+
3+
use std::env::var;
4+
use std::process::Command;
5+
use std::str;
6+
7+
fn main() {
8+
let version_line = Command::new(var("RUSTC").unwrap_or("rustc".into()))
9+
.arg("--version")
10+
.output()
11+
.unwrap()
12+
.stdout;
13+
let captures = regex::Regex::new(r"rustc (\d+)\.(\d+)\.(\d+).+(\d{4}-\d{2}-\d{2})\)")
14+
.unwrap()
15+
.captures(str::from_utf8(&version_line).unwrap())
16+
.unwrap();
17+
let version = (
18+
captures[1].parse::<u32>().unwrap(),
19+
captures[2].parse::<u32>().unwrap(),
20+
captures[3].parse::<u32>().unwrap(),
21+
&captures[4],
22+
);
23+
if version < (1, 8, 0, "2016-02-14") {
24+
println!("cargo:rustc-cfg=prefixed_jemalloc");
25+
}
26+
}

src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use std::rc::Rc;
2020

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

3536
/// A wrapper for je_malloc_usable_size that handles `EMPTY` and returns `usize`.
@@ -42,7 +43,7 @@ pub unsafe fn heap_size_of(ptr: *const c_void) -> usize {
4243
if ptr == 0x01 as *const c_void {
4344
0
4445
} else {
45-
je_malloc_usable_size(ptr)
46+
malloc_usable_size(ptr)
4647
}
4748
}
4849

0 commit comments

Comments
 (0)