author | Emilio Cobos Álvarez <emilio@crisal.io> |
Sun, 21 May 2017 15:40:41 -0500 | |
changeset 359845 | fa623e714a039edc02c380a3da81ea529c9c00ec |
parent 359844 | cbef0952c3416b20baee769e4dd7d194317587d6 |
child 359846 | 09b32ef21528901ccf1d62dcc77422744a7bfa79 |
push id | 31859 |
push user | ihsiao@mozilla.com |
push date | Mon, 22 May 2017 03:28:26 +0000 |
treeherder | mozilla-central@367944041b55 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | nox, emilio |
milestone | 55.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/servo/components/style/gecko/generated/bindings.rs +++ b/servo/components/style/gecko/generated/bindings.rs @@ -1,18 +1,18 @@ /* automatically generated by rust-bindgen */ pub use nsstring::{nsACString, nsAString, nsString, nsStringRepr}; +use gecko_bindings::structs::nsTArray; type nsACString_internal = nsACString; type nsAString_internal = nsAString; use gecko_bindings::structs::mozilla::css::GridTemplateAreasValue; use gecko_bindings::structs::mozilla::css::ImageValue; use gecko_bindings::structs::mozilla::css::URLValue; use gecko_bindings::structs::mozilla::Side; -use gecko_bindings::structs::already_AddRefed; use gecko_bindings::structs::RawGeckoAnimationPropertySegment; use gecko_bindings::structs::RawGeckoComputedTiming; use gecko_bindings::structs::RawGeckoCSSPropertyIDList; use gecko_bindings::structs::RawGeckoDocument; use gecko_bindings::structs::RawGeckoElement; use gecko_bindings::structs::RawGeckoKeyframeList; use gecko_bindings::structs::RawGeckoComputedKeyframeValuesList; use gecko_bindings::structs::RawGeckoFontFaceRuleList; @@ -185,17 +185,16 @@ use gecko_bindings::structs::nsStyleVari unsafe impl Send for nsStyleVariables {} unsafe impl Sync for nsStyleVariables {} use gecko_bindings::structs::nsStyleVisibility; unsafe impl Send for nsStyleVisibility {} unsafe impl Sync for nsStyleVisibility {} use gecko_bindings::structs::nsStyleXUL; unsafe impl Send for nsStyleXUL {} unsafe impl Sync for nsStyleXUL {} -use gecko_bindings::structs::nsTArray; use gecko_bindings::structs::nsTimingFunction; use gecko_bindings::structs::nscolor; use gecko_bindings::structs::nscoord; use gecko_bindings::structs::nsresult; use gecko_bindings::structs::Loader; use gecko_bindings::structs::ServoStyleSheet; use gecko_bindings::structs::EffectCompositor_CascadeLevel; use gecko_bindings::structs::UpdateAnimationsTasks; @@ -1233,17 +1232,17 @@ extern "C" { } extern "C" { pub fn Gecko_CSSValue_SetStringFromAtom(css_value: nsCSSValueBorrowedMut, atom: *mut nsIAtom, unit: nsCSSUnit); } extern "C" { pub fn Gecko_CSSValue_SetAtomIdent(css_value: nsCSSValueBorrowedMut, - atom: already_AddRefed<nsIAtom>); + atom: *mut nsIAtom); } extern "C" { pub fn Gecko_CSSValue_SetArray(css_value: nsCSSValueBorrowedMut, len: i32); } extern "C" { pub fn Gecko_CSSValue_SetURL(css_value: nsCSSValueBorrowedMut, uri: ServoBundledURI); @@ -1977,17 +1976,17 @@ extern "C" { RawServoDeclarationBlockBorrowed); } extern "C" { pub fn Servo_KeyframesRule_GetName(rule: RawServoKeyframesRuleBorrowed) -> *mut nsIAtom; } extern "C" { pub fn Servo_KeyframesRule_SetName(rule: RawServoKeyframesRuleBorrowed, - name: already_AddRefed<nsIAtom>); + name: *mut nsIAtom); } extern "C" { pub fn Servo_KeyframesRule_GetCount(rule: RawServoKeyframesRuleBorrowed) -> u32; } extern "C" { pub fn Servo_KeyframesRule_GetKeyframe(rule: RawServoKeyframesRuleBorrowed,
--- a/servo/components/style/gecko/wrapper.rs +++ b/servo/components/style/gecko/wrapper.rs @@ -49,17 +49,16 @@ use gecko_bindings::structs::{RawGeckoEl use gecko_bindings::structs::{nsIAtom, nsIContent, nsINode_BooleanFlag, nsStyleContext}; use gecko_bindings::structs::ELEMENT_HANDLED_SNAPSHOT; use gecko_bindings::structs::ELEMENT_HAS_ANIMATION_ONLY_DIRTY_DESCENDANTS_FOR_SERVO; use gecko_bindings::structs::ELEMENT_HAS_DIRTY_DESCENDANTS_FOR_SERVO; use gecko_bindings::structs::ELEMENT_HAS_SNAPSHOT; use gecko_bindings::structs::EffectCompositor_CascadeLevel as CascadeLevel; use gecko_bindings::structs::NODE_IS_IN_NATIVE_ANONYMOUS_SUBTREE; use gecko_bindings::structs::NODE_IS_NATIVE_ANONYMOUS; -use gecko_bindings::structs::already_AddRefed; use gecko_bindings::sugar::ownership::HasArcFFI; use logical_geometry::WritingMode; use media_queries::Device; use properties::{ComputedValues, parse_style_attribute}; use properties::{Importance, PropertyDeclaration, PropertyDeclarationBlock}; use properties::animated_properties::{AnimationValue, AnimationValueMap, TransitionProperty}; use properties::style_structs::Font; use rule_tree::CascadeLevel as ServoCascadeLevel; @@ -1070,23 +1069,23 @@ impl<'le> PresentationalHintsSynthesizer ); } // xml:lang has precedence over lang, which can be // set by Gecko_GetHTMLPresentationAttrDeclarationBlock // // http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#language let ptr = unsafe { - already_AddRefed::new(bindings::Gecko_GetXMLLangValue(self.0)) + bindings::Gecko_GetXMLLangValue(self.0) }; - if let Some(ptr) = ptr { + if !ptr.is_null() { let global_style_data = &*GLOBAL_STYLE_DATA; let pdb = PropertyDeclarationBlock::with_one( - PropertyDeclaration::XLang(SpecifiedLang(ptr.into())), + PropertyDeclaration::XLang(SpecifiedLang(unsafe { Atom::from_addrefed(ptr) })), Importance::Normal ); let arc = Arc::new(global_style_data.shared_lock.wrap(pdb)); hints.push(ApplicableDeclarationBlock::from_declarations(arc, ServoCascadeLevel::PresHints)) } // MathML's default lang has precedence over both `lang` and `xml:lang` if ns == &*Namespace(atom!("http://www.w3.org/1998/Math/MathML")) { if self.get_local_name().as_ptr() == atom!("math").as_ptr() {
deleted file mode 100644 --- a/servo/components/style/gecko_bindings/sugar/already_addrefed.rs +++ /dev/null @@ -1,48 +0,0 @@ -/* 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/. */ - -//! little helpers for `already_AddRefed`. - -use gecko_bindings::structs::already_AddRefed; -use std::marker::PhantomData; -use std::mem; - -impl<T> already_AddRefed<T> { - /// Create an already_AddRefed from an addrefed pointer. - #[inline] - pub unsafe fn new(ptr: *mut T) -> Option<Self> { - if !ptr.is_null() { - Some(Self::new_unchecked(ptr)) - } else { - None - } - } - - /// Create an already_AddRefed from an non-nullable addrefed pointer. - #[inline] - pub unsafe fn new_unchecked(ptr: *mut T) -> Self { - debug_assert!(!ptr.is_null()); - already_AddRefed { - mRawPtr: ptr, - _phantom_0: PhantomData, - } - } - - /// Take the addrefed pointer from this struct. - #[inline] - pub fn take(self) -> *mut T { - let ptr = self.mRawPtr; - mem::forget(self); - ptr - } -} - -#[cfg(debug_assertions)] -impl<T> Drop for already_AddRefed<T> { - fn drop(&mut self) { - // We really should instead mark already_AddRefed must_use, but - // we cannot currently, which is servo/rust-bindgen#710. - unreachable!("Destructor shouldn't be called, otherwise we are leaking") - } -}
--- a/servo/components/style/gecko_bindings/sugar/mod.rs +++ b/servo/components/style/gecko_bindings/sugar/mod.rs @@ -1,15 +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/. */ //! Rust sugar and convenience methods for Gecko types. -mod already_addrefed; mod ns_com_ptr; mod ns_compatibility; mod ns_css_shadow_array; pub mod ns_css_value; mod ns_style_auto_array; pub mod ns_style_coord; mod ns_t_array; mod ns_timing_function;
--- a/servo/components/style/gecko_bindings/sugar/ns_css_value.rs +++ b/servo/components/style/gecko_bindings/sugar/ns_css_value.rs @@ -147,17 +147,17 @@ impl nsCSSValue { /// Set to an identifier value pub fn set_ident(&mut self, s: &str) { self.set_string_internal(s, nsCSSUnit::eCSSUnit_Ident) } /// Set to an atom identifier value pub fn set_atom_ident(&mut self, s: Atom) { - unsafe { bindings::Gecko_CSSValue_SetAtomIdent(self, s.into()) } + unsafe { bindings::Gecko_CSSValue_SetAtomIdent(self, s.into_addrefed()) } } /// Set to a font format pub fn set_font_format(&mut self, s: &str) { self.set_string_internal(s, nsCSSUnit::eCSSUnit_Font_Format); } /// Set to a local font value
--- a/servo/components/style/gecko_string_cache/mod.rs +++ b/servo/components/style/gecko_string_cache/mod.rs @@ -5,17 +5,17 @@ #![allow(unsafe_code)] //! A drop-in replacement for string_cache, but backed by Gecko `nsIAtom`s. use gecko_bindings::bindings::Gecko_AddRefAtom; use gecko_bindings::bindings::Gecko_Atomize; use gecko_bindings::bindings::Gecko_Atomize16; use gecko_bindings::bindings::Gecko_ReleaseAtom; -use gecko_bindings::structs::{already_AddRefed, nsIAtom}; +use gecko_bindings::structs::nsIAtom; use nsstring::nsAString; use precomputed_hash::PrecomputedHash; use std::ascii::AsciiExt; use std::borrow::{Cow, Borrow}; use std::char::{self, DecodeUtf16}; use std::fmt::{self, Write}; use std::hash::{Hash, Hasher}; use std::iter::Cloned; @@ -214,16 +214,34 @@ impl Atom { #[inline] unsafe fn from_static(ptr: *mut nsIAtom) -> Self { let atom = Atom(ptr as *mut WeakAtom); debug_assert!(atom.is_static(), "Called from_static for a non-static atom!"); atom } + /// Creates an atom from a dynamic atom pointer that has already had AddRef + /// called on it. + #[inline] + pub unsafe fn from_addrefed(ptr: *mut nsIAtom) -> Self { + debug_assert!(!ptr.is_null()); + unsafe { + Atom(WeakAtom::new(ptr)) + } + } + + /// Convert this atom into an addrefed nsIAtom pointer. + #[inline] + pub fn into_addrefed(self) -> *mut nsIAtom { + let ptr = self.as_ptr(); + mem::forget(self); + ptr + } + /// Return whether two atoms are ASCII-case-insensitive matches pub fn eq_ignore_ascii_case(&self, other: &Self) -> bool { let a = self.as_slice(); let b = other.as_slice(); a.len() == b.len() && a.iter().zip(b).all(|(&a16, &b16)| { if a16 <= 0x7F && b16 <= 0x7F { (a16 as u8).eq_ignore_ascii_case(&(b16 as u8)) } else { @@ -335,24 +353,8 @@ impl From<*mut nsIAtom> for Atom { let ret = Atom(WeakAtom::new(ptr)); if !ret.is_static() { Gecko_AddRefAtom(ptr); } ret } } } - -impl From<already_AddRefed<nsIAtom>> for Atom { - #[inline] - fn from(ptr: already_AddRefed<nsIAtom>) -> Atom { - unsafe { Atom(WeakAtom::new(ptr.take())) } - } -} - -impl From<Atom> for already_AddRefed<nsIAtom> { - #[inline] - fn from(atom: Atom) -> already_AddRefed<nsIAtom> { - let ptr = atom.as_ptr(); - mem::forget(atom); - unsafe { already_AddRefed::new_unchecked(ptr) } - } -}
--- a/servo/ports/geckolib/glue.rs +++ b/servo/ports/geckolib/glue.rs @@ -67,17 +67,16 @@ use style::gecko_bindings::structs::{CSS use style::gecko_bindings::structs::{RawServoStyleRule, ServoStyleSheet}; use style::gecko_bindings::structs::{SheetParsingMode, nsIAtom, nsCSSPropertyID}; use style::gecko_bindings::structs::{nsCSSFontFaceRule, nsCSSCounterStyleRule}; use style::gecko_bindings::structs::{nsRestyleHint, nsChangeHint}; use style::gecko_bindings::structs::Loader; use style::gecko_bindings::structs::RawGeckoPresContextOwned; use style::gecko_bindings::structs::ServoElementSnapshotTable; use style::gecko_bindings::structs::URLExtraData; -use style::gecko_bindings::structs::already_AddRefed; use style::gecko_bindings::structs::nsCSSValueSharedList; use style::gecko_bindings::structs::nsCompatibility; use style::gecko_bindings::structs::nsresult; use style::gecko_bindings::sugar::ownership::{FFIArcHelpers, HasFFI, HasArcFFI, HasBoxFFI}; use style::gecko_bindings::sugar::ownership::{HasSimpleFFI, Strong}; use style::gecko_bindings::sugar::refptr::RefPtr; use style::gecko_properties::{self, style_structs}; use style::keyframes::{Keyframe, KeyframeSelector, KeyframesStepValue}; @@ -1001,20 +1000,19 @@ pub extern "C" fn Servo_Keyframe_SetStyl } #[no_mangle] pub extern "C" fn Servo_KeyframesRule_GetName(rule: RawServoKeyframesRuleBorrowed) -> *mut nsIAtom { read_locked_arc(rule, |rule: &KeyframesRule| rule.name.as_atom().as_ptr()) } #[no_mangle] -pub extern "C" fn Servo_KeyframesRule_SetName(rule: RawServoKeyframesRuleBorrowed, - name: already_AddRefed<nsIAtom>) { +pub extern "C" fn Servo_KeyframesRule_SetName(rule: RawServoKeyframesRuleBorrowed, name: *mut nsIAtom) { write_locked_arc(rule, |rule: &mut KeyframesRule| { - rule.name = KeyframesName::Ident(CustomIdent(name.into())); + rule.name = KeyframesName::Ident(CustomIdent(unsafe { Atom::from_addrefed(name) })); }) } #[no_mangle] pub extern "C" fn Servo_KeyframesRule_GetCount(rule: RawServoKeyframesRuleBorrowed) -> u32 { read_locked_arc(rule, |rule: &KeyframesRule| rule.keyframes.len() as u32) }