From c7fc98e5bf3a96ba6e25790041f6c83a91cdf128 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Wed, 18 Oct 2017 13:38:07 +0200 Subject: [PATCH] =?UTF-8?q?Stop=20relying=20on=20linking=20details=20of=20?= =?UTF-8?q?std=E2=80=99s=20default=20allocator?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We’ve been bitten before by symbol names changing: https://github.com/servo/heapsize/pull/46 and upstream is planning to stop using jemalloc by default: https://github.com/rust-lang/rust/issues/33082#issuecomment-309781465 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. --- Cargo.toml | 3 --- lib.rs | 31 ------------------------------- 2 files changed, 34 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index afc92cf..05a8f4f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,9 +8,6 @@ publish = false [lib] path = "lib.rs" -[target.'cfg(windows)'.dependencies] -kernel32-sys = "0.2.1" - [features] servo = ["js", "string_cache", "url", "webrender_api", "xml5ever"] diff --git a/lib.rs b/lib.rs index 48350e6..399f118 100644 --- a/lib.rs +++ b/lib.rs @@ -49,8 +49,6 @@ extern crate euclid; extern crate hashglobe; #[cfg(feature = "servo")] extern crate js; -#[cfg(target_os = "windows")] -extern crate kernel32; extern crate servo_arc; extern crate smallbitvec; extern crate smallvec; @@ -63,8 +61,6 @@ extern crate webrender_api; #[cfg(feature = "servo")] extern crate xml5ever; -#[cfg(target_os = "windows")] -use kernel32::{GetProcessHeap, HeapSize, HeapValidate}; use std::hash::{BuildHasher, Hash}; use std::mem::size_of; use std::ops::Range; @@ -146,33 +142,6 @@ impl MallocSizeOfOps { } } -/// Get the size of a heap block. -#[cfg(not(target_os = "windows"))] -pub unsafe extern "C" fn malloc_size_of(ptr: *const c_void) -> usize { - // The C prototype is `je_malloc_usable_size(JEMALLOC_USABLE_SIZE_CONST void *ptr)`. On some - // 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. - extern "C" { - #[cfg_attr(any(prefixed_jemalloc, target_os = "macos", target_os = "ios", target_os = "android"), - link_name = "je_malloc_usable_size")] - fn malloc_usable_size(ptr: *const c_void) -> usize; - } - malloc_usable_size(ptr) -} - -/// Get the size of a heap block. -#[cfg(target_os = "windows")] -pub unsafe extern "C" fn malloc_size_of(mut ptr: *const c_void) -> usize { - let heap = GetProcessHeap(); - - if HeapValidate(heap, 0, ptr) == 0 { - ptr = *(ptr as *const *const c_void).offset(-1); - } - - HeapSize(heap, 0, ptr) as usize -} - /// Trait for measuring the "deep" heap usage of a data structure. This is the /// most commonly-used of the traits. pub trait MallocSizeOf {