mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Explicitly allocate and deallocate our initial computed values.
This allows us to trigger style struct destructors before Gecko's leak checking runs.
This commit is contained in:
parent
9b92d0bc3a
commit
f0f39904a2
3 changed files with 35 additions and 12 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) {
|
||||
|
@ -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:
|
||||
|
|
|
@ -368,6 +368,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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue