mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Auto merge of #21046 - servo:stable-alloc, r=nox
Upgrade to rustc 1.28.0-nightly (b68432d56 2018-06-12) <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/21046) <!-- Reviewable:end -->
This commit is contained in:
commit
98ac66d015
5 changed files with 21 additions and 49 deletions
|
@ -8,14 +8,8 @@ publish = false
|
|||
[lib]
|
||||
path = "lib.rs"
|
||||
|
||||
[features]
|
||||
unstable = ["kernel32-sys", "jemalloc-sys"]
|
||||
|
||||
[dependencies]
|
||||
libc = "0.2" # Only used when 'unstable' is disabled, but looks like Cargo cannot express that.
|
||||
|
||||
[target.'cfg(not(windows))'.dependencies]
|
||||
jemalloc-sys = { version = "0.1.4", optional = true }
|
||||
jemalloc-sys = { version = "0.1.4" }
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
kernel32-sys = { version = "0.2.1", optional = true }
|
||||
kernel32-sys = { version = "0.2.1" }
|
||||
|
|
|
@ -4,20 +4,17 @@
|
|||
|
||||
//! Selecting the default global allocator for Servo
|
||||
|
||||
#![cfg_attr(feature = "unstable", feature(global_allocator, allocator_api, alloc_system))]
|
||||
|
||||
#[cfg(feature = "unstable")]
|
||||
#[global_allocator]
|
||||
static ALLOC: Allocator = Allocator;
|
||||
|
||||
pub use platform::*;
|
||||
|
||||
|
||||
#[cfg(all(feature = "unstable", not(windows)))]
|
||||
#[cfg(not(windows))]
|
||||
mod platform {
|
||||
extern crate jemalloc_sys as ffi;
|
||||
|
||||
use std::alloc::{GlobalAlloc, Layout, Opaque};
|
||||
use std::alloc::{GlobalAlloc, Layout};
|
||||
use std::os::raw::{c_int, c_void};
|
||||
|
||||
/// Get the size of a heap block.
|
||||
|
@ -65,44 +62,43 @@ mod platform {
|
|||
|
||||
unsafe impl GlobalAlloc for Allocator {
|
||||
#[inline]
|
||||
unsafe fn alloc(&self, layout: Layout) -> *mut Opaque {
|
||||
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
|
||||
let flags = layout_to_flags(layout.align(), layout.size());
|
||||
ffi::mallocx(layout.size(), flags) as *mut Opaque
|
||||
ffi::mallocx(layout.size(), flags) as *mut u8
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut Opaque {
|
||||
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
|
||||
if layout.align() <= MIN_ALIGN && layout.align() <= layout.size() {
|
||||
ffi::calloc(1, layout.size()) as *mut Opaque
|
||||
ffi::calloc(1, layout.size()) as *mut u8
|
||||
} else {
|
||||
let flags = layout_to_flags(layout.align(), layout.size()) | ffi::MALLOCX_ZERO;
|
||||
ffi::mallocx(layout.size(), flags) as *mut Opaque
|
||||
ffi::mallocx(layout.size(), flags) as *mut u8
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn dealloc(&self, ptr: *mut Opaque, layout: Layout) {
|
||||
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
|
||||
let flags = layout_to_flags(layout.align(), layout.size());
|
||||
ffi::sdallocx(ptr as *mut _, layout.size(), flags)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn realloc(&self,
|
||||
ptr: *mut Opaque,
|
||||
ptr: *mut u8,
|
||||
layout: Layout,
|
||||
new_size: usize) -> *mut Opaque {
|
||||
new_size: usize) -> *mut u8 {
|
||||
let flags = layout_to_flags(layout.align(), new_size);
|
||||
ffi::rallocx(ptr as *mut _, new_size, flags) as *mut Opaque
|
||||
ffi::rallocx(ptr as *mut _, new_size, flags) as *mut u8
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "unstable", windows))]
|
||||
#[cfg(windows)]
|
||||
mod platform {
|
||||
extern crate alloc_system;
|
||||
extern crate kernel32;
|
||||
|
||||
pub use self::alloc_system::System as Allocator;
|
||||
pub use std::alloc::System as Allocator;
|
||||
use self::kernel32::{GetProcessHeap, HeapSize, HeapValidate};
|
||||
use std::os::raw::c_void;
|
||||
|
||||
|
@ -117,20 +113,3 @@ mod platform {
|
|||
HeapSize(heap, 0, ptr) as usize
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "unstable"))]
|
||||
mod platform {
|
||||
use std::os::raw::c_void;
|
||||
|
||||
/// Without `#[global_allocator]` we cannot be certain of what allocator is used
|
||||
/// or how it is linked. We therefore disable memory reporting. (Return zero.)
|
||||
pub unsafe extern "C" fn usable_size(_ptr: *const c_void) -> usize {
|
||||
0
|
||||
}
|
||||
|
||||
/// Memory allocation APIs compatible with libc
|
||||
pub mod libc_compat {
|
||||
extern crate libc;
|
||||
pub use self::libc::{malloc, realloc, free};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ path = "lib.rs"
|
|||
|
||||
[features]
|
||||
debugmozjs = ['mozjs/debugmozjs']
|
||||
unstable = ["servo_allocator/unstable"]
|
||||
unstable = []
|
||||
unrooted_must_root_lint = ["script_plugins/unrooted_must_root_lint"]
|
||||
default = ["unrooted_must_root_lint"]
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue