From 612dbb868d01b0f2a94492272f38d4bdb9ce77bc Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Thu, 13 Jul 2017 15:20:51 +0200 Subject: [PATCH 1/2] Update to rustc 1.20.0-nightly (f85579d4a 2017-07-12) --- components/gfx/lib.rs | 6 ++---- components/gfx/platform/freetype/font_context.rs | 15 ++++++++++----- rust-commit-hash | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/components/gfx/lib.rs b/components/gfx/lib.rs index b1b9614f787..86e275bd254 100644 --- a/components/gfx/lib.rs +++ b/components/gfx/lib.rs @@ -3,11 +3,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ // For SIMD -#![feature(cfg_target_feature)] -#![cfg_attr(any(target_os = "linux", target_os = "android"), feature(heap_api))] - -#![cfg_attr(any(target_os = "linux", target_os = "android"), feature(alloc))] +#![cfg_attr(any(target_os = "linux", target_os = "android"), feature(alloc, allocator_api))] #![feature(box_syntax)] +#![feature(cfg_target_feature)] #![feature(range_contains)] #![feature(unique)] diff --git a/components/gfx/platform/freetype/font_context.rs b/components/gfx/platform/freetype/font_context.rs index 86643ae348b..bca6de5484e 100644 --- a/components/gfx/platform/freetype/font_context.rs +++ b/components/gfx/platform/freetype/font_context.rs @@ -2,7 +2,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use alloc::heap; +use alloc::allocator::{Alloc, Layout}; +use alloc::heap::Heap; use freetype::freetype::FT_Add_Default_Modules; use freetype::freetype::FT_Done_Library; use freetype::freetype::FT_Library; @@ -26,7 +27,8 @@ const FT_ALIGNMENT: usize = 1; extern fn ft_alloc(mem: FT_Memory, req_size: c_long) -> *mut c_void { unsafe { - let ptr = heap::allocate(req_size as usize, FT_ALIGNMENT) as *mut c_void; + let layout = Layout::from_size_align(req_size as usize, FT_ALIGNMENT).unwrap(); + let ptr = Heap.alloc(layout).unwrap() as *mut c_void; let actual_size = heap_size_of(ptr as *const _); let user = (*mem).user as *mut User; @@ -43,7 +45,8 @@ extern fn ft_free(mem: FT_Memory, ptr: *mut c_void) { let user = (*mem).user as *mut User; (*user).size -= actual_size; - heap::deallocate(ptr as *mut u8, actual_size, FT_ALIGNMENT); + let layout = Layout::from_size_align(actual_size, FT_ALIGNMENT).unwrap(); + Heap.dealloc(ptr as *mut u8, layout); } } @@ -51,8 +54,10 @@ extern fn ft_realloc(mem: FT_Memory, _cur_size: c_long, new_req_size: c_long, old_ptr: *mut c_void) -> *mut c_void { unsafe { let old_actual_size = heap_size_of(old_ptr as *const _); - let new_ptr = heap::reallocate(old_ptr as *mut u8, old_actual_size, - new_req_size as usize, FT_ALIGNMENT) as *mut c_void; + let old_layout = Layout::from_size_align(old_actual_size, FT_ALIGNMENT).unwrap(); + let new_layout = Layout::from_size_align(new_req_size as usize, FT_ALIGNMENT).unwrap(); + let result = Heap.realloc(old_ptr as *mut u8, old_layout, new_layout); + let new_ptr = result.unwrap() as *mut c_void; let new_actual_size = heap_size_of(new_ptr as *const _); let user = (*mem).user as *mut User; diff --git a/rust-commit-hash b/rust-commit-hash index 3a022687970..f674e43611d 100644 --- a/rust-commit-hash +++ b/rust-commit-hash @@ -1 +1 @@ -3bfc18a9619a5151ff4f11618db9cd882996ba6f +f85579d4a2c342654f9b158fafd565eb159fdb59 From db1a3e54b0a016a78fbdb1d53f674684a31b3474 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Thu, 13 Jul 2017 15:26:40 +0200 Subject: [PATCH 2/2] Use heap API from std rather than the alloc crate --- components/gfx/lib.rs | 5 +---- components/gfx/platform/freetype/font_context.rs | 3 +-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/components/gfx/lib.rs b/components/gfx/lib.rs index 86e275bd254..5a5de4da89e 100644 --- a/components/gfx/lib.rs +++ b/components/gfx/lib.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ // For SIMD -#![cfg_attr(any(target_os = "linux", target_os = "android"), feature(alloc, allocator_api))] +#![cfg_attr(any(target_os = "linux", target_os = "android"), feature(allocator_api))] #![feature(box_syntax)] #![feature(cfg_target_feature)] #![feature(range_contains)] @@ -11,9 +11,6 @@ #![deny(unsafe_code)] -#[cfg(any(target_os = "linux", target_os = "android"))] -extern crate alloc; - extern crate app_units; #[macro_use] extern crate bitflags; diff --git a/components/gfx/platform/freetype/font_context.rs b/components/gfx/platform/freetype/font_context.rs index bca6de5484e..5e19e081663 100644 --- a/components/gfx/platform/freetype/font_context.rs +++ b/components/gfx/platform/freetype/font_context.rs @@ -2,8 +2,6 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use alloc::allocator::{Alloc, Layout}; -use alloc::heap::Heap; use freetype::freetype::FT_Add_Default_Modules; use freetype::freetype::FT_Done_Library; use freetype::freetype::FT_Library; @@ -11,6 +9,7 @@ use freetype::freetype::FT_Memory; use freetype::freetype::FT_MemoryRec_; use freetype::freetype::FT_New_Library; use heapsize::{HeapSizeOf, heap_size_of}; +use std::heap::{Heap, Alloc, Layout}; use std::os::raw::{c_long, c_void}; use std::ptr; use std::rc::Rc;