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.
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.My solution is to keep track of whether the internal pointer is "owned". If it was created via
new
orcopy
, it will be dropped like usual. If it is created viawrap_pointer
, it will not be dropped. This should allow us to wrap system-provided pointers without accidentally freeing them afterwards.