Skip to content
  • Federico Mena Quintero's avatar
    node.rs: Implement rsvg_node_ref() and rsvg_node_unref() · 2477434b
    Federico Mena Quintero authored
    In Rust, we have Rc<Node> for the main refcounted node struct.
    
    We export that to C by boxing as Box<Rc<Node>>, since an Rc<Node>
    normally lives in the stack - that is, the Rc is in the stack, and the
    Node and its refcount are in the heap.
    
    When we ref() a node, we return a new Box:
    
      Box::into_raw (Box::new (node.clone ()))
    
    This means that in C, "x = rsvg_node_ref (y)" gives you back a pointer x
    that is different from y!  Both refer to the same Node in the Rust
    world, and after that the node has one more refcount, as expected.
    
    When we unref() a node, we expect you to call "x = rsvg_node_unref (x)".
    This returns NULL, so your x=NULL after that, i.e. the node that was in
    x is not accessible anymore.
    2477434b