Permalink
Browse files

Use NonZeroUsize in script_layout_interface

  • Loading branch information...
SimonSapin committed Oct 12, 2017
1 parent 0d9c9b1 commit a15eaab2e6a83e438372b6ed5c21f2c7f51cfe23
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -10,7 +10,7 @@ name = "layout_thread"
path = "lib.rs"
[features]
unstable = ["parking_lot/nightly"]
unstable = ["parking_lot/nightly", "nonzero/unstable"]
[dependencies]
app_units = "0.5"
@@ -29,6 +29,7 @@ log = "0.3.5"
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"}
@@ -31,12 +31,12 @@
#![allow(unsafe_code)]
use atomic_refcell::{AtomicRef, AtomicRefMut, AtomicRefCell};
use core::nonzero::NonZero;
use gfx_traits::ByteIndex;
use html5ever::{LocalName, Namespace};
use layout::data::StyleAndLayoutData;
use layout::wrapper::GetRawData;
use msg::constellation_msg::{BrowsingContextId, PipelineId};
use nonzero::NonZeroUsize;
use range::Range;
use script::layout_exports::{CAN_BE_FRAGMENTED, HAS_DIRTY_DESCENDANTS, IS_IN_DOC};
use script::layout_exports::{CharacterDataTypeId, ElementTypeId, HTMLElementTypeId, NodeTypeId};
@@ -79,7 +79,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: *mut StyleData = data.ptr.get();
let ptr = data.ptr.get() as *mut StyleData;
let non_opaque: *mut StyleAndLayoutData = ptr as *mut _;
let _ = Box::from_raw(non_opaque);
}
@@ -235,7 +235,8 @@ 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: NonZeroUsize::new_unchecked(ptr as usize),
phantom: PhantomData,
};
self.init_style_and_layout_data(opaque);
};
@@ -471,7 +472,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()).element_data
&(*(d.ptr.get() as *mut StyleData)).element_data
})
}
}
@@ -583,7 +584,7 @@ impl<'le> ServoLayoutElement<'le> {
fn get_style_data(&self) -> Option<&StyleData> {
unsafe {
self.get_style_and_layout_data().map(|d| &*d.ptr.get())
self.get_style_and_layout_data().map(|d| &*(d.ptr.get() as *mut StyleData))
}
}
@@ -6,11 +6,10 @@
//! painted.
#![feature(mpsc_select)]
#![feature(nonzero)]
#![cfg_attr(feature = "unstable", feature(nonzero))]
extern crate app_units;
extern crate atomic_refcell;
extern crate core;
extern crate euclid;
extern crate fnv;
extern crate gfx;
@@ -28,6 +27,7 @@ extern crate lazy_static;
extern crate log;
extern crate metrics;
extern crate msg;
extern crate nonzero;
extern crate net_traits;
extern crate parking_lot;
#[macro_use]
View
@@ -31,6 +31,7 @@ mod imp {
pub struct NonZeroU32(u32);
impl NonZeroU32 {
#[inline]
pub fn new(x: u32) -> Option<Self> {
if x != 0 {
Some(NonZeroU32(x))
@@ -39,10 +40,12 @@ mod imp {
}
}
#[inline]
pub unsafe fn new_unchecked(x: u32) -> Self {
NonZeroU32(x)
}
#[inline]
pub fn get(self) -> u32 {
self.0
}
@@ -52,38 +55,49 @@ mod imp {
pub struct NonZeroUsize(&'static ());
impl NonZeroUsize {
#[inline]
pub fn new(x: usize) -> Option<Self> {
if x != 0 {
Some(NonZeroUsize(unsafe { &*(x as *const ()) }))
Some(unsafe { Self::new_unchecked(x) })
} else {
None
}
}
#[inline]
pub unsafe fn new_unchecked(x: usize) -> Self {
NonZeroUsize(&*(x as *const ()))
}
#[inline]
pub fn get(self) -> usize {
self.0 as *const () as usize
}
}
impl PartialEq for NonZeroUsize {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.get() == other.get()
}
}
impl PartialOrd for NonZeroUsize {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
self.get().partial_cmp(&other.get())
}
}
impl Ord for NonZeroUsize {
#[inline]
fn cmp(&self, other: &Self) -> cmp::Ordering {
self.get().cmp(&other.get())
}
}
impl hash::Hash for NonZeroUsize {
#[inline]
fn hash<H: hash::Hasher>(&self, hasher: &mut H) {
self.get().hash(hasher)
}
@@ -9,6 +9,9 @@ publish = false
name = "script_layout_interface"
path = "lib.rs"
[features]
unstable = ["nonzero/unstable"]
[dependencies]
app_units = "0.5"
atomic_refcell = "0.1"
@@ -25,6 +28,7 @@ log = "0.3.5"
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"}
@@ -7,12 +7,11 @@
//! to depend on script.
#![deny(unsafe_code)]
#![feature(nonzero)]
#![cfg_attr(feature = "unstable", feature(nonzero))]
extern crate app_units;
extern crate atomic_refcell;
extern crate canvas_traits;
extern crate core;
extern crate cssparser;
extern crate euclid;
extern crate gfx_traits;
@@ -26,6 +25,7 @@ extern crate log;
extern crate metrics;
extern crate msg;
extern crate net_traits;
extern crate nonzero;
extern crate profile_traits;
extern crate range;
extern crate script_traits;
@@ -43,12 +43,13 @@ pub mod wrapper_traits;
use atomic_refcell::AtomicRefCell;
use canvas_traits::canvas::CanvasMsg;
use core::nonzero::NonZero;
use nonzero::NonZeroUsize;
use ipc_channel::ipc::IpcSender;
use libc::c_void;
use net_traits::image_cache::PendingImageId;
use script_traits::UntrustedNodeAddress;
use servo_url::ServoUrl;
use std::marker::PhantomData;
use std::sync::atomic::AtomicIsize;
use style::data::ElementData;
@@ -78,7 +79,8 @@ pub struct OpaqueStyleAndLayoutData {
// NB: We really store a `StyleAndLayoutData` here, so be careful!
#[ignore_heap_size_of = "TODO(#6910) Box value that should be counted but \
the type lives in layout"]
pub ptr: NonZero<*mut StyleData>
pub ptr: NonZeroUsize,
pub phantom: PhantomData<*mut StyleData>,
}
#[allow(unsafe_code)]
@@ -27,6 +27,7 @@ unstable = [
"constellation/unstable",
"gfx/unstable",
"profile/unstable",
"script_layout_interface/unstable",
]
[dependencies]

0 comments on commit a15eaab

Please sign in to comment.