Move dummy url data to be a static member of URLExtraData.

This commit is contained in:
Xidorn Quan 2017-04-07 09:50:57 +10:00
parent 3beaa8d2e9
commit 2820b7ac53
4 changed files with 7 additions and 14 deletions

2
Cargo.lock generated
View file

@ -2787,12 +2787,10 @@ dependencies = [
"env_logger 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"geckoservo 0.0.1",
"lazy_static 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.18.0",
"servo_url 0.0.1",
"style 0.0.1",
"style_traits 0.0.1",
]

View file

@ -100,10 +100,10 @@ use super::stylesheet_loader::StylesheetLoader;
// 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;
static mut DUMMY_URL_DATA: *mut URLExtraData = 0 as *mut URLExtraData;
#[no_mangle]
pub extern "C" fn Servo_Initialize() {
pub extern "C" fn Servo_Initialize(dummy_url_data: *mut URLExtraData) {
// Initialize logging.
let mut builder = LogBuilder::new();
let default_level = if cfg!(debug_assertions) { "warn" } else { "error" };
@ -122,9 +122,7 @@ pub extern "C" fn Servo_Initialize() {
gecko_properties::initialize();
// Initialize the dummy url data
unsafe {
DUMMY_URL_DATA = Some(bindings::Gecko_URLExtraData_CreateDummy());
}
unsafe { DUMMY_URL_DATA = dummy_url_data; }
}
#[no_mangle]
@ -132,12 +130,13 @@ 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()) };
// The dummy url will be released after shutdown, so clear the
// reference to avoid use-after-free.
unsafe { DUMMY_URL_DATA = ptr::null_mut(); }
}
unsafe fn dummy_url_data() -> &'static RefPtr<URLExtraData> {
RefPtr::from_ptr_ref(DUMMY_URL_DATA.as_ref().unwrap())
RefPtr::from_ptr_ref(&DUMMY_URL_DATA)
}
fn create_shared_context<'a>(guard: &'a SharedRwLockReadGuard,

View file

@ -19,12 +19,10 @@ atomic_refcell = "0.1"
cssparser = "0.12"
env_logger = "0.4"
euclid = "0.11"
lazy_static = "0.2"
libc = "0.2"
log = {version = "0.3.5", features = ["release_max_level_info"]}
parking_lot = "0.3"
selectors = {path = "../../../components/selectors"}
servo_url = {path = "../../../components/url"}
style_traits = {path = "../../../components/style_traits"}
geckoservo = {path = "../../../ports/geckolib"}
style = {path = "../../../components/style", features = ["gecko"]}

View file

@ -6,11 +6,9 @@ extern crate atomic_refcell;
extern crate cssparser;
extern crate env_logger;
extern crate geckoservo;
#[macro_use] extern crate lazy_static;
#[macro_use] extern crate log;
extern crate parking_lot;
extern crate selectors;
extern crate servo_url;
#[macro_use] extern crate style;
extern crate style_traits;