Re: why no gtk_tree_iter_new()?



Murray Cumming wrote:

I notice that functions such as gtk_tree_store_new() take pointers to
allocated, but unset, GtkTreeIters, so in gtk-demo/main.c you have to do
this:

GtkTreeIter iter;
...
gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);


Isn't there a risk that someone could end up calling
gtk_tree_iter_free() on this. And if there is a gtk_tree_iter(),
shouldn't there be a matching gtk_tree_iter_new(), which could also zero
the struct memory to avoid undefined behaviour.

The tree iter filled in by gtk_tree_store_append is owned by the caller. It is responsible for freeing it (if necessary). Unlike iters allocated on the heap, you can't really transfer ownership of an iter allocated on the stack. This is no more dangerous than the possibility of a program calling free() on an object it allocated on the stack.

If you are wondering about how to wrap the function, in python all functions that logically create GtkTextIters or GtkTreeIters, I changed them to return the iter, rather than taking a reference to it as an argument. This may be appropriate for the C++ binding as well.

James.

--
Email: james daa com au
WWW:   http://www.daa.com.au/~james/







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