diff options
author | Simon Sapin <simon.sapin@exyr.org> | 2018-01-22 13:05:38 +0100 |
---|---|---|
committer | Simon Sapin <simon.sapin@exyr.org> | 2018-01-22 17:41:25 +0100 |
commit | 10ec5a2bb0e08940a5d14500d59f2aadd913bc19 (patch) | |
tree | d8b7892859a4dadedc79a4cd8bc951bfbee5c2ac | |
parent | 52eda6082fd32d3e28f3600858afd8f5bbc918fe (diff) | |
download | servo-10ec5a2bb0e08940a5d14500d59f2aadd913bc19.tar.gz servo-10ec5a2bb0e08940a5d14500d59f2aadd913bc19.zip |
Replace NonZero<*{const,mut} _> with std::ptr::NonNull
-rw-r--r-- | Cargo.lock | 3 | ||||
-rw-r--r-- | components/layout/wrapper.rs | 2 | ||||
-rw-r--r-- | components/layout_thread/Cargo.toml | 3 | ||||
-rw-r--r-- | components/layout_thread/dom_wrapper.rs | 10 | ||||
-rw-r--r-- | components/layout_thread/lib.rs | 1 | ||||
-rw-r--r-- | components/script/Cargo.toml | 1 | ||||
-rw-r--r-- | components/script/dom/bindings/root.rs | 35 | ||||
-rw-r--r-- | components/script/dom/bindings/weakref.rs | 30 | ||||
-rw-r--r-- | components/script/lib.rs | 1 | ||||
-rw-r--r-- | components/script_layout_interface/Cargo.toml | 1 | ||||
-rw-r--r-- | components/script_layout_interface/lib.rs | 5 |
11 files changed, 42 insertions, 50 deletions
diff --git a/Cargo.lock b/Cargo.lock index c6df3be6f7d..1598b0b3a7a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1455,7 +1455,6 @@ dependencies = [ "metrics 0.0.1", "msg 0.0.1", "net_traits 0.0.1", - "nonzero 0.0.1", "parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "profile_traits 0.0.1", "range 0.0.1", @@ -2437,7 +2436,6 @@ dependencies = [ "mozjs 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", "msg 0.0.1", "net_traits 0.0.1", - "nonzero 0.0.1", "num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", "offscreen_gl_context 0.14.2 (registry+https://github.com/rust-lang/crates.io-index)", "open 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2496,7 +2494,6 @@ dependencies = [ "metrics 0.0.1", "msg 0.0.1", "net_traits 0.0.1", - "nonzero 0.0.1", "profile_traits 0.0.1", "range 0.0.1", "script_traits 0.0.1", diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index 4eba8b88a4d..df93edb776d 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -67,7 +67,7 @@ pub trait GetRawData { impl<T: GetLayoutData> GetRawData for T { fn get_raw_data(&self) -> Option<&StyleAndLayoutData> { self.get_style_and_layout_data().map(|opaque| { - let container = opaque.ptr.get() as *mut StyleAndLayoutData; + let container = opaque.ptr.as_ptr() as *mut StyleAndLayoutData; unsafe { &*container } }) } diff --git a/components/layout_thread/Cargo.toml b/components/layout_thread/Cargo.toml index f4a2e5d9acb..661a7f849de 100644 --- a/components/layout_thread/Cargo.toml +++ b/components/layout_thread/Cargo.toml @@ -10,7 +10,7 @@ name = "layout_thread" path = "lib.rs" [features] -unstable = ["parking_lot/nightly", "nonzero/unstable"] +unstable = ["parking_lot/nightly"] [dependencies] app_units = "0.6" @@ -30,7 +30,6 @@ malloc_size_of = { path = "../malloc_size_of" } metrics = {path = "../metrics"} msg = {path = "../msg"} net_traits = {path = "../net_traits"} -nonzero = {path = "../nonzero"} parking_lot = "0.4" profile_traits = {path = "../profile_traits"} range = {path = "../range"} diff --git a/components/layout_thread/dom_wrapper.rs b/components/layout_thread/dom_wrapper.rs index 1b58f9f81b5..6eef1106c3d 100644 --- a/components/layout_thread/dom_wrapper.rs +++ b/components/layout_thread/dom_wrapper.rs @@ -36,7 +36,6 @@ use html5ever::{LocalName, Namespace}; use layout::data::StyleAndLayoutData; use layout::wrapper::GetRawData; use msg::constellation_msg::{BrowsingContextId, PipelineId}; -use nonzero::NonZero; use range::Range; use script::layout_exports::{CharacterDataTypeId, ElementTypeId, HTMLElementTypeId, NodeTypeId}; use script::layout_exports::{Document, Element, Node, Text}; @@ -59,6 +58,7 @@ use std::fmt; use std::fmt::Debug; use std::hash::{Hash, Hasher}; use std::marker::PhantomData; +use std::ptr::NonNull; use std::sync::atomic::Ordering; use style::CaseSensitivityExt; use style::applicable_declarations::ApplicableDeclarationBlock; @@ -76,7 +76,7 @@ use style::shared_lock::{SharedRwLock as StyleSharedRwLock, Locked as StyleLocke use style::str::is_whitespace; pub unsafe fn drop_style_and_layout_data(data: OpaqueStyleAndLayoutData) { - let ptr = data.ptr.get() as *mut StyleData; + let ptr = data.ptr.as_ptr() as *mut StyleData; let non_opaque: *mut StyleAndLayoutData = ptr as *mut _; let _ = Box::from_raw(non_opaque); } @@ -229,7 +229,7 @@ impl<'ln> LayoutNode for ServoLayoutNode<'ln> { let ptr: *mut StyleAndLayoutData = Box::into_raw(Box::new(StyleAndLayoutData::new())); let opaque = OpaqueStyleAndLayoutData { - ptr: NonZero::new_unchecked(ptr as *mut StyleData), + ptr: NonNull::new_unchecked(ptr as *mut StyleData), }; self.init_style_and_layout_data(opaque); }; @@ -450,7 +450,7 @@ impl<'le> TElement for ServoLayoutElement<'le> { fn get_data(&self) -> Option<&AtomicRefCell<ElementData>> { unsafe { self.get_style_and_layout_data().map(|d| { - &(*(d.ptr.get() as *mut StyleData)).element_data + &(*(d.ptr.as_ptr() as *mut StyleData)).element_data }) } } @@ -575,7 +575,7 @@ impl<'le> ServoLayoutElement<'le> { fn get_style_data(&self) -> Option<&StyleData> { unsafe { - self.get_style_and_layout_data().map(|d| &*(d.ptr.get() as *mut StyleData)) + self.get_style_and_layout_data().map(|d| &*(d.ptr.as_ptr() as *mut StyleData)) } } diff --git a/components/layout_thread/lib.rs b/components/layout_thread/lib.rs index bca5da278b8..3fb7d0c8c73 100644 --- a/components/layout_thread/lib.rs +++ b/components/layout_thread/lib.rs @@ -28,7 +28,6 @@ extern crate malloc_size_of; extern crate metrics; extern crate msg; extern crate net_traits; -extern crate nonzero; extern crate parking_lot; #[macro_use] extern crate profile_traits; diff --git a/components/script/Cargo.toml b/components/script/Cargo.toml index a78053f76cd..4aae00f551b 100644 --- a/components/script/Cargo.toml +++ b/components/script/Cargo.toml @@ -65,7 +65,6 @@ mime_guess = "1.8.0" mozjs = { version = "0.1.10", features = ["promises"]} msg = {path = "../msg"} net_traits = {path = "../net_traits"} -nonzero = {path = "../nonzero"} num-traits = "0.1.32" offscreen_gl_context = { version = "0.14", features = ["serde"] } open = "1.1.1" diff --git a/components/script/dom/bindings/root.rs b/components/script/dom/bindings/root.rs index 636c14b4d5c..18cb0062023 100644 --- a/components/script/dom/bindings/root.rs +++ b/components/script/dom/bindings/root.rs @@ -34,7 +34,6 @@ use js::jsapi::{JSObject, JSTracer, Heap}; use js::rust::GCMethods; use malloc_size_of::{MallocSizeOf, MallocSizeOfOps}; use mitochondria::OnceCell; -use nonzero::NonZero; use script_layout_interface::TrustedNodeAddress; use std::cell::{Cell, UnsafeCell}; use std::default::Default; @@ -312,7 +311,7 @@ impl<'root, T: RootedReference<'root> + 'root> RootedReference<'root> for Option /// This should only be used as a field in other DOM objects. #[must_root] pub struct Dom<T> { - ptr: NonZero<*const T>, + ptr: ptr::NonNull<T>, } // Dom<T> is similar to Rc<T>, in that it's not always clear how to avoid double-counting. @@ -339,7 +338,7 @@ impl<T: DomObject> Dom<T> { pub fn from_ref(obj: &T) -> Dom<T> { debug_assert!(thread_state::get().is_script()); Dom { - ptr: unsafe { NonZero::new_unchecked(&*obj) }, + ptr: ptr::NonNull::from(obj), } } } @@ -351,7 +350,7 @@ impl<T: DomObject> Deref for Dom<T> { debug_assert!(thread_state::get().is_script()); // We can only have &Dom<T> from a rooted thing, so it's safe to deref // it to &T. - unsafe { &*self.ptr.get() } + unsafe { &*self.ptr.as_ptr() } } } @@ -366,7 +365,7 @@ unsafe impl<T: DomObject> JSTraceable for Dom<T> { trace_reflector(trc, trace_info, - (*self.ptr.get()).reflector()); + (*self.ptr.as_ptr()).reflector()); } } @@ -374,7 +373,7 @@ unsafe impl<T: DomObject> JSTraceable for Dom<T> { /// traits must be implemented on this. #[allow_unrooted_interior] pub struct LayoutDom<T> { - ptr: NonZero<*const T>, + ptr: ptr::NonNull<T>, } impl<T: Castable> LayoutDom<T> { @@ -384,9 +383,9 @@ impl<T: Castable> LayoutDom<T> { T: DerivedFrom<U> { debug_assert!(thread_state::get().is_layout()); - let ptr: *const T = self.ptr.get(); + let ptr: *mut T = self.ptr.as_ptr(); LayoutDom { - ptr: unsafe { NonZero::new_unchecked(ptr as *const U) }, + ptr: unsafe { ptr::NonNull::new_unchecked(ptr as *mut U) }, } } @@ -397,9 +396,9 @@ impl<T: Castable> LayoutDom<T> { debug_assert!(thread_state::get().is_layout()); unsafe { if (*self.unsafe_get()).is::<U>() { - let ptr: *const T = self.ptr.get(); + let ptr: *mut T = self.ptr.as_ptr(); Some(LayoutDom { - ptr: NonZero::new_unchecked(ptr as *const U), + ptr: ptr::NonNull::new_unchecked(ptr as *mut U), }) } else { None @@ -412,7 +411,7 @@ impl<T: DomObject> LayoutDom<T> { /// Get the reflector. pub unsafe fn get_jsobject(&self) -> *mut JSObject { debug_assert!(thread_state::get().is_layout()); - (*self.ptr.get()).reflector().get_jsobject().get() + (*self.ptr.as_ptr()).reflector().get_jsobject().get() } } @@ -420,7 +419,7 @@ impl<T> Copy for LayoutDom<T> {} impl<T> PartialEq for Dom<T> { fn eq(&self, other: &Dom<T>) -> bool { - self.ptr == other.ptr + self.ptr.as_ptr() == other.ptr.as_ptr() } } @@ -428,7 +427,7 @@ impl<T> Eq for Dom<T> {} impl<T> PartialEq for LayoutDom<T> { fn eq(&self, other: &LayoutDom<T>) -> bool { - self.ptr == other.ptr + self.ptr.as_ptr() == other.ptr.as_ptr() } } @@ -436,13 +435,13 @@ impl<T> Eq for LayoutDom<T> {} impl<T> Hash for Dom<T> { fn hash<H: Hasher>(&self, state: &mut H) { - self.ptr.hash(state) + self.ptr.as_ptr().hash(state) } } impl<T> Hash for LayoutDom<T> { fn hash<H: Hasher>(&self, state: &mut H) { - self.ptr.hash(state) + self.ptr.as_ptr().hash(state) } } @@ -474,7 +473,7 @@ impl LayoutDom<Node> { debug_assert!(thread_state::get().is_layout()); let TrustedNodeAddress(addr) = inner; LayoutDom { - ptr: NonZero::new_unchecked(addr as *const Node), + ptr: ptr::NonNull::new_unchecked(addr as *const Node as *mut Node), } } } @@ -700,7 +699,7 @@ impl<T: DomObject> LayoutDom<T> { /// this is unsafe is what necessitates the layout wrappers.) pub unsafe fn unsafe_get(&self) -> *const T { debug_assert!(thread_state::get().is_layout()); - self.ptr.get() + self.ptr.as_ptr() } /// Returns a reference to the interior of this JS object. This method is @@ -708,7 +707,7 @@ impl<T: DomObject> LayoutDom<T> { /// mutate DOM nodes. pub fn get_for_script(&self) -> &T { debug_assert!(thread_state::get().is_script()); - unsafe { &*self.ptr.get() } + unsafe { &*self.ptr.as_ptr() } } } diff --git a/components/script/dom/bindings/weakref.rs b/components/script/dom/bindings/weakref.rs index 2aa12490867..e4e5f00103f 100644 --- a/components/script/dom/bindings/weakref.rs +++ b/components/script/dom/bindings/weakref.rs @@ -18,10 +18,10 @@ use js::jsapi::{JSTracer, JS_GetReservedSlot, JS_SetReservedSlot}; use js::jsval::PrivateValue; use libc::c_void; use malloc_size_of::{MallocSizeOf, MallocSizeOfOps}; -use nonzero::NonZero; use std::cell::{Cell, UnsafeCell}; use std::mem; use std::ops::{Deref, DerefMut, Drop}; +use std::ptr; /// The index of the slot wherein a pointer to the weak holder cell is /// stored for weak-referenceable bindings. We use slot 1 for holding it, @@ -30,9 +30,10 @@ use std::ops::{Deref, DerefMut, Drop}; pub const DOM_WEAK_SLOT: u32 = 1; /// A weak reference to a JS-managed DOM object. +#[allow(unrooted_must_root)] #[allow_unrooted_interior] pub struct WeakRef<T: WeakReferenceable> { - ptr: NonZero<*mut WeakBox<T>>, + ptr: ptr::NonNull<WeakBox<T>>, } /// The inner box of weak references, public for the finalization in codegen. @@ -42,7 +43,7 @@ pub struct WeakBox<T: WeakReferenceable> { /// have already been set to `None`. The pointee contributes one to the count. pub count: Cell<usize>, /// The pointer to the JS-managed object, set to None when it is collected. - pub value: Cell<Option<NonZero<*const T>>>, + pub value: Cell<Option<ptr::NonNull<T>>>, } /// Trait implemented by weak-referenceable interfaces. @@ -58,7 +59,7 @@ pub trait WeakReferenceable: DomObject + Sized { trace!("Creating new WeakBox holder for {:p}.", self); ptr = Box::into_raw(Box::new(WeakBox { count: Cell::new(1), - value: Cell::new(Some(NonZero::new_unchecked(self))), + value: Cell::new(Some(ptr::NonNull::from(self))), })); JS_SetReservedSlot(object, DOM_WEAK_SLOT, PrivateValue(ptr as *const c_void)); } @@ -70,7 +71,7 @@ pub trait WeakReferenceable: DomObject + Sized { new_count); box_.count.set(new_count); WeakRef { - ptr: NonZero::new_unchecked(ptr), + ptr: ptr::NonNull::new_unchecked(ptr), } } } @@ -86,21 +87,21 @@ impl<T: WeakReferenceable> WeakRef<T> { /// DomRoot a weak reference. Returns `None` if the object was already collected. pub fn root(&self) -> Option<DomRoot<T>> { - unsafe { &*self.ptr.get() }.value.get().map(|ptr| unsafe { - DomRoot::from_ref(&*ptr.get()) + unsafe { &*self.ptr.as_ptr() }.value.get().map(|ptr| unsafe { + DomRoot::from_ref(&*ptr.as_ptr()) }) } /// Return whether the weakly-referenced object is still alive. pub fn is_alive(&self) -> bool { - unsafe { &*self.ptr.get() }.value.get().is_some() + unsafe { &*self.ptr.as_ptr() }.value.get().is_some() } } impl<T: WeakReferenceable> Clone for WeakRef<T> { fn clone(&self) -> WeakRef<T> { unsafe { - let box_ = &*self.ptr.get(); + let box_ = &*self.ptr.as_ptr(); let new_count = box_.count.get() + 1; box_.count.set(new_count); WeakRef { @@ -119,7 +120,8 @@ impl<T: WeakReferenceable> MallocSizeOf for WeakRef<T> { impl<T: WeakReferenceable> PartialEq for WeakRef<T> { fn eq(&self, other: &Self) -> bool { unsafe { - (*self.ptr.get()).value.get() == (*other.ptr.get()).value.get() + (*self.ptr.as_ptr()).value.get().map(ptr::NonNull::as_ptr) == + (*other.ptr.as_ptr()).value.get().map(ptr::NonNull::as_ptr) } } } @@ -127,8 +129,8 @@ impl<T: WeakReferenceable> PartialEq for WeakRef<T> { impl<T: WeakReferenceable> PartialEq<T> for WeakRef<T> { fn eq(&self, other: &T) -> bool { unsafe { - match (*self.ptr.get()).value.get() { - Some(ptr) => ptr.get() == other, + match self.ptr.as_ref().value.get() { + Some(ptr) => ptr::eq(ptr.as_ptr(), other), None => false, } } @@ -145,7 +147,7 @@ impl<T: WeakReferenceable> Drop for WeakRef<T> { fn drop(&mut self) { unsafe { let (count, value) = { - let weak_box = &*self.ptr.get(); + let weak_box = &*self.ptr.as_ptr(); assert!(weak_box.count.get() > 0); let count = weak_box.count.get() - 1; weak_box.count.set(count); @@ -153,7 +155,7 @@ impl<T: WeakReferenceable> Drop for WeakRef<T> { }; if count == 0 { assert!(value.is_none()); - mem::drop(Box::from_raw(self.ptr.get())); + mem::drop(Box::from_raw(self.ptr.as_ptr())); } } } diff --git a/components/script/lib.rs b/components/script/lib.rs index c3517691e8b..a871b320758 100644 --- a/components/script/lib.rs +++ b/components/script/lib.rs @@ -68,7 +68,6 @@ extern crate mitochondria; extern crate mozjs as js; extern crate msg; extern crate net_traits; -extern crate nonzero; extern crate num_traits; extern crate offscreen_gl_context; extern crate open; diff --git a/components/script_layout_interface/Cargo.toml b/components/script_layout_interface/Cargo.toml index 6a64c2b205e..db3c63dddbe 100644 --- a/components/script_layout_interface/Cargo.toml +++ b/components/script_layout_interface/Cargo.toml @@ -25,7 +25,6 @@ malloc_size_of_derive = { path = "../malloc_size_of_derive" } metrics = {path = "../metrics"} msg = {path = "../msg"} net_traits = {path = "../net_traits"} -nonzero = {path = "../nonzero"} profile_traits = {path = "../profile_traits"} range = {path = "../range"} script_traits = {path = "../script_traits"} diff --git a/components/script_layout_interface/lib.rs b/components/script_layout_interface/lib.rs index 4e17570f92d..0538aabafd0 100644 --- a/components/script_layout_interface/lib.rs +++ b/components/script_layout_interface/lib.rs @@ -24,7 +24,6 @@ extern crate malloc_size_of; extern crate metrics; extern crate msg; extern crate net_traits; -extern crate nonzero; extern crate profile_traits; extern crate range; extern crate script_traits; @@ -45,9 +44,9 @@ use canvas_traits::canvas::CanvasMsg; use ipc_channel::ipc::IpcSender; use libc::c_void; use net_traits::image_cache::PendingImageId; -use nonzero::NonZero; use script_traits::UntrustedNodeAddress; use servo_url::ServoUrl; +use std::ptr::NonNull; use std::sync::atomic::AtomicIsize; use style::data::ElementData; @@ -77,7 +76,7 @@ pub struct OpaqueStyleAndLayoutData { // NB: We really store a `StyleAndLayoutData` here, so be careful! #[ignore_malloc_size_of = "TODO(#6910) Box value that should be counted but \ the type lives in layout"] - pub ptr: NonZero<*mut StyleData>, + pub ptr: NonNull<StyleData>, } #[allow(unsafe_code)] |