mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Auto merge of #12725 - bholley:fix_leaks, r=emilio
stylo: fix leaks, and accept null in Servo_InheritComputedValues This corresponds to changes in: https://bugzilla.mozilla.org/show_bug.cgi?id=1291885 and https://bugzilla.mozilla.org/show_bug.cgi?id=1291891 <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12725) <!-- Reviewable:end -->
This commit is contained in:
commit
939e0a5f89
4 changed files with 47 additions and 21 deletions
|
@ -100,7 +100,30 @@ impl ComputedValues {
|
|||
ComputedValues::inherit_from(parent)
|
||||
}
|
||||
|
||||
pub fn initial_values() -> &'static Self { &*INITIAL_GECKO_VALUES }
|
||||
pub fn initial_values() -> &'static Self {
|
||||
unsafe {
|
||||
debug_assert!(!INITIAL_GECKO_VALUES.is_null());
|
||||
&*INITIAL_GECKO_VALUES
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn initialize() {
|
||||
debug_assert!(INITIAL_GECKO_VALUES.is_null());
|
||||
INITIAL_GECKO_VALUES = Box::into_raw(Box::new(ComputedValues {
|
||||
% for style_struct in data.style_structs:
|
||||
${style_struct.ident}: style_structs::${style_struct.name}::initial(),
|
||||
% endfor
|
||||
custom_properties: None,
|
||||
shareable: true,
|
||||
writing_mode: WritingMode::empty(),
|
||||
root_font_size: longhands::font_size::get_initial_value(),
|
||||
}));
|
||||
}
|
||||
|
||||
pub unsafe fn shutdown() {
|
||||
debug_assert!(!INITIAL_GECKO_VALUES.is_null());
|
||||
let _ = Box::from_raw(INITIAL_GECKO_VALUES);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn do_cascade_property<F: FnOnce(&[CascadePropertyFn])>(f: F) {
|
||||
|
@ -236,7 +259,7 @@ def set_gecko_property(ffi_name, expr):
|
|||
// In the longer term, Gecko should store currentColor as a computed
|
||||
// value, so that we don't need to do this:
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=760345
|
||||
unimplemented!();
|
||||
warn!("stylo: mishandling currentColor");
|
||||
% endif
|
||||
</%def>
|
||||
|
||||
|
@ -1338,17 +1361,7 @@ ${impl_style_struct(style_struct)}
|
|||
${define_ffi_struct_accessor(style_struct)}
|
||||
% endfor
|
||||
|
||||
lazy_static! {
|
||||
pub static ref INITIAL_GECKO_VALUES: ComputedValues = ComputedValues {
|
||||
% for style_struct in data.style_structs:
|
||||
${style_struct.ident}: style_structs::${style_struct.name}::initial(),
|
||||
% endfor
|
||||
custom_properties: None,
|
||||
shareable: true,
|
||||
writing_mode: WritingMode::empty(),
|
||||
root_font_size: longhands::font_size::get_initial_value(),
|
||||
};
|
||||
}
|
||||
static mut INITIAL_GECKO_VALUES: *mut ComputedValues = 0 as *mut ComputedValues;
|
||||
|
||||
static CASCADE_PROPERTY: [CascadePropertyFn; ${len(data.longhands)}] = [
|
||||
% for property in data.longhands:
|
||||
|
|
|
@ -375,6 +375,7 @@ extern "C" {
|
|||
pub fn Servo_AddRefComputedValues(arg1: *mut ServoComputedValues);
|
||||
pub fn Servo_ReleaseComputedValues(arg1: *mut ServoComputedValues);
|
||||
pub fn Servo_Initialize();
|
||||
pub fn Servo_Shutdown();
|
||||
pub fn Servo_RestyleDocument(doc: *mut RawGeckoDocument,
|
||||
set: *mut RawServoStyleSet);
|
||||
pub fn Servo_RestyleSubtree(node: *mut RawGeckoNode,
|
||||
|
|
|
@ -76,6 +76,15 @@ pub extern "C" fn Servo_Initialize() -> () {
|
|||
//
|
||||
// See https://doc.rust-lang.org/log/env_logger/index.html for instructions.
|
||||
env_logger::init().unwrap();
|
||||
|
||||
// Allocate our default computed values.
|
||||
unsafe { ComputedValues::initialize(); }
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn Servo_Shutdown() -> () {
|
||||
// Destroy our default computed values.
|
||||
unsafe { ComputedValues::shutdown(); }
|
||||
}
|
||||
|
||||
fn restyle_subtree(node: GeckoNode, raw_data: *mut RawServoStyleSet) {
|
||||
|
@ -355,10 +364,12 @@ pub extern "C" fn Servo_GetComputedValuesForPseudoElement(parent_style: *mut Ser
|
|||
pub extern "C" fn Servo_InheritComputedValues(parent_style: *mut ServoComputedValues)
|
||||
-> *mut ServoComputedValues {
|
||||
type Helpers = ArcHelpers<ServoComputedValues, ComputedValues>;
|
||||
Helpers::with(parent_style, |parent| {
|
||||
let style = ComputedValues::inherit_from(parent);
|
||||
Helpers::from(style)
|
||||
})
|
||||
let style = if parent_style.is_null() {
|
||||
Arc::new(ComputedValues::initial_values().clone())
|
||||
} else {
|
||||
Helpers::with(parent_style, ComputedValues::inherit_from)
|
||||
};
|
||||
Helpers::from(style)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
|
|
@ -53,7 +53,8 @@ use style::selector_impl::ElementExt;
|
|||
use style::sink::Push;
|
||||
use url::Url;
|
||||
|
||||
pub type NonOpaqueStyleData = *mut RefCell<PrivateStyleData>;
|
||||
pub type NonOpaqueStyleData = RefCell<PrivateStyleData>;
|
||||
pub type NonOpaqueStyleDataPtr = *mut NonOpaqueStyleData;
|
||||
|
||||
// Important: We don't currently refcount the DOM, because the wrapper lifetime
|
||||
// magic guarantees that our LayoutFoo references won't outlive the root, and
|
||||
|
@ -78,16 +79,16 @@ impl<'ln> GeckoNode<'ln> {
|
|||
GeckoNode::from_raw(n as *const RawGeckoNode as *mut RawGeckoNode)
|
||||
}
|
||||
|
||||
fn get_node_data(&self) -> NonOpaqueStyleData {
|
||||
fn get_node_data(&self) -> NonOpaqueStyleDataPtr {
|
||||
unsafe {
|
||||
Gecko_GetNodeData(self.node) as NonOpaqueStyleData
|
||||
Gecko_GetNodeData(self.node) as NonOpaqueStyleDataPtr
|
||||
}
|
||||
}
|
||||
|
||||
pub fn initialize_data(self) {
|
||||
unsafe {
|
||||
if self.get_node_data().is_null() {
|
||||
let ptr: NonOpaqueStyleData = Box::into_raw(Box::new(RefCell::new(PrivateStyleData::new())));
|
||||
let ptr: NonOpaqueStyleDataPtr = Box::into_raw(Box::new(RefCell::new(PrivateStyleData::new())));
|
||||
Gecko_SetNodeData(self.node, ptr as *mut ServoNodeData);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue