Use the new nonzero crate in the msg crate

This commit is contained in:
Simon Sapin 2017-10-12 00:28:50 +02:00
parent c4bf3ec14f
commit 57709dc0bf
8 changed files with 43 additions and 17 deletions

9
Cargo.lock generated
View file

@ -473,6 +473,7 @@ dependencies = [
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"msg 0.0.1", "msg 0.0.1",
"net_traits 0.0.1", "net_traits 0.0.1",
"nonzero 0.0.1",
"profile_traits 0.0.1", "profile_traits 0.0.1",
"script_traits 0.0.1", "script_traits 0.0.1",
"servo_config 0.0.1", "servo_config 0.0.1",
@ -1907,6 +1908,7 @@ dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize_derive 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_derive 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"nonzero 0.0.1",
"serde 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)",
"webrender_api 0.52.0 (git+https://github.com/servo/webrender)", "webrender_api 0.52.0 (git+https://github.com/servo/webrender)",
] ]
@ -2046,6 +2048,13 @@ name = "nom"
version = "1.2.4" version = "1.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "nonzero"
version = "0.0.1"
dependencies = [
"serde 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "nsstring_vendor" name = "nsstring_vendor"
version = "0.1.0" version = "0.1.0"

View file

@ -9,6 +9,9 @@ publish = false
name = "compositing" name = "compositing"
path = "lib.rs" path = "lib.rs"
[features]
unstable = ["nonzero/unstable"]
[dependencies] [dependencies]
euclid = "0.15" euclid = "0.15"
gfx_traits = {path = "../gfx_traits"} gfx_traits = {path = "../gfx_traits"}
@ -18,6 +21,7 @@ ipc-channel = "0.8"
log = "0.3.5" log = "0.3.5"
msg = {path = "../msg"} msg = {path = "../msg"}
net_traits = {path = "../net_traits"} net_traits = {path = "../net_traits"}
nonzero = {path = "../nonzero"}
profile_traits = {path = "../profile_traits"} profile_traits = {path = "../profile_traits"}
script_traits = {path = "../script_traits"} script_traits = {path = "../script_traits"}
servo_config = {path = "../config"} servo_config = {path = "../config"}

View file

@ -6,7 +6,6 @@ use CompositionPipeline;
use SendableFrameTree; use SendableFrameTree;
use compositor_thread::{CompositorProxy, CompositorReceiver}; use compositor_thread::{CompositorProxy, CompositorReceiver};
use compositor_thread::{InitialCompositorState, Msg, RenderListener}; use compositor_thread::{InitialCompositorState, Msg, RenderListener};
use core::nonzero::NonZero;
use euclid::{Point2D, TypedPoint2D, TypedVector2D, ScaleFactor}; use euclid::{Point2D, TypedPoint2D, TypedVector2D, ScaleFactor};
use gfx_traits::Epoch; use gfx_traits::Epoch;
use gleam::gl; use gleam::gl;
@ -14,6 +13,7 @@ use image::{DynamicImage, ImageFormat, RgbImage};
use ipc_channel::ipc::{self, IpcSharedMemory}; use ipc_channel::ipc::{self, IpcSharedMemory};
use msg::constellation_msg::{PipelineId, PipelineIndex, PipelineNamespaceId}; use msg::constellation_msg::{PipelineId, PipelineIndex, PipelineNamespaceId};
use net_traits::image::base::{Image, PixelFormat}; use net_traits::image::base::{Image, PixelFormat};
use nonzero::NonZeroU32;
use profile_traits::time::{self, ProfilerCategory, profile}; use profile_traits::time::{self, ProfilerCategory, profile};
use script_traits::{AnimationState, AnimationTickType, ConstellationControlMsg}; use script_traits::{AnimationState, AnimationTickType, ConstellationControlMsg};
use script_traits::{ConstellationMsg, LayoutControlMsg, MouseButton}; use script_traits::{ConstellationMsg, LayoutControlMsg, MouseButton};
@ -62,7 +62,7 @@ impl ConvertPipelineIdFromWebRender for webrender_api::PipelineId {
fn from_webrender(&self) -> PipelineId { fn from_webrender(&self) -> PipelineId {
PipelineId { PipelineId {
namespace_id: PipelineNamespaceId(self.0), namespace_id: PipelineNamespaceId(self.0),
index: PipelineIndex(NonZero::new(self.1).expect("Webrender pipeline zero?")), index: PipelineIndex(NonZeroU32::new(self.1).expect("Webrender pipeline zero?")),
} }
} }
} }

View file

@ -3,9 +3,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#![deny(unsafe_code)] #![deny(unsafe_code)]
#![feature(nonzero)] #![cfg_attr(feature = "unstable", feature(nonzero))]
extern crate core;
extern crate euclid; extern crate euclid;
extern crate gfx_traits; extern crate gfx_traits;
extern crate gleam; extern crate gleam;
@ -15,6 +14,7 @@ extern crate ipc_channel;
extern crate log; extern crate log;
extern crate msg; extern crate msg;
extern crate net_traits; extern crate net_traits;
extern crate nonzero;
extern crate profile_traits; extern crate profile_traits;
extern crate script_traits; extern crate script_traits;
extern crate servo_config; extern crate servo_config;

View file

@ -9,9 +9,13 @@ publish = false
name = "msg" name = "msg"
path = "lib.rs" path = "lib.rs"
[features]
unstable = ["nonzero/unstable"]
[dependencies] [dependencies]
bitflags = "0.7" bitflags = "0.7"
heapsize = "0.4" heapsize = "0.4"
heapsize_derive = "0.1" heapsize_derive = "0.1"
serde = { version = "1.0.14", features = [ "unstable" ] } nonzero = {path = "../nonzero"}
serde = "1.0.14"
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]} webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}

View file

@ -5,7 +5,7 @@
//! The high-level interface from script to constellation. Using this abstract interface helps //! The high-level interface from script to constellation. Using this abstract interface helps
//! reduce coupling between these two components. //! reduce coupling between these two components.
use core::nonzero::NonZero; use nonzero::NonZeroU32;
use std::cell::Cell; use std::cell::Cell;
use std::fmt; use std::fmt;
use webrender_api; use webrender_api;
@ -195,9 +195,9 @@ impl PipelineNamespace {
}); });
} }
fn next_index(&mut self) -> NonZero<u32> { fn next_index(&mut self) -> NonZeroU32 {
self.index += 1; self.index += 1;
NonZero::new(self.index).expect("pipeline id index wrapped!") NonZeroU32::new(self.index).expect("pipeline id index wrapped!")
} }
fn next_pipeline_id(&mut self) -> PipelineId { fn next_pipeline_id(&mut self) -> PipelineId {
@ -221,7 +221,7 @@ thread_local!(pub static PIPELINE_NAMESPACE: Cell<Option<PipelineNamespace>> = C
pub struct PipelineNamespaceId(pub u32); pub struct PipelineNamespaceId(pub u32);
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
pub struct PipelineIndex(pub NonZero<u32>); pub struct PipelineIndex(pub NonZeroU32);
known_heap_size!(0, PipelineIndex); known_heap_size!(0, PipelineIndex);
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, HeapSizeOf, Ord, PartialEq, PartialOrd, Serialize)] #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, HeapSizeOf, Ord, PartialEq, PartialOrd, Serialize)]
@ -264,7 +264,7 @@ impl fmt::Display for PipelineId {
} }
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
pub struct BrowsingContextIndex(pub NonZero<u32>); pub struct BrowsingContextIndex(pub NonZeroU32);
known_heap_size!(0, BrowsingContextIndex); known_heap_size!(0, BrowsingContextIndex);
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, HeapSizeOf, Ord, PartialEq, PartialOrd, Serialize)] #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, HeapSizeOf, Ord, PartialEq, PartialOrd, Serialize)]
@ -339,11 +339,15 @@ impl PartialEq<BrowsingContextId> for TopLevelBrowsingContextId {
// We provide ids just for unit testing. // We provide ids just for unit testing.
pub const TEST_NAMESPACE: PipelineNamespaceId = PipelineNamespaceId(1234); pub const TEST_NAMESPACE: PipelineNamespaceId = PipelineNamespaceId(1234);
#[allow(unsafe_code)] #[allow(unsafe_code)]
pub const TEST_PIPELINE_INDEX: PipelineIndex = unsafe { PipelineIndex(NonZero::new_unchecked(5678)) }; #[cfg(feature = "unstable")]
pub const TEST_PIPELINE_INDEX: PipelineIndex = unsafe { PipelineIndex(NonZeroU32::new_unchecked(5678)) };
#[cfg(feature = "unstable")]
pub const TEST_PIPELINE_ID: PipelineId = PipelineId { namespace_id: TEST_NAMESPACE, index: TEST_PIPELINE_INDEX }; pub const TEST_PIPELINE_ID: PipelineId = PipelineId { namespace_id: TEST_NAMESPACE, index: TEST_PIPELINE_INDEX };
#[allow(unsafe_code)] #[allow(unsafe_code)]
#[cfg(feature = "unstable")]
pub const TEST_BROWSING_CONTEXT_INDEX: BrowsingContextIndex = pub const TEST_BROWSING_CONTEXT_INDEX: BrowsingContextIndex =
unsafe { BrowsingContextIndex(NonZero::new_unchecked(8765)) }; unsafe { BrowsingContextIndex(NonZeroU32::new_unchecked(8765)) };
#[cfg(feature = "unstable")]
pub const TEST_BROWSING_CONTEXT_ID: BrowsingContextId = pub const TEST_BROWSING_CONTEXT_ID: BrowsingContextId =
BrowsingContextId { namespace_id: TEST_NAMESPACE, index: TEST_BROWSING_CONTEXT_INDEX }; BrowsingContextId { namespace_id: TEST_NAMESPACE, index: TEST_BROWSING_CONTEXT_INDEX };

View file

@ -2,16 +2,16 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#![feature(const_fn)] #![cfg_attr(feature = "unstable", feature(nonzero))]
#![feature(const_nonzero_new)] #![cfg_attr(feature = "unstable", feature(const_fn))]
#![feature(nonzero)] #![cfg_attr(feature = "unstable", feature(const_nonzero_new))]
#![deny(unsafe_code)] #![deny(unsafe_code)]
#[macro_use] #[macro_use]
extern crate bitflags; extern crate bitflags;
extern crate core;
#[macro_use] extern crate heapsize; #[macro_use] extern crate heapsize;
#[macro_use] extern crate heapsize_derive; #[macro_use] extern crate heapsize_derive;
extern crate nonzero;
#[macro_use] extern crate serde; #[macro_use] extern crate serde;
extern crate webrender_api; extern crate webrender_api;

View file

@ -18,7 +18,12 @@ energy-profiling = ["profile_traits/energy-profiling"]
debugmozjs = ["script/debugmozjs"] debugmozjs = ["script/debugmozjs"]
googlevr = ["webvr/googlevr"] googlevr = ["webvr/googlevr"]
oculusvr = ["webvr/oculusvr"] oculusvr = ["webvr/oculusvr"]
unstable = ["euclid/unstable", "layout_thread/unstable"] unstable = [
"euclid/unstable",
"layout_thread/unstable",
"msg/unstable",
"compositing/unstable"
]
[dependencies] [dependencies]
bluetooth_traits = {path = "../bluetooth_traits"} bluetooth_traits = {path = "../bluetooth_traits"}