mirror of
https://github.com/servo/servo.git
synced 2025-08-01 03:30:33 +01:00
style: Simplify Owned FFI types.
And make them actually sound. We're defining functions on Rust-land that get structs as arguments, but declaring them in C++ as getting pointers. This is another step in order to be able to autogenerate ServoBindings.h and remove bindings.rs altogether. We remove FooOwned in favor of Owned<Foo>, which is generated via cbindgen. It'd be good to actually mark Owned and such as MOZ_MUST_USE_TYPE, so I sent https://github.com/eqrion/cbindgen/pull/307 for that. Differential Revision: https://phabricator.services.mozilla.com/D24681
This commit is contained in:
parent
64f19ae34d
commit
02bc29a11b
3 changed files with 20 additions and 44 deletions
|
@ -258,13 +258,6 @@ mod bindings {
|
|||
.collect()
|
||||
}
|
||||
|
||||
fn get_boxed_types() -> Vec<String> {
|
||||
get_types("ServoBoxedTypeList.h", "SERVO_BOXED_TYPE")
|
||||
.into_iter()
|
||||
.map(|(_, type_name)| type_name)
|
||||
.collect()
|
||||
}
|
||||
|
||||
struct BuilderWithConfig<'a> {
|
||||
builder: Builder,
|
||||
config: &'a Table,
|
||||
|
@ -453,22 +446,6 @@ mod bindings {
|
|||
ty
|
||||
));
|
||||
}
|
||||
for ty in get_boxed_types().iter() {
|
||||
builder = builder
|
||||
.blacklist_type(format!("{}Owned", ty))
|
||||
.raw_line(format!(
|
||||
"pub type {0}Owned = ::gecko_bindings::sugar::ownership::Owned<{0}>;",
|
||||
ty
|
||||
))
|
||||
.blacklist_type(format!("{}OwnedOrNull", ty))
|
||||
.raw_line(format!(
|
||||
concat!(
|
||||
"pub type {0}OwnedOrNull = ",
|
||||
"::gecko_bindings::sugar::ownership::OwnedOrNull<{0}>;"
|
||||
),
|
||||
ty
|
||||
));
|
||||
}
|
||||
write_binding_file(builder, BINDINGS_FILE, &fixups);
|
||||
}
|
||||
|
||||
|
|
|
@ -109,6 +109,8 @@ include = [
|
|||
"WillChangeBits",
|
||||
"TextDecorationLine",
|
||||
"MozListReversed",
|
||||
"Owned",
|
||||
"OwnedOrNull",
|
||||
]
|
||||
item_types = ["enums", "structs", "typedefs"]
|
||||
|
||||
|
@ -208,3 +210,21 @@ item_types = ["enums", "structs", "typedefs"]
|
|||
static inline StyleRestyleHint RecascadeSubtree();
|
||||
static inline StyleRestyleHint ForAnimations();
|
||||
"""
|
||||
|
||||
# TODO(emilio): Add hooks to cbindgen to be able to generate MOZ_MUST_USE_TYPE
|
||||
# or MOZ_MUST_USE on the functions.
|
||||
"Owned" = """
|
||||
UniquePtr<GeckoType> Consume() {
|
||||
UniquePtr<GeckoType> ret(ptr);
|
||||
ptr = nullptr;
|
||||
return ret;
|
||||
}
|
||||
"""
|
||||
|
||||
"OwnedOrNull" = """
|
||||
UniquePtr<GeckoType> Consume() {
|
||||
UniquePtr<GeckoType> ret(ptr);
|
||||
ptr = nullptr;
|
||||
return ret;
|
||||
}
|
||||
"""
|
||||
|
|
|
@ -320,27 +320,6 @@ impl<GeckoType> OwnedOrNull<GeckoType> {
|
|||
self.ptr.is_null()
|
||||
}
|
||||
|
||||
/// Returns an owned pointer if this is non-null, and `None` otherwise.
|
||||
pub fn into_box_opt<ServoType>(self) -> Option<Box<ServoType>>
|
||||
where
|
||||
ServoType: HasBoxFFI<FFIType = GeckoType>,
|
||||
{
|
||||
if self.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(unsafe { transmute(self) })
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns an `Owned<GeckoType>` if non-null, `None` otherwise.
|
||||
pub fn into_owned_opt(self) -> Option<Owned<GeckoType>> {
|
||||
if self.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(unsafe { transmute(self) })
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets a immutable reference to the underlying Gecko type, or `None` if
|
||||
/// null.
|
||||
pub fn borrow(&self) -> Option<&GeckoType> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue