[librsvg] ViewParams: keep a Weak reference to the view box stack, not a strong one
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] ViewParams: keep a Weak reference to the view box stack, not a strong one
- Date: Wed, 12 Sep 2018 11:54:23 +0000 (UTC)
commit 20e8a3b3095ce6e26158c7e8f110a052d4c99262
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Sep 5 12:10:02 2018 -0500
ViewParams: keep a Weak reference to the view box stack, not a strong one
This lets us be extra-paranoid about not dropping a ViewParams after
the corresponding DrawingCtx has been dropped.
rsvg_internals/src/drawing_ctx.rs | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
---
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index 60a7ad92..3c45f488 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -9,7 +9,7 @@ use pango_cairo_sys;
use pango_sys;
use pangocairo;
use std::cell::RefCell;
-use std::rc::Rc;
+use std::rc::{Rc, Weak};
use bbox::BoundingBox;
use clip_path::{ClipPathUnits, NodeClipPath};
@@ -53,7 +53,7 @@ pub struct ViewParams {
dpi_y: f64,
view_box_width: f64,
view_box_height: f64,
- view_box_stack: Option<Rc<RefCell<Vec<ViewBox>>>>,
+ view_box_stack: Option<Weak<RefCell<Vec<ViewBox>>>>,
}
impl ViewParams {
@@ -87,7 +87,10 @@ impl ViewParams {
impl Drop for ViewParams {
fn drop(&mut self) {
- if let Some(ref stack) = self.view_box_stack {
+ if let Some(ref weak_stack) = self.view_box_stack {
+ let stack = weak_stack
+ .upgrade()
+ .expect("A ViewParams was dropped after its DrawingCtx!?");
stack.borrow_mut().pop();
}
}
@@ -258,7 +261,7 @@ impl<'a> DrawingCtx<'a> {
dpi_y: self.dpi_y,
view_box_width: width,
view_box_height: height,
- view_box_stack: Some(self.view_box_stack.clone()),
+ view_box_stack: Some(Rc::downgrade(&self.view_box_stack)),
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]