mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
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:
parent
bb310efbb9
commit
deaa935f5b
9 changed files with 79 additions and 94 deletions
|
@ -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)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue