Bug 1500233 - Re-vendor rust dependencies. r=kats
authorWR Updater Bot <graphics-team@mozilla.staktrace.com>
Fri, 19 Oct 2018 15:57:43 +0000
changeset 490522 9788a3095675249e279b46b1dfee0246aec4fcc3
parent 490521 3fd071cc143477b440eec25e856613ae906e3c6b
child 490523 59d216896c04522d674c86e16ce59658973dfab4
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewerskats
bugs1500233
milestone64.0a1
Bug 1500233 - Re-vendor rust dependencies. r=kats Depends on D9268 Differential Revision: https://phabricator.services.mozilla.com/D9269
Cargo.lock
third_party/rust/dwrote/.cargo-checksum.json
third_party/rust/dwrote/Cargo.toml
third_party/rust/dwrote/src/font_file.rs
third_party/rust/dwrote/src/font_file_loader_impl.rs
third_party/rust/dwrote/src/test.rs
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -762,17 +762,17 @@ dependencies = [
 name = "dump_syms_rust_demangle"
 version = "0.1.0"
 dependencies = [
  "rustc-demangle 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "dwrote"
-version = "0.5.1"
+version = "0.5.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde_derive 1.0.66 (git+https://github.com/servo/serde?branch=deserialize_from_enums8)",
  "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
@@ -2927,17 +2927,17 @@ dependencies = [
  "app_units 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "bincode 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
  "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "core-foundation 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "core-graphics 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "core-text 13.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "dwrote 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "dwrote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "euclid 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "freetype 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "gleam 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
  "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
  "plane-split 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2955,33 +2955,33 @@ name = "webrender_api"
 version = "0.57.2"
 dependencies = [
  "app_units 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "bincode 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
  "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "core-foundation 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "core-graphics 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "dwrote 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "dwrote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "euclid 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde_bytes 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde_derive 1.0.66 (git+https://github.com/servo/serde?branch=deserialize_from_enums8)",
  "time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "webrender_bindings"
 version = "0.1.0"
 dependencies = [
  "app_units 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "bincode 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "core-foundation 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "core-graphics 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "dwrote 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "dwrote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "euclid 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "foreign-types 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "gleam 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
  "nsstring 0.1.0",
  "rayon 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "thread_profiler 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -3180,17 +3180,17 @@ dependencies = [
 "checksum darling_macro 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "eb69a38fdeaeaf3db712e1df170de67ee9dfc24fb88ca3e9d21e703ec25a4d8e"
 "checksum devd-rs 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e7c9ac481c38baf400d3b732e4a06850dfaa491d1b6379a249d9d40d14c2434c"
 "checksum diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "3c2b69f912779fbb121ceb775d74d51e915af17aaebc38d28a592843a2dd0a3a"
 "checksum digest 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "03b072242a8cbaf9c145665af9d250c59af3b958f83ed6824e13533cf76d5b90"
 "checksum dirs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "88972de891f6118092b643d85a0b28e0678e0f948d7f879aa32f2d5aafe97d2a"
 "checksum docopt 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d8acd393692c503b168471874953a2531df0e9ab77d0b6bbc582395743300a4a"
 "checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab"
 "checksum dtoa-short 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "068d4026697c1a18f0b0bb8cfcad1b0c151b90d8edb9bf4c235ad68128920d1d"
-"checksum dwrote 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "30a998e9ff70cd208ccdc4f864e998688bf61d7b897dccec8e17a884d17358bf"
+"checksum dwrote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f5472f94ba0d9e65b4fefb8c1661ad5b253455eec42cb0702cf0189526321034"
 "checksum either 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18785c1ba806c258137c937e44ada9ee7e69a37e3c72077542cd2f069d78562a"
 "checksum ena 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "88dc8393b3c7352f94092497f6b52019643e493b6b890eb417cdb7c46117e621"
 "checksum encoding_c 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "769ecb8b33323998e482b218c0d13cd64c267609023b4b7ec3ee740714c318ee"
 "checksum encoding_rs 0.8.9 (registry+https://github.com/rust-lang/crates.io-index)" = "f1a79fa56c329a5b087de13748054fb3b974c4a672c12c71f0b66e35c5addec5"
 "checksum env_logger 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0561146661ae44c579e993456bc76d11ce1e0c7d745e57b2fa7146b6e49fa2ad"
 "checksum error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff511d5dc435d703f4971bc399647c9bc38e20cb41452e3b9feb4765419ed3f3"
 "checksum euclid 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)" = "70a2ebdf55fb9d6329046e026329a55ef8fbaae5ea833f56e170beb3125a8a5f"
 "checksum failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7efb22686e4a466b1ec1a15c2898f91fa9cb340452496dca654032de20ff95b9"
--- a/third_party/rust/dwrote/.cargo-checksum.json
+++ b/third_party/rust/dwrote/.cargo-checksum.json
@@ -1,1 +1,1 @@
-{"files":{"Cargo.toml":"76ab5c65a983292b55154defbe54d6d18661e4f0addc237873b8333a6f5f3c05","README.md":"d69d75705e2582721cbfb2d3b4b2af052c71679057a0b2ac53a22c03f1755bba","appveyor.yml":"7c1e0718a363d3567cecd1ef772d4e17c2a17f18906dc464dce8a2411adff6be","src/bitmap_render_target.rs":"fc13525d7459515e4bf9769c8a8961b046b4d1ba4042591aaf0925dd5edebf64","src/com_helpers.rs":"02535b27bfb0cee6e4d8db3abd22f2d2e8137a4ce3ab3504beaf4fa3ca9370df","src/comptr.rs":"84794cf04b772398e75fdb5d55fd8fa015abf26c61b1f9c761a597133682b2e1","src/font.rs":"a79b944f2f5125bbef9e24921355dc6996f073e3742ddd410b8efaa0df3a3ee2","src/font_collection.rs":"df3767b305e9981fbe9398d9982123c668fb2a38cd92f5bdbaf574353005378d","src/font_collection_impl.rs":"a585a6ce62083b3346d67619ea47fec46423a7fb04cc11372828389ab26c5a05","src/font_face.rs":"55d3ddef22be160b9b9a0ffd677993290b0df0f847e7dbcce4014a222490205e","src/font_family.rs":"4e948542dba0c158187d0cb2d72343c443380480cacd12894070d0ef1351dd0a","src/font_file.rs":"913c5dd428028fb3c870b70f4ef2ac2ac357c7ae02cc2c7fb075eb675dcc97b4","src/font_file_loader_impl.rs":"42d23dd036bd2ec7c76de6fffd34a675949f5f881fba553f53351f2ac96da003","src/gdi_interop.rs":"04dbef7c34bb0fe62c4f2c2ceca62ca94c75a964d744b29b3322a6c3bbb4eabd","src/geometry_sink_impl.rs":"d615de212e55b8b8d95c8d605fc5d78044b4ae4dfd846f706911a16cc3afc049","src/glyph_run_analysis.rs":"3b2a351422098a19e8f490421e5b19227fc14a41a0df97d488c536fd1d4b552c","src/helpers.rs":"2f3c57642b24b80c45bbd012e7d6ca1fc524b1b42a8be004cb9b52ea13f4166d","src/lib.rs":"b634e62dd088d804429f451ba9f14aaab0b6a1179042d70fed825f3253ffacfb","src/outline_builder.rs":"0f5c842b2ffe75e21d68f93be6a3834c120bd43303d4e490fdfee9f4f964cdc4","src/rendering_params.rs":"850a51143790f5d29422dc49cbceddc232d814ecd0e6933434ad644e6eec539b","src/test.rs":"120f63cd638b2195caeec8c74a06985103abc6e720275a7f80ffdf130474a8a0","src/types.rs":"587aea2e50720e85b28efe237c8ea10bc45b52049ca724447a0fc9b0e6672b11"},"package":"30a998e9ff70cd208ccdc4f864e998688bf61d7b897dccec8e17a884d17358bf"}
\ No newline at end of file
+{"files":{"Cargo.toml":"0fde468a4a83f83c7dddf49edc2e6f3730700b268c55b6a721a4938cd2b82478","README.md":"d69d75705e2582721cbfb2d3b4b2af052c71679057a0b2ac53a22c03f1755bba","appveyor.yml":"7c1e0718a363d3567cecd1ef772d4e17c2a17f18906dc464dce8a2411adff6be","src/bitmap_render_target.rs":"fc13525d7459515e4bf9769c8a8961b046b4d1ba4042591aaf0925dd5edebf64","src/com_helpers.rs":"02535b27bfb0cee6e4d8db3abd22f2d2e8137a4ce3ab3504beaf4fa3ca9370df","src/comptr.rs":"84794cf04b772398e75fdb5d55fd8fa015abf26c61b1f9c761a597133682b2e1","src/font.rs":"a79b944f2f5125bbef9e24921355dc6996f073e3742ddd410b8efaa0df3a3ee2","src/font_collection.rs":"df3767b305e9981fbe9398d9982123c668fb2a38cd92f5bdbaf574353005378d","src/font_collection_impl.rs":"a585a6ce62083b3346d67619ea47fec46423a7fb04cc11372828389ab26c5a05","src/font_face.rs":"55d3ddef22be160b9b9a0ffd677993290b0df0f847e7dbcce4014a222490205e","src/font_family.rs":"4e948542dba0c158187d0cb2d72343c443380480cacd12894070d0ef1351dd0a","src/font_file.rs":"1c012d0b436c2831d31cd76f77a59dab1edc5d63881c495eb486cd4febe23031","src/font_file_loader_impl.rs":"71c4153971dbfc21d42ba2e33f159fcb145f7dcfbd17e856e9fd75f0571d41e0","src/gdi_interop.rs":"04dbef7c34bb0fe62c4f2c2ceca62ca94c75a964d744b29b3322a6c3bbb4eabd","src/geometry_sink_impl.rs":"d615de212e55b8b8d95c8d605fc5d78044b4ae4dfd846f706911a16cc3afc049","src/glyph_run_analysis.rs":"3b2a351422098a19e8f490421e5b19227fc14a41a0df97d488c536fd1d4b552c","src/helpers.rs":"2f3c57642b24b80c45bbd012e7d6ca1fc524b1b42a8be004cb9b52ea13f4166d","src/lib.rs":"b634e62dd088d804429f451ba9f14aaab0b6a1179042d70fed825f3253ffacfb","src/outline_builder.rs":"0f5c842b2ffe75e21d68f93be6a3834c120bd43303d4e490fdfee9f4f964cdc4","src/rendering_params.rs":"850a51143790f5d29422dc49cbceddc232d814ecd0e6933434ad644e6eec539b","src/test.rs":"158aa4d03655f4efef00327fe72a03dfb504659176aa0eef976ca2485b2c1d74","src/types.rs":"587aea2e50720e85b28efe237c8ea10bc45b52049ca724447a0fc9b0e6672b11"},"package":"f5472f94ba0d9e65b4fefb8c1661ad5b253455eec42cb0702cf0189526321034"}
\ No newline at end of file
--- a/third_party/rust/dwrote/Cargo.toml
+++ b/third_party/rust/dwrote/Cargo.toml
@@ -7,17 +7,17 @@
 #
 # If you believe there's an error in this file please file an
 # issue against the rust-lang/cargo repository. If you're
 # editing this file be aware that the upstream Cargo.toml
 # will likely look very different (and much more reasonable)
 
 [package]
 name = "dwrote"
-version = "0.5.1"
+version = "0.5.2"
 authors = ["Vladimir Vukicevic <vladimir@pobox.com>"]
 description = "Lightweight binding to DirectWrite."
 license = "MPL-2.0"
 repository = "https://github.com/servo/dwrote-rs"
 
 [lib]
 name = "dwrote"
 [dependencies.lazy_static]
--- a/third_party/rust/dwrote/src/font_file.rs
+++ b/third_party/rust/dwrote/src/font_file.rs
@@ -6,32 +6,34 @@ use std::slice;
 use std::ptr;
 use std::cell::UnsafeCell;
 use std::path::PathBuf;
 use std::ffi::OsString;
 use std::fs::File;
 use std::os::windows::ffi::{OsStrExt, OsStringExt};
 use std::os::windows::io::IntoRawHandle;
 use std::path::Path;
+use std::sync::Arc;
 
 use comptr::ComPtr;
 
 use winapi::Interface;
 use winapi::ctypes::c_void;
 use winapi::um::dwrite::{IDWriteFontFace, IDWriteFontFile, IDWriteFontFileStream};
 use winapi::um::dwrite::{IDWriteFontFileLoader, IDWriteLocalFontFileLoader};
 use winapi::um::dwrite::{DWRITE_FONT_SIMULATIONS, DWRITE_FONT_FACE_TYPE_UNKNOWN};
 use winapi::um::dwrite::{DWRITE_FONT_FACE_TYPE, DWRITE_FONT_FILE_TYPE_UNKNOWN};
 
 use font_file_loader_impl::DataFontHelper;
 use font_face::FontFace;
 use super::DWriteFactory;
 
 pub struct FontFile {
     native: UnsafeCell<ComPtr<IDWriteFontFile>>,
+    stream: UnsafeCell<Option<ComPtr<IDWriteFontFileStream>>>,
     data_key: usize,
     face_type: DWRITE_FONT_FACE_TYPE,
 }
 
 impl FontFile {
     pub fn new_from_path<P>(path: P) -> Option<FontFile> where P: AsRef<Path> {
         unsafe {
             let mut path: Vec<u16> = path.as_ref().as_os_str().encode_wide().collect();
@@ -42,44 +44,46 @@ impl FontFile {
                                                                 ptr::null(),
                                                                 font_file.getter_addrefs());
             if hr != 0 || font_file.is_null() {
                 return None
             }
 
             Some(FontFile {
                 native: UnsafeCell::new(font_file),
+                stream: UnsafeCell::new(None),
                 data_key: 0,
                 face_type: DWRITE_FONT_FACE_TYPE_UNKNOWN,
             })
         }
     }
 
-    pub fn new_from_data(data: &[u8]) -> Option<FontFile> {
-        let (font_file, key) = DataFontHelper::register_font_data(data);
+    pub fn new_from_data(data: Arc<Vec<u8>>) -> Option<FontFile> {
+        let (font_file, font_file_stream, key) = DataFontHelper::register_font_data(data);
 
         let mut ff = FontFile {
             native: UnsafeCell::new(font_file),
+            stream: UnsafeCell::new(Some(font_file_stream)),
             data_key: key,
             face_type: DWRITE_FONT_FACE_TYPE_UNKNOWN,
         };
 
         if ff.analyze() == 0 {
-            DataFontHelper::unregister_font_data(key);
-            return None;
+            None
+        } else {
+            Some(ff)
         }
-
-        Some(ff)
     }
 
-    pub fn analyze_data(data: &[u8]) -> u32 {
-        let (font_file, key) = DataFontHelper::register_font_data(data);
+    pub fn analyze_data(data: Arc<Vec<u8>>) -> u32 {
+        let (font_file, font_file_stream, key) = DataFontHelper::register_font_data(data);
 
         let mut ff = FontFile {
             native: UnsafeCell::new(font_file),
+            stream: UnsafeCell::new(Some(font_file_stream)),
             data_key: key,
             face_type: DWRITE_FONT_FACE_TYPE_UNKNOWN,
         };
 
         ff.analyze()
     }
 
     fn analyze(&mut self) -> u32 {
@@ -99,16 +103,17 @@ impl FontFile {
         }
         self.face_type = face_type;
         num_faces as u32
     }
 
     pub fn take(native: ComPtr<IDWriteFontFile>) -> FontFile {
         let mut ff = FontFile {
             native: UnsafeCell::new(native),
+            stream: UnsafeCell::new(None),
             data_key: 0,
             face_type: DWRITE_FONT_FACE_TYPE_UNKNOWN,
         };
         ff.analyze();
         ff
     }
 
     pub fn data_key(&self) -> Option<usize> {
@@ -211,14 +216,15 @@ impl FontFile {
     }
 }
 
 impl Clone for FontFile {
     fn clone(&self) -> FontFile {
         unsafe {
             FontFile {
                 native: UnsafeCell::new((*self.native.get()).clone()),
+                stream: UnsafeCell::new((*self.stream.get()).clone()),
                 data_key: self.data_key,
                 face_type: self.face_type,
             }
         }
     }
 }
--- a/third_party/rust/dwrote/src/font_file_loader_impl.rs
+++ b/third_party/rust/dwrote/src/font_file_loader_impl.rs
@@ -1,14 +1,14 @@
 #![allow(non_snake_case, non_upper_case_globals)]
 
 use std::{mem, ptr};
 use std::collections::HashMap;
 use std::sync::atomic::AtomicUsize;
-use std::sync::{Mutex, atomic};
+use std::sync::{Arc, Mutex, atomic};
 use std::marker::Send;
 use winapi::ctypes::c_void;
 use winapi::shared::basetsd::{UINT32, UINT64};
 use winapi::shared::guiddef::REFIID;
 use winapi::shared::minwindef::ULONG;
 use winapi::shared::winerror::{E_FAIL, E_INVALIDARG, E_NOTIMPL, S_OK};
 use winapi::um::dwrite::IDWriteFontFile;
 use winapi::um::dwrite::{IDWriteFontFileLoader, IDWriteFontFileLoaderVtbl};
@@ -34,23 +34,23 @@ const FontFileLoaderVtbl: &'static IDWri
             fontFileReferenceKeySize: UINT32,
             fontFileStream: *mut *mut IDWriteFontFileStream) -> HRESULT
         {
             if fontFileReferenceKey.is_null() || fontFileStream.is_null() {
                 return E_INVALIDARG
             }
             assert!(fontFileReferenceKeySize == mem::size_of::<usize>() as UINT32);
             let key = *(fontFileReferenceKey as *const usize);
-            let stream = match FONT_FILE_STREAM_MAP.lock().unwrap().get_mut(&key) {
+            let stream = match FONT_FILE_STREAM_MAP.lock().unwrap().get(&key) {
                 None => {
                     *fontFileStream = ptr::null_mut();
                     return E_FAIL
                 }
-                Some(file_stream) => {
-                    file_stream.as_ptr()
+                Some(&FontFileStreamPtr(file_stream)) => {
+                    file_stream
                 }
             };
 
             // This is an addref getter, so make sure to do that!
             (*stream).AddRef();
 
             *fontFileStream = stream;
             S_OK
@@ -75,17 +75,18 @@ impl FontFileLoader {
     }
 }
 
 unsafe impl Send for FontFileLoader {}
 unsafe impl Sync for FontFileLoader {}
 
 struct FontFileStream {
     refcount: atomic::AtomicUsize,
-    data: Vec<u8>,
+    key: usize,
+    data: Arc<Vec<u8>>,
 }
 
 const FontFileStreamVtbl: &'static IDWriteFontFileStreamVtbl = &IDWriteFontFileStreamVtbl {
     parent: implement_iunknown!(IDWriteFontFileStream, UuidOfIDWriteFontFileStream, FontFileStream),
     ReadFileFragment: {
         unsafe extern "system" fn ReadFileFragment(
             This: *mut IDWriteFontFileStream,
             fragmentStart: *mut *const c_void,
@@ -94,17 +95,17 @@ const FontFileStreamVtbl: &'static IDWri
             fragmentContext: *mut *mut c_void) -> HRESULT
         {
             let this = FontFileStream::from_interface(This);
             *fragmentContext = ptr::null_mut();
             if (fileOffset + fragmentSize) as usize > this.data.len() {
                 return E_INVALIDARG
             }
             let index = fileOffset as usize;
-            *fragmentStart = this.data[index..].as_mut_ptr() as *const c_void;
+            *fragmentStart = this.data[index..].as_ptr() as *const c_void;
             S_OK
         }
         ReadFileFragment
     },
     ReleaseFileFragment: {
         unsafe extern "system" fn ReleaseFileFragment(
             _This: *mut IDWriteFontFileStream,
             _fragmentContext: *mut c_void)
@@ -130,38 +131,49 @@ const FontFileStreamVtbl: &'static IDWri
         {
             E_NOTIMPL
         }
         GetLastWriteTime
     },
 };
 
 impl FontFileStream {
-    pub fn new(data: &[u8]) -> FontFileStream {
+    pub fn new(key: usize, data: Arc<Vec<u8>>) -> FontFileStream {
         FontFileStream {
             refcount: AtomicUsize::new(1),
-            data: data.to_vec(),
+            key,
+            data,
         }
     }
 }
 
+impl Drop for FontFileStream {
+    fn drop(&mut self) {
+        DataFontHelper::unregister_font_data(self.key);
+    }
+}
+
 impl Com<IDWriteFontFileStream> for FontFileStream {
     type Vtbl = IDWriteFontFileStreamVtbl;
     fn vtbl() -> &'static IDWriteFontFileStreamVtbl { FontFileStreamVtbl }
 }
 
 impl Com<IUnknown> for FontFileStream {
     type Vtbl = IUnknownVtbl;
     fn vtbl() -> &'static IUnknownVtbl { &FontFileStreamVtbl.parent }
 }
 
+struct FontFileStreamPtr(*mut IDWriteFontFileStream);
+
+unsafe impl Send for FontFileStreamPtr {}
+
 static mut FONT_FILE_KEY: atomic::AtomicUsize = atomic::ATOMIC_USIZE_INIT;
 
 lazy_static! {
-    static ref FONT_FILE_STREAM_MAP: Mutex<HashMap<usize, ComPtr<IDWriteFontFileStream>>> = {
+    static ref FONT_FILE_STREAM_MAP: Mutex<HashMap<usize, FontFileStreamPtr>> = {
         Mutex::new(HashMap::new())
     };
 
     static ref FONT_FILE_LOADER: Mutex<ComPtr<IDWriteFontFileLoader>> = {
         let ffl_native = FontFileLoader::new();
         let ffl = ComPtr::<IDWriteFontFileLoader>::from_ptr(ffl_native.into_interface());
         unsafe {
             let hr = (*DWriteFactory()).RegisterFontFileLoader(ffl.as_ptr());
@@ -169,42 +181,43 @@ lazy_static! {
         }
         Mutex::new(ffl)
     };
 }
 
 pub struct DataFontHelper;
 
 impl DataFontHelper {
-    pub fn register_font_data(font_data: &[u8]) -> (ComPtr<IDWriteFontFile>, usize) {
+    pub fn register_font_data(font_data: Arc<Vec<u8>>)
+        -> (ComPtr<IDWriteFontFile>, ComPtr<IDWriteFontFileStream>, usize) {
         unsafe {
             let key = FONT_FILE_KEY.fetch_add(1, atomic::Ordering::Relaxed);
-            let font_file_stream_native = FontFileStream::new(font_data);
+            let font_file_stream_native = FontFileStream::new(key, font_data);
             let font_file_stream: ComPtr<IDWriteFontFileStream> =
-                ComPtr::from_ptr(font_file_stream_native.into_interface());
+                ComPtr::already_addrefed(font_file_stream_native.into_interface());
 
             {
                 let mut map = FONT_FILE_STREAM_MAP.lock().unwrap();
-                map.insert(key, font_file_stream);
+                map.insert(key, FontFileStreamPtr(font_file_stream.as_ptr()));
             }
 
             let mut font_file: ComPtr<IDWriteFontFile> = ComPtr::new();
             {
                 let loader = FONT_FILE_LOADER.lock().unwrap();
                 let hr = (*DWriteFactory()).CreateCustomFontFileReference(
                     mem::transmute(&key),
                     mem::size_of::<usize>() as UINT32,
                     loader.as_ptr(),
                     font_file.getter_addrefs());
                 assert!(hr == S_OK);
             }
 
-            (font_file, key)
+            (font_file, font_file_stream, key)
         }
     }
 
-    pub fn unregister_font_data(key: usize) {
+    fn unregister_font_data(key: usize) {
         let mut map = FONT_FILE_STREAM_MAP.lock().unwrap();
         if map.remove(&key).is_none() {
             panic!("unregister_font_data: trying to unregister key that is no longer registered");
         }
     }
 }
--- a/third_party/rust/dwrote/src/test.rs
+++ b/third_party/rust/dwrote/src/test.rs
@@ -1,13 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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 super::*;
+use std::sync::Arc;
 
 #[test]
 fn test_system_family_iter() {
     let system_fc = FontCollection::system();
     let count = system_fc.families_iter().count();
     assert!(count > 0);
     assert!(system_fc.families_iter().find(|f| f.name() == "Arial").is_some());
 }
@@ -74,17 +75,17 @@ fn test_create_font_file_from_bytes() {
     let face = arial_font.create_font_face();
     let files = face.get_files();
     assert!(files.len() > 0);
 
     let bytes = files[0].get_font_file_bytes();
     assert!(bytes.len() > 0);
 
     // now go back
-    let new_font = FontFile::new_from_data(&bytes);
+    let new_font = FontFile::new_from_data(Arc::new(bytes));
     assert!(new_font.is_some());
 
     let new_font = new_font.unwrap();
 }
 
 #[test]
 fn test_glyph_image() {
     let system_fc = FontCollection::system();