aboutsummaryrefslogtreecommitdiffstats
path: root/components/style
diff options
context:
space:
mode:
Diffstat (limited to 'components/style')
-rw-r--r--components/style/gecko/arc_types.rs61
-rw-r--r--components/style/gecko/data.rs6
-rw-r--r--components/style/gecko_bindings/sugar/ownership.rs9
3 files changed, 40 insertions, 36 deletions
diff --git a/components/style/gecko/arc_types.rs b/components/style/gecko/arc_types.rs
index c72047183f2..c9f5717bc19 100644
--- a/components/style/gecko/arc_types.rs
+++ b/components/style/gecko/arc_types.rs
@@ -10,14 +10,14 @@
use crate::gecko::url::CssUrlData;
use crate::gecko_bindings::structs::{
- RawServoAnimationValue, RawServoContainerRule, RawServoCounterStyleRule, RawServoCssUrlData,
+ RawServoAnimationValue, RawServoContainerRule, RawServoCounterStyleRule,
RawServoDeclarationBlock, RawServoFontFaceRule, RawServoFontFeatureValuesRule,
RawServoFontPaletteValuesRule, RawServoImportRule, RawServoKeyframe, RawServoKeyframesRule,
RawServoLayerBlockRule, RawServoLayerStatementRule, RawServoMediaList, RawServoMediaRule,
RawServoMozDocumentRule, RawServoNamespaceRule, RawServoPageRule, RawServoStyleRule,
- RawServoStyleSheetContents, RawServoSupportsRule, ServoCssRules,
+ RawServoSupportsRule, ServoCssRules,
};
-use crate::gecko_bindings::sugar::ownership::{HasArcFFI, Strong};
+use crate::gecko_bindings::sugar::ownership::HasArcFFI;
use crate::media_queries::MediaList;
use crate::properties::animated_properties::AnimationValue;
use crate::properties::{ComputedValues, PropertyDeclarationBlock};
@@ -28,8 +28,7 @@ use crate::stylesheets::{
FontPaletteValuesRule, ImportRule, KeyframesRule, LayerBlockRule, LayerStatementRule,
MediaRule, NamespaceRule, PageRule, StyleRule, StylesheetContents, SupportsRule,
};
-use servo_arc::{Arc, ArcBorrow};
-use std::{mem, ptr};
+use servo_arc::Arc;
macro_rules! impl_arc_ffi {
($servo_type:ty => $gecko_type:ty[$addref:ident, $release:ident]) => {
@@ -52,9 +51,6 @@ macro_rules! impl_arc_ffi {
impl_arc_ffi!(Locked<CssRules> => ServoCssRules
[Servo_CssRules_AddRef, Servo_CssRules_Release]);
-impl_arc_ffi!(StylesheetContents => RawServoStyleSheetContents
- [Servo_StyleSheetContents_AddRef, Servo_StyleSheetContents_Release]);
-
impl_arc_ffi!(Locked<PropertyDeclarationBlock> => RawServoDeclarationBlock
[Servo_DeclarationBlock_AddRef, Servo_DeclarationBlock_Release]);
@@ -112,29 +108,32 @@ impl_arc_ffi!(Locked<FontFaceRule> => RawServoFontFaceRule
impl_arc_ffi!(Locked<CounterStyleRule> => RawServoCounterStyleRule
[Servo_CounterStyleRule_AddRef, Servo_CounterStyleRule_Release]);
-impl_arc_ffi!(CssUrlData => RawServoCssUrlData
- [Servo_CssUrlData_AddRef, Servo_CssUrlData_Release]);
-
-// ComputedStyle is not an opaque type on any side of FFI.
-// This means that doing the HasArcFFI type trick is actually unsound,
-// since it gives us a way to construct an Arc<ComputedStyle> from
-// an &ComputedStyle, which in general is not allowed. So we
-// implement the restricted set of arc type functionality we need.
-
-#[no_mangle]
-pub unsafe extern "C" fn Servo_ComputedStyle_AddRef(obj: &ComputedValues) {
- mem::forget(ArcBorrow::from_ref(obj).clone_arc());
-}
+macro_rules! impl_simple_arc_ffi {
+ ($ty:ty, $addref:ident, $release:ident) => {
+ #[no_mangle]
+ pub unsafe extern "C" fn $addref(obj: &$ty) {
+ std::mem::forget(Arc::from_raw_addrefed(obj));
+ }
-#[no_mangle]
-pub unsafe extern "C" fn Servo_ComputedStyle_Release(obj: &ComputedValues) {
- ArcBorrow::from_ref(obj).with_arc(|a: &Arc<ComputedValues>| {
- let _: Arc<ComputedValues> = ptr::read(a);
- });
+ #[no_mangle]
+ pub unsafe extern "C" fn $release(obj: &$ty) {
+ let _ = Arc::from_raw(obj);
+ }
+ };
}
-impl From<Arc<ComputedValues>> for Strong<ComputedValues> {
- fn from(arc: Arc<ComputedValues>) -> Self {
- unsafe { mem::transmute(Arc::into_raw_offset(arc)) }
- }
-}
+impl_simple_arc_ffi!(
+ StylesheetContents,
+ Servo_StyleSheetContents_AddRef,
+ Servo_StyleSheetContents_Release
+);
+impl_simple_arc_ffi!(
+ CssUrlData,
+ Servo_CssUrlData_AddRef,
+ Servo_CssUrlData_Release
+);
+impl_simple_arc_ffi!(
+ ComputedValues,
+ Servo_ComputedStyle_AddRef,
+ Servo_ComputedStyle_Release
+);
diff --git a/components/style/gecko/data.rs b/components/style/gecko/data.rs
index 65c7dc71012..50c827bf62f 100644
--- a/components/style/gecko/data.rs
+++ b/components/style/gecko/data.rs
@@ -125,11 +125,7 @@ impl StylesheetInDocument for GeckoStyleSheet {
#[inline]
fn contents(&self) -> &StylesheetContents {
debug_assert!(!self.inner().mContents.mRawPtr.is_null());
- unsafe {
- let contents =
- (&**StylesheetContents::as_arc(&&*self.inner().mContents.mRawPtr)) as *const _;
- &*contents
- }
+ unsafe { &*self.inner().mContents.mRawPtr }
}
}
diff --git a/components/style/gecko_bindings/sugar/ownership.rs b/components/style/gecko_bindings/sugar/ownership.rs
index bb9d2c87e6d..cd965038704 100644
--- a/components/style/gecko_bindings/sugar/ownership.rs
+++ b/components/style/gecko_bindings/sugar/ownership.rs
@@ -95,6 +95,15 @@ pub struct Strong<GeckoType> {
_marker: PhantomData<GeckoType>,
}
+impl<T> From<Arc<T>> for Strong<T> {
+ fn from(arc: Arc<T>) -> Self {
+ Self {
+ ptr: Arc::into_raw(arc),
+ _marker: PhantomData,
+ }
+ }
+}
+
impl<GeckoType> Strong<GeckoType> {
#[inline]
/// Returns whether this reference is null.