Auto merge of #18549 - nnethercote:fix-enclosing-crash, r=heycam

Fix a panic in Stylo memory reporting.

`MallocSizeOfOps::enclosing_size_of_op` is an `Option<>` type, and the panic in
question is caused by not providing a value in a case where it's needed for
measuring a HashSet.

HashMaps and HashSets are common enough that it makes sense to make
`enclosing_size_of_op` non-optional, which this patch does.

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [X] These changes do not require tests because tests are on the Gecko side.

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18549)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-09-17 23:19:54 -05:00 committed by GitHub
commit bb998dbdf3
3 changed files with 20 additions and 11 deletions

View file

@ -781,13 +781,16 @@ pub extern "C" fn Servo_Element_ClearData(element: RawGeckoElementBorrowed) {
#[no_mangle]
pub extern "C" fn Servo_Element_SizeOfExcludingThisAndCVs(malloc_size_of: GeckoMallocSizeOf,
malloc_enclosing_size_of:
GeckoMallocSizeOf,
seen_ptrs: *mut SeenPtrs,
element: RawGeckoElementBorrowed) -> usize {
let element = GeckoElement(element);
let borrow = element.borrow_data();
if let Some(data) = borrow {
let have_seen_ptr = move |ptr| { unsafe { Gecko_HaveSeenPtr(seen_ptrs, ptr) } };
let mut ops = MallocSizeOfOps::new(malloc_size_of.unwrap(), None,
let mut ops = MallocSizeOfOps::new(malloc_size_of.unwrap(),
malloc_enclosing_size_of.unwrap(),
Some(Box::new(have_seen_ptr)));
(*data).size_of_excluding_cvs(&mut ops)
} else {
@ -1087,11 +1090,14 @@ pub extern "C" fn Servo_StyleSheet_Clone(
#[no_mangle]
pub extern "C" fn Servo_StyleSheet_SizeOfIncludingThis(
malloc_size_of: GeckoMallocSizeOf,
malloc_enclosing_size_of: GeckoMallocSizeOf,
sheet: RawServoStyleSheetContentsBorrowed
) -> usize {
let global_style_data = &*GLOBAL_STYLE_DATA;
let guard = global_style_data.shared_lock.read();
let mut ops = MallocSizeOfOps::new(malloc_size_of.unwrap(), None, None);
let mut ops = MallocSizeOfOps::new(malloc_size_of.unwrap(),
malloc_enclosing_size_of.unwrap(),
None);
StylesheetContents::as_arc(&sheet).size_of(&guard, &mut ops)
}
@ -3751,7 +3757,8 @@ pub extern "C" fn Servo_StyleSet_AddSizeOfExcludingThis(
) {
let data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
let mut ops = MallocSizeOfOps::new(malloc_size_of.unwrap(),
malloc_enclosing_size_of, None);
malloc_enclosing_size_of.unwrap(),
None);
let sizes = unsafe { sizes.as_mut() }.unwrap();
data.add_size_of_children(&mut ops, sizes);
}