jeremyletang / rgtk

GTK+ bindings and wrappers for Rust (DEPRECATED SEE https://github.com/rust-gnome )
GNU Lesser General Public License v3.0
121 stars 22 forks source link

Don't drop TreeIter created by wrap_pointer #187

Closed oakes closed 9 years ago

oakes commented 9 years ago

I noticed a problem when I wanted to use the RowExpanded and RowCollapsed signals with my TreeView. It provides a raw C_GtkTreeIter pointer, so I have to wrap it. Since TreeIter implements Drop, it will free the pointer at the end of the closure, which we do not want since it is a pointer we didn't create.

tree.connect(gtk::signals::RowExpanded::new(&mut |&mut: iter_raw, tree_path| {
    let iter = gtk::TreeIter::wrap_pointer(iter_raw);
    // iter_raw will be freed
}));

My solution is to keep track of whether the internal pointer is "owned". If it was created via new or copy, it will be dropped like usual. If it is created via wrap_pointer, it will not be dropped. This should allow us to wrap system-provided pointers without accidentally freeing them afterwards.

GuillaumeGomez commented 9 years ago

Thanks for that ! I merge it.