Bug 1304792: Use borrowed types for ServoImportRule. r=Manishearth r=heycam

MozReview-Commit-ID: HKjsOaE2qAp
Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
This commit is contained in:
Emilio Cobos Álvarez 2016-12-29 18:33:47 +01:00
parent a5f5e48c68
commit df9da705f5
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
3 changed files with 9 additions and 3 deletions

View file

@ -330,7 +330,7 @@ extern "C" {
extern "C" { extern "C" {
pub fn Gecko_LoadStyleSheet(loader: *mut Loader, pub fn Gecko_LoadStyleSheet(loader: *mut Loader,
parent: *mut ServoStyleSheet, parent: *mut ServoStyleSheet,
import_rule: RawServoImportRuleStrong, import_rule: RawServoImportRuleBorrowed,
url_bytes: *const u8, url_length: u32, url_bytes: *const u8, url_length: u32,
media_bytes: *const u8, media_length: u32); media_bytes: *const u8, media_length: u32);
} }

View file

@ -109,6 +109,12 @@ pub unsafe trait HasArcFFI : HasFFI {
} }
} }
fn arc_as_borrowed<'a>(arc: &'a Arc<Self>) -> &'a &Self::FFIType {
unsafe {
transmute::<&Arc<Self>, &&Self::FFIType>(arc)
}
}
#[inline] #[inline]
fn arc_from_borrowed<'a>(ptr: &'a Option<&Self::FFIType>) -> Option<&'a Arc<Self>> { fn arc_from_borrowed<'a>(ptr: &'a Option<&Self::FFIType>) -> Option<&'a Arc<Self>> {
unsafe { unsafe {

View file

@ -3,10 +3,10 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use parking_lot::RwLock; use parking_lot::RwLock;
use std::mem;
use std::sync::Arc; use std::sync::Arc;
use style::gecko_bindings::bindings::Gecko_LoadStyleSheet; use style::gecko_bindings::bindings::Gecko_LoadStyleSheet;
use style::gecko_bindings::structs::{Loader, ServoStyleSheet}; use style::gecko_bindings::structs::{Loader, ServoStyleSheet};
use style::gecko_bindings::sugar::ownership::HasArcFFI;
use style::stylesheets::{ImportRule, StylesheetLoader as StyleStylesheetLoader}; use style::stylesheets::{ImportRule, StylesheetLoader as StyleStylesheetLoader};
use style_traits::ToCss; use style_traits::ToCss;
@ -37,7 +37,7 @@ impl StyleStylesheetLoader for StylesheetLoader {
unsafe { unsafe {
Gecko_LoadStyleSheet(self.0, Gecko_LoadStyleSheet(self.0,
self.1, self.1,
mem::transmute(import_rule.clone()), HasArcFFI::arc_as_borrowed(import_rule),
spec_bytes, spec_bytes,
spec_len as u32, spec_len as u32,
media.as_bytes().as_ptr(), media.as_bytes().as_ptr(),