aboutsummaryrefslogtreecommitdiffstats
path: root/components/style/gecko
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2023-05-11 00:36:24 +0000
committerMartin Robinson <mrobinson@igalia.com>2023-11-24 08:57:14 +0100
commit779aa9d30ec43c043910883dce5988c0b01534bd (patch)
tree89b742d8c798da48e62ed721405a8a9e66c6b890 /components/style/gecko
parentd9d865e8c9fad5eaaa15be7d3bfbf53df47135ca (diff)
downloadservo-779aa9d30ec43c043910883dce5988c0b01534bd.tar.gz
servo-779aa9d30ec43c043910883dce5988c0b01534bd.zip
style: Remove HasArcFFI for some types
See blocked bug. For non-Locked types we can just use the same underlying type at the FFI boundary. Port StylesheetContents and CssUrlData to this set-up. CssUrlData is already generated by cbindgen anyways. Differential Revision: https://phabricator.services.mozilla.com/D177559
Diffstat (limited to 'components/style/gecko')
-rw-r--r--components/style/gecko/arc_types.rs61
-rw-r--r--components/style/gecko/data.rs6
2 files changed, 31 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 }
}
}