diff --git a/components/style/build_gecko.rs b/components/style/build_gecko.rs index a30a2a8aeb8..c8e886c4b29 100644 --- a/components/style/build_gecko.rs +++ b/components/style/build_gecko.rs @@ -300,7 +300,7 @@ mod bindings { .expect("Unable to write output"); } - fn get_types(filename: &str, macro_name: &str) -> Vec { + fn get_types(filename: &str, macro_pat: &str) -> Vec<(String, String)> { // Read the file let path = DISTDIR_PATH.join("include/mozilla/").join(filename); let mut list_file = File::open(path) @@ -315,31 +315,46 @@ mod bindings { let content = block_comment_re.replace_all(&content, ""); let content = line_comment_re.replace_all(&content, ""); // Extract the list - let re_string = format!(r#"^{}\(\w+,\s*(\w+)\)$"#, macro_name); + let re_string = format!(r#"^({})\(.+,\s*(\w+)\)$"#, macro_pat); let re = Regex::new(&re_string).unwrap(); content .lines() .map(|line| line.trim()) .filter(|line| !line.is_empty()) .map(|line| { - re.captures(&line) + let captures = re.captures(&line) .expect(&format!( "Unrecognized line in {}: '{}'", filename, line - )).get(1) - .unwrap() - .as_str() - .to_string() + )); + let macro_name = captures.get(1).unwrap().as_str().to_string(); + let type_name = captures.get(2).unwrap().as_str().to_string(); + (macro_name, type_name) }).collect() } + fn get_borrowed_types() -> Vec<(bool, String)> { + get_types("BorrowedTypeList.h", "GECKO_BORROWED_TYPE(?:_MUT)?") + .into_iter() + .map(|(macro_name, type_name)| { + (macro_name.ends_with("MUT"), type_name) + }) + .collect() + } + fn get_arc_types() -> Vec { get_types("ServoArcTypeList.h", "SERVO_ARC_TYPE") + .into_iter() + .map(|(_, type_name)| type_name) + .collect() } fn get_boxed_types() -> Vec { get_types("ServoBoxedTypeList.h", "SERVO_BOXED_TYPE") + .into_iter() + .map(|(_, type_name)| type_name) + .collect() } struct BuilderWithConfig<'a> { @@ -544,6 +559,13 @@ mod bindings { // which _do_ need to be opaque, we'll need a separate mode. .handle_str_items("servo-borrow-types", |b, ty| b.mutable_borrowed_type(ty)) .get_builder(); + for (is_mut, ty) in get_borrowed_types().iter() { + if *is_mut { + builder = builder.mutable_borrowed_type(ty); + } else { + builder = builder.borrowed_type(ty); + } + } for ty in get_arc_types().iter() { builder = builder .blacklist_type(format!("{}Strong", ty)) diff --git a/components/style/gecko/data.rs b/components/style/gecko/data.rs index d737167c28a..2ede2f5b81f 100644 --- a/components/style/gecko/data.rs +++ b/components/style/gecko/data.rs @@ -8,7 +8,7 @@ use atomic_refcell::{AtomicRef, AtomicRefCell, AtomicRefMut}; use context::QuirksMode; use dom::TElement; use gecko_bindings::bindings::{self, RawServoStyleSet}; -use gecko_bindings::structs::{RawGeckoPresContextOwned, ServoStyleSetSizes, StyleSheet as DomStyleSheet}; +use gecko_bindings::structs::{RawGeckoPresContextBorrowed, ServoStyleSetSizes, StyleSheet as DomStyleSheet}; use gecko_bindings::structs::{StyleSheetInfo, nsIDocument}; use gecko_bindings::sugar::ownership::{HasArcFFI, HasBoxFFI, HasFFI, HasSimpleFFI}; use invalidation::media_queries::{MediaListKey, ToMediaListKey}; @@ -143,7 +143,7 @@ pub struct PerDocumentStyleData(AtomicRefCell); impl PerDocumentStyleData { /// Create a dummy `PerDocumentStyleData`. - pub fn new(pres_context: RawGeckoPresContextOwned) -> Self { + pub fn new(pres_context: RawGeckoPresContextBorrowed) -> Self { let device = Device::new(pres_context); // FIXME(emilio, tlin): How is this supposed to work with XBL? This is diff --git a/components/style/gecko/media_queries.rs b/components/style/gecko/media_queries.rs index 65855b0a8a3..d95c8df7028 100644 --- a/components/style/gecko/media_queries.rs +++ b/components/style/gecko/media_queries.rs @@ -12,7 +12,7 @@ use euclid::TypedScale; use gecko::values::{convert_nscolor_to_rgba, convert_rgba_to_nscolor}; use gecko_bindings::bindings; use gecko_bindings::structs; -use gecko_bindings::structs::{nsPresContext, RawGeckoPresContextOwned}; +use gecko_bindings::structs::{nsPresContext, RawGeckoPresContextBorrowed}; use media_queries::MediaType; use properties::ComputedValues; use servo_arc::Arc; @@ -30,7 +30,7 @@ pub struct Device { /// NB: The pres context lifetime is tied to the styleset, who owns the /// stylist, and thus the `Device`, so having a raw pres context pointer /// here is fine. - pres_context: RawGeckoPresContextOwned, + pres_context: RawGeckoPresContextBorrowed, default_values: Arc, /// The font size of the root element /// This is set when computing the style of the root @@ -77,7 +77,7 @@ unsafe impl Send for Device {} impl Device { /// Trivially constructs a new `Device`. - pub fn new(pres_context: RawGeckoPresContextOwned) -> Self { + pub fn new(pres_context: RawGeckoPresContextBorrowed) -> Self { assert!(!pres_context.is_null()); Device { pres_context,