Skip to content
This repository was archived by the owner on Jan 18, 2024. It is now read-only.

Commit c7fc98e

Browse files
committed
Stop relying on linking details of std’s default allocator
We’ve been bitten before by symbol names changing: servo/heapsize#46 and upstream is planning to stop using jemalloc by default: rust-lang/rust#33082 (comment) So use the (relatively) new `#[global_allocator]` attribute to explicitly select the system allocator on Windows and jemalloc (now in an external crate) on other platforms. This choice matches current defaults.
1 parent a17e57d commit c7fc98e

File tree

2 files changed

+0
-34
lines changed

2 files changed

+0
-34
lines changed

Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ publish = false
88
[lib]
99
path = "lib.rs"
1010

11-
[target.'cfg(windows)'.dependencies]
12-
kernel32-sys = "0.2.1"
13-
1411
[features]
1512
servo = ["js", "string_cache", "url", "webrender_api", "xml5ever"]
1613

lib.rs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ extern crate euclid;
4949
extern crate hashglobe;
5050
#[cfg(feature = "servo")]
5151
extern crate js;
52-
#[cfg(target_os = "windows")]
53-
extern crate kernel32;
5452
extern crate servo_arc;
5553
extern crate smallbitvec;
5654
extern crate smallvec;
@@ -63,8 +61,6 @@ extern crate webrender_api;
6361
#[cfg(feature = "servo")]
6462
extern crate xml5ever;
6563

66-
#[cfg(target_os = "windows")]
67-
use kernel32::{GetProcessHeap, HeapSize, HeapValidate};
6864
use std::hash::{BuildHasher, Hash};
6965
use std::mem::size_of;
7066
use std::ops::Range;
@@ -146,33 +142,6 @@ impl MallocSizeOfOps {
146142
}
147143
}
148144

149-
/// Get the size of a heap block.
150-
#[cfg(not(target_os = "windows"))]
151-
pub unsafe extern "C" fn malloc_size_of(ptr: *const c_void) -> usize {
152-
// The C prototype is `je_malloc_usable_size(JEMALLOC_USABLE_SIZE_CONST void *ptr)`. On some
153-
// platforms `JEMALLOC_USABLE_SIZE_CONST` is `const` and on some it is empty. But in practice
154-
// this function doesn't modify the contents of the block that `ptr` points to, so we use
155-
// `*const c_void` here.
156-
extern "C" {
157-
#[cfg_attr(any(prefixed_jemalloc, target_os = "macos", target_os = "ios", target_os = "android"),
158-
link_name = "je_malloc_usable_size")]
159-
fn malloc_usable_size(ptr: *const c_void) -> usize;
160-
}
161-
malloc_usable_size(ptr)
162-
}
163-
164-
/// Get the size of a heap block.
165-
#[cfg(target_os = "windows")]
166-
pub unsafe extern "C" fn malloc_size_of(mut ptr: *const c_void) -> usize {
167-
let heap = GetProcessHeap();
168-
169-
if HeapValidate(heap, 0, ptr) == 0 {
170-
ptr = *(ptr as *const *const c_void).offset(-1);
171-
}
172-
173-
HeapSize(heap, 0, ptr) as usize
174-
}
175-
176145
/// Trait for measuring the "deep" heap usage of a data structure. This is the
177146
/// most commonly-used of the traits.
178147
pub trait MallocSizeOf {

0 commit comments

Comments
 (0)