layout: Stop doing unsafe transmutes between refcell references.

This commit splits the style and layout data in two separate refcells.

These transmutes have been a source of trouble (for example on Android), and
they feel like a hack anyway.

Fixes #16982
This commit is contained in:
Emilio Cobos Álvarez 2017-05-24 19:15:12 +02:00
parent bb310efbb9
commit deaa935f5b
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
9 changed files with 79 additions and 94 deletions

View file

@ -51,35 +51,32 @@ use std::sync::atomic::AtomicIsize;
use style::data::ElementData;
#[repr(C)]
pub struct PartialPersistentLayoutData {
pub struct StyleData {
/// Data that the style system associates with a node. When the
/// style system is being used standalone, this is all that hangs
/// off the node. This must be first to permit the various
/// transmutations between ElementData and PersistentLayoutData.
pub style_data: ElementData,
pub element_data: AtomicRefCell<ElementData>,
/// Information needed during parallel traversals.
pub parallel: DomParallelInfo,
// Required alignment for safe transmutes between PersistentLayoutData and PartialPersistentLayoutData.
_align: [u64; 0]
}
impl PartialPersistentLayoutData {
impl StyleData {
pub fn new() -> Self {
PartialPersistentLayoutData {
style_data: ElementData::new(None),
Self {
element_data: AtomicRefCell::new(ElementData::new(None)),
parallel: DomParallelInfo::new(),
_align: [],
}
}
}
#[derive(Copy, Clone, HeapSizeOf)]
pub struct OpaqueStyleAndLayoutData {
// NB: We really store a `StyleAndLayoutData` here, so be careful!
#[ignore_heap_size_of = "TODO(#6910) Box value that should be counted but \
the type lives in layout"]
pub ptr: NonZero<*mut AtomicRefCell<PartialPersistentLayoutData>>
pub ptr: NonZero<*mut StyleData>
}
#[allow(unsafe_code)]