Skip to content

Commit

Permalink
Move DUMMY_URL_DATA to glue and use static to avoid shutdown leak.
Browse files Browse the repository at this point in the history
  • Loading branch information
upsuper committed Apr 3, 2017
1 parent 806d73e commit 3d483a9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
14 changes: 1 addition & 13 deletions components/style/gecko/wrapper.rs
Expand Up @@ -41,15 +41,14 @@ use gecko_bindings::bindings::Gecko_IsSignificantChild;
use gecko_bindings::bindings::Gecko_MatchStringArgPseudo;
use gecko_bindings::bindings::Gecko_UpdateAnimations;
use gecko_bindings::structs;
use gecko_bindings::structs::{RawGeckoElement, RawGeckoNode, URLExtraData};
use gecko_bindings::structs::{RawGeckoElement, RawGeckoNode};
use gecko_bindings::structs::{nsIAtom, nsIContent, nsStyleContext};
use gecko_bindings::structs::EffectCompositor_CascadeLevel as CascadeLevel;
use gecko_bindings::structs::NODE_HAS_ANIMATION_ONLY_DIRTY_DESCENDANTS_FOR_SERVO;
use gecko_bindings::structs::NODE_HAS_DIRTY_DESCENDANTS_FOR_SERVO;
use gecko_bindings::structs::NODE_IS_IN_NATIVE_ANONYMOUS_SUBTREE;
use gecko_bindings::structs::NODE_IS_NATIVE_ANONYMOUS;
use gecko_bindings::sugar::ownership::HasArcFFI;
use gecko_bindings::sugar::refptr::RefPtr;
use parking_lot::RwLock;
use properties::{ComputedValues, parse_style_attribute};
use properties::PropertyDeclarationBlock;
Expand Down Expand Up @@ -388,17 +387,6 @@ impl<'le> GeckoElement<'le> {
}
}

lazy_static! {
/// A dummy url data in order to get it where we don't have any available.
///
/// We need to get rid of this sooner than later.
pub static ref DUMMY_URL_DATA: RefPtr<URLExtraData> = {
unsafe {
RefPtr::from_addrefed(bindings::Gecko_URLExtraData_CreateDummy())
}
};
}

/// Converts flags from the layout used by rust-selectors to the layout used
/// by Gecko. We could align these and then do this without conditionals, but
/// it's probably not worth the trouble.
Expand Down
25 changes: 19 additions & 6 deletions ports/geckolib/glue.rs
Expand Up @@ -25,7 +25,6 @@ use style::gecko::global_style_data::GLOBAL_STYLE_DATA;
use style::gecko::restyle_damage::GeckoRestyleDamage;
use style::gecko::selector_parser::{SelectorImpl, PseudoElement};
use style::gecko::traversal::RecalcStyleOnly;
use style::gecko::wrapper::DUMMY_URL_DATA;
use style::gecko::wrapper::GeckoElement;
use style::gecko_bindings::bindings;
use style::gecko_bindings::bindings::{RawGeckoKeyframeListBorrowed, RawGeckoKeyframeListBorrowedMut};
Expand Down Expand Up @@ -97,7 +96,9 @@ use super::stylesheet_loader::StylesheetLoader;
* depend on but good enough for our purposes.
*/


// A dummy url data for where we don't pass url data in.
// We need to get rid of this sooner than later.
static mut DUMMY_URL_DATA: Option<*mut URLExtraData> = None;

#[no_mangle]
pub extern "C" fn Servo_Initialize() {
Expand All @@ -117,12 +118,24 @@ pub extern "C" fn Servo_Initialize() {

// Initialize some static data.
gecko_properties::initialize();

// Initialize the dummy url data
unsafe {
DUMMY_URL_DATA = Some(bindings::Gecko_URLExtraData_CreateDummy());
}
}

#[no_mangle]
pub extern "C" fn Servo_Shutdown() {
// Clear some static data to avoid shutdown leaks.
gecko_properties::shutdown();

// Clear the dummy url data to avoid shutdown leaks.
unsafe { RefPtr::from_addrefed(DUMMY_URL_DATA.take().unwrap()) };
}

unsafe fn dummy_url_data() -> &'static RefPtr<URLExtraData> {
RefPtr::from_ptr_ref(DUMMY_URL_DATA.as_ref().unwrap())
}

fn create_shared_context<'a>(guard: &'a SharedRwLockReadGuard,
Expand Down Expand Up @@ -317,8 +330,8 @@ pub extern "C" fn Servo_StyleSheet_Empty(mode: SheetParsingMode) -> RawServoStyl
};
let shared_lock = global_style_data.shared_lock.clone();
Arc::new(Stylesheet::from_str(
"", DUMMY_URL_DATA.clone(), origin, Default::default(),
shared_lock, None, &StdoutErrorReporter)
"", unsafe { dummy_url_data() }.clone(), origin,
Default::default(), shared_lock, None, &StdoutErrorReporter)
).into_strong()
}

Expand Down Expand Up @@ -1335,7 +1348,7 @@ pub extern "C" fn Servo_CSSSupports2(property: *const nsACString, value: *const
};
let value = unsafe { value.as_ref().unwrap().as_str_unchecked() };

let url_data = &*DUMMY_URL_DATA;
let url_data = unsafe { dummy_url_data() };
parse_one_declaration(id, &value, url_data, &StdoutErrorReporter).is_ok()
}

Expand All @@ -1345,7 +1358,7 @@ pub extern "C" fn Servo_CSSSupports(cond: *const nsACString) -> bool {
let mut input = Parser::new(&condition);
let cond = parse_condition_or_declaration(&mut input);
if let Ok(cond) = cond {
let url_data = &*DUMMY_URL_DATA;
let url_data = unsafe { dummy_url_data() };
let reporter = StdoutErrorReporter;
let context = ParserContext::new_for_cssom(url_data, &reporter);
cond.eval(&context)
Expand Down

0 comments on commit 3d483a9

Please sign in to comment.