mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
style: Remove HasFFI as well
After the previous patches we only have one trait which we should also tweak / rework, so let's put it all on that single trait. Differential Revision: https://phabricator.services.mozilla.com/D177515
This commit is contained in:
parent
42cbb9d3cf
commit
e18675401e
2 changed files with 13 additions and 24 deletions
|
@ -17,7 +17,7 @@ use crate::gecko_bindings::structs::{
|
||||||
RawServoMozDocumentRule, RawServoNamespaceRule, RawServoPageRule, RawServoStyleRule,
|
RawServoMozDocumentRule, RawServoNamespaceRule, RawServoPageRule, RawServoStyleRule,
|
||||||
RawServoStyleSheetContents, RawServoSupportsRule, ServoCssRules,
|
RawServoStyleSheetContents, RawServoSupportsRule, ServoCssRules,
|
||||||
};
|
};
|
||||||
use crate::gecko_bindings::sugar::ownership::{HasArcFFI, HasFFI, Strong};
|
use crate::gecko_bindings::sugar::ownership::{HasArcFFI, Strong};
|
||||||
use crate::media_queries::MediaList;
|
use crate::media_queries::MediaList;
|
||||||
use crate::properties::animated_properties::AnimationValue;
|
use crate::properties::animated_properties::AnimationValue;
|
||||||
use crate::properties::{ComputedValues, PropertyDeclarationBlock};
|
use crate::properties::{ComputedValues, PropertyDeclarationBlock};
|
||||||
|
@ -33,10 +33,9 @@ use std::{mem, ptr};
|
||||||
|
|
||||||
macro_rules! impl_arc_ffi {
|
macro_rules! impl_arc_ffi {
|
||||||
($servo_type:ty => $gecko_type:ty[$addref:ident, $release:ident]) => {
|
($servo_type:ty => $gecko_type:ty[$addref:ident, $release:ident]) => {
|
||||||
unsafe impl HasFFI for $servo_type {
|
unsafe impl HasArcFFI for $servo_type {
|
||||||
type FFIType = $gecko_type;
|
type FFIType = $gecko_type;
|
||||||
}
|
}
|
||||||
unsafe impl HasArcFFI for $servo_type {}
|
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn $addref(obj: &$gecko_type) {
|
pub unsafe extern "C" fn $addref(obj: &$gecko_type) {
|
||||||
|
|
|
@ -11,21 +11,18 @@ use std::mem::{forget, transmute};
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
/// Indicates that a given Servo type has a corresponding Gecko FFI type.
|
|
||||||
pub unsafe trait HasFFI: Sized + 'static {
|
|
||||||
/// The corresponding Gecko type that this rust type represents.
|
|
||||||
///
|
|
||||||
/// See the examples in `components/style/gecko/conversions.rs`.
|
|
||||||
type FFIType: Sized;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Helper trait for conversions between FFI Strong/Borrowed types and Arcs
|
/// Helper trait for conversions between FFI Strong/Borrowed types and Arcs
|
||||||
///
|
///
|
||||||
/// Should be implemented by types which are passed over FFI as Arcs via Strong
|
/// Should be implemented by types which are passed over FFI as Arcs via Strong
|
||||||
/// and Borrowed.
|
/// and Borrowed.
|
||||||
///
|
///
|
||||||
/// In this case, the FFIType is the rough equivalent of ArcInner<Self>.
|
/// In this case, the FFIType is the rough equivalent of ArcInner<Self>.
|
||||||
pub unsafe trait HasArcFFI: HasFFI {
|
pub unsafe trait HasArcFFI: Sized + 'static {
|
||||||
|
/// The corresponding Gecko type that this rust type represents.
|
||||||
|
///
|
||||||
|
/// See the examples in `components/style/gecko/conversions.rs`.
|
||||||
|
type FFIType: Sized;
|
||||||
|
|
||||||
// these methods can't be on Borrowed because it leads to an unspecified
|
// these methods can't be on Borrowed because it leads to an unspecified
|
||||||
// impl parameter
|
// impl parameter
|
||||||
/// Artificially increments the refcount of a (possibly null) borrowed Arc
|
/// Artificially increments the refcount of a (possibly null) borrowed Arc
|
||||||
|
@ -163,26 +160,21 @@ impl<GeckoType> Strong<GeckoType> {
|
||||||
|
|
||||||
/// A few helpers implemented on top of Arc<ServoType> to make it more
|
/// A few helpers implemented on top of Arc<ServoType> to make it more
|
||||||
/// comfortable to use and write safe code with.
|
/// comfortable to use and write safe code with.
|
||||||
pub unsafe trait FFIArcHelpers {
|
pub unsafe trait FFIArcHelpers<T: HasArcFFI> {
|
||||||
/// The Rust FFI type that we're implementing methods for.
|
|
||||||
type Inner: HasArcFFI;
|
|
||||||
|
|
||||||
/// Converts an Arc into a strong FFI reference.
|
/// Converts an Arc into a strong FFI reference.
|
||||||
///
|
///
|
||||||
/// Arc<ServoType> -> Strong<GeckoType>
|
/// Arc<ServoType> -> Strong<GeckoType>
|
||||||
fn into_strong(self) -> Strong<<Self::Inner as HasFFI>::FFIType>;
|
fn into_strong(self) -> Strong<T::FFIType>;
|
||||||
|
|
||||||
/// Produces a borrowed FFI reference by borrowing an Arc.
|
/// Produces a borrowed FFI reference by borrowing an Arc.
|
||||||
///
|
///
|
||||||
/// &Arc<ServoType> -> &GeckoType
|
/// &Arc<ServoType> -> &GeckoType
|
||||||
///
|
///
|
||||||
/// Then the `arc_as_borrowed` method can go away.
|
/// Then the `arc_as_borrowed` method can go away.
|
||||||
fn as_borrowed(&self) -> &<Self::Inner as HasFFI>::FFIType;
|
fn as_borrowed(&self) -> &T::FFIType;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl<T: HasArcFFI> FFIArcHelpers for RawOffsetArc<T> {
|
unsafe impl<T: HasArcFFI> FFIArcHelpers<T> for RawOffsetArc<T> {
|
||||||
type Inner = T;
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn into_strong(self) -> Strong<T::FFIType> {
|
fn into_strong(self) -> Strong<T::FFIType> {
|
||||||
unsafe { transmute(self) }
|
unsafe { transmute(self) }
|
||||||
|
@ -194,9 +186,7 @@ unsafe impl<T: HasArcFFI> FFIArcHelpers for RawOffsetArc<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl<T: HasArcFFI> FFIArcHelpers for Arc<T> {
|
unsafe impl<T: HasArcFFI> FFIArcHelpers<T> for Arc<T> {
|
||||||
type Inner = T;
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn into_strong(self) -> Strong<T::FFIType> {
|
fn into_strong(self) -> Strong<T::FFIType> {
|
||||||
Arc::into_raw_offset(self).into_strong()
|
Arc::into_raw_offset(self).into_strong()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue