mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
style: Cleanup refcounted types.
And make the handling of ComputedStyle more similar to these. Differential Revision: https://phabricator.services.mozilla.com/D24703
This commit is contained in:
parent
02bc29a11b
commit
ecda72a5fd
4 changed files with 11 additions and 76 deletions
|
@ -220,44 +220,6 @@ mod bindings {
|
|||
.expect("Unable to write output");
|
||||
}
|
||||
|
||||
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).expect(&format!("Unable to open {}", filename));
|
||||
let mut content = String::new();
|
||||
list_file
|
||||
.read_to_string(&mut content)
|
||||
.expect(&format!("Failed to read {}", filename));
|
||||
// Remove comments
|
||||
let block_comment_re = Regex::new(r#"(?s)/\*.*?\*/"#).unwrap();
|
||||
let line_comment_re = Regex::new(r#"//.*"#).unwrap();
|
||||
let content = block_comment_re.replace_all(&content, "");
|
||||
let content = line_comment_re.replace_all(&content, "");
|
||||
// Extract the list
|
||||
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| {
|
||||
let captures = re
|
||||
.captures(&line)
|
||||
.expect(&format!("Unrecognized line in {}: '{}'", filename, line));
|
||||
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_arc_types() -> Vec<String> {
|
||||
get_types("ServoArcTypeList.h", "SERVO_ARC_TYPE")
|
||||
.into_iter()
|
||||
.map(|(_, type_name)| type_name)
|
||||
.collect()
|
||||
}
|
||||
|
||||
struct BuilderWithConfig<'a> {
|
||||
builder: Builder,
|
||||
config: &'a Table,
|
||||
|
@ -434,18 +396,10 @@ mod bindings {
|
|||
.with_codegen_config(CodegenConfig::FUNCTIONS);
|
||||
let config = CONFIG["bindings"].as_table().unwrap();
|
||||
let mut fixups = vec![];
|
||||
let mut builder = BuilderWithConfig::new(builder, config)
|
||||
let builder = BuilderWithConfig::new(builder, config)
|
||||
.handle_common(&mut fixups)
|
||||
.handle_str_items("whitelist-functions", |b, item| b.whitelist_function(item))
|
||||
.get_builder();
|
||||
for ty in get_arc_types().iter() {
|
||||
builder = builder
|
||||
.blacklist_type(format!("{}Strong", ty))
|
||||
.raw_line(format!(
|
||||
"pub type {0}Strong = ::gecko_bindings::sugar::ownership::Strong<{0}>;",
|
||||
ty
|
||||
));
|
||||
}
|
||||
write_binding_file(builder, BINDINGS_FILE, &fixups);
|
||||
}
|
||||
|
||||
|
|
|
@ -111,6 +111,7 @@ include = [
|
|||
"MozListReversed",
|
||||
"Owned",
|
||||
"OwnedOrNull",
|
||||
"Strong",
|
||||
]
|
||||
item_types = ["enums", "structs", "typedefs"]
|
||||
|
||||
|
@ -228,3 +229,11 @@ item_types = ["enums", "structs", "typedefs"]
|
|||
return ret;
|
||||
}
|
||||
"""
|
||||
|
||||
"Strong" = """
|
||||
already_AddRefed<GeckoType> Consume() {
|
||||
already_AddRefed<GeckoType> ret(const_cast<GeckoType*>(ptr));
|
||||
ptr = nullptr;
|
||||
return ret;
|
||||
}
|
||||
"""
|
||||
|
|
|
@ -18,8 +18,6 @@ use crate::gecko_bindings::structs::RawServoMediaRule;
|
|||
use crate::gecko_bindings::structs::RawServoMozDocumentRule;
|
||||
use crate::gecko_bindings::structs::RawServoNamespaceRule;
|
||||
use crate::gecko_bindings::structs::RawServoPageRule;
|
||||
use crate::gecko_bindings::structs::RawServoRuleNode;
|
||||
use crate::gecko_bindings::structs::RawServoRuleNodeStrong;
|
||||
use crate::gecko_bindings::structs::RawServoSupportsRule;
|
||||
use crate::gecko_bindings::structs::ServoCssRules;
|
||||
use crate::gecko_bindings::structs::RawServoAnimationValue;
|
||||
|
@ -34,7 +32,6 @@ use crate::gecko_bindings::sugar::ownership::{HasArcFFI, HasFFI, Strong};
|
|||
use crate::media_queries::MediaList;
|
||||
use crate::properties::animated_properties::AnimationValue;
|
||||
use crate::properties::{ComputedValues, PropertyDeclarationBlock};
|
||||
use crate::rule_tree::StrongRuleNode;
|
||||
use crate::shared_lock::Locked;
|
||||
use crate::stylesheets::keyframes_rule::Keyframe;
|
||||
use crate::stylesheets::{CounterStyleRule, CssRules, FontFaceRule, FontFeatureValuesRule};
|
||||
|
@ -121,31 +118,6 @@ impl_arc_ffi!(CssUrlData => RawServoCssUrlData
|
|||
impl_arc_ffi!(Box<[QuotePair]> => RawServoQuotes
|
||||
[Servo_Quotes_AddRef, Servo_Quotes_Release]);
|
||||
|
||||
// RuleNode is a Arc-like type but it does not use Arc.
|
||||
|
||||
impl StrongRuleNode {
|
||||
pub fn into_strong(self) -> RawServoRuleNodeStrong {
|
||||
let ptr = self.ptr();
|
||||
mem::forget(self);
|
||||
unsafe { mem::transmute(ptr) }
|
||||
}
|
||||
|
||||
pub fn from_ffi<'a>(ffi: &'a &RawServoRuleNode) -> &'a Self {
|
||||
unsafe { &*(ffi as *const &RawServoRuleNode as *const StrongRuleNode) }
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn Servo_RuleNode_AddRef(obj: &RawServoRuleNode) {
|
||||
mem::forget(StrongRuleNode::from_ffi(&obj).clone());
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn Servo_RuleNode_Release(obj: &RawServoRuleNode) {
|
||||
let ptr = StrongRuleNode::from_ffi(&obj);
|
||||
ptr::read(ptr as *const StrongRuleNode);
|
||||
}
|
||||
|
||||
// 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
|
||||
|
|
|
@ -135,12 +135,12 @@ pub unsafe trait HasArcFFI: HasFFI {
|
|||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
/// Gecko-FFI-safe Arc (T is an ArcInner).
|
||||
///
|
||||
/// This can be null.
|
||||
///
|
||||
/// Leaks on drop. Please don't drop this.
|
||||
#[repr(C)]
|
||||
pub struct Strong<GeckoType> {
|
||||
ptr: *const GeckoType,
|
||||
_marker: PhantomData<GeckoType>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue