[librsvg] AcquiredNodes: Use a Rc<...> instead of a raw pointer into the Vec of acquired nodes



commit c647b691c72eb6f3817d216b1e68e30fe873a932
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Sep 19 09:23:51 2018 -0500

    AcquiredNodes: Use a Rc<...> instead of a raw pointer into the Vec of acquired nodes
    
    Similar to how the view_box_stack is done.

 rsvg_internals/src/drawing_ctx.rs | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
---
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index a8d62f23..0b4ab218 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -129,7 +129,7 @@ pub struct DrawingCtx<'a> {
     drawsub_stack: Vec<RsvgNode>,
 
     defs: RefCell<&'a mut Defs>,
-    acquired_nodes: RefCell<Vec<RsvgNode>>,
+    acquired_nodes: Rc<RefCell<Vec<RsvgNode>>>,
 
     is_testing: bool,
 }
@@ -183,7 +183,7 @@ impl<'a> DrawingCtx<'a> {
             bbox_stack: Vec::new(),
             drawsub_stack: Vec::new(),
             defs: RefCell::new(defs),
-            acquired_nodes: RefCell::new(Vec::new()),
+            acquired_nodes: Rc::new(RefCell::new(Vec::new())),
             is_testing,
         }
     }
@@ -290,7 +290,7 @@ impl<'a> DrawingCtx<'a> {
         if let Some(node) = self.defs.borrow_mut().lookup(url) {
             if !self.acquired_nodes_contains(node) {
                 self.acquired_nodes.borrow_mut().push(node.clone());
-                return Some(AcquiredNode(&self.acquired_nodes as *const _, node.clone()));
+                return Some(AcquiredNode(self.acquired_nodes.clone(), node.clone()));
             }
         }
 
@@ -1107,15 +1107,13 @@ pub extern "C" fn rsvg_drawing_ctx_get_ink_rect(
     res.to_glib()
 }
 
-pub struct AcquiredNode(*const RefCell<Vec<RsvgNode>>, RsvgNode);
+pub struct AcquiredNode(Rc<RefCell<Vec<RsvgNode>>>, RsvgNode);
 
 impl Drop for AcquiredNode {
     fn drop(&mut self) {
-        unsafe {
-            let mut v = (*self.0).borrow_mut();
-            assert!(Rc::ptr_eq(v.last().unwrap(), &self.1));
-            v.pop();
-        }
+        let mut v = self.0.borrow_mut();
+        assert!(Rc::ptr_eq(v.last().unwrap(), &self.1));
+        v.pop();
     }
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]