Hello,

Le 30/08/2010, Damien Caliste <[email protected]> a écrit :
>    Besides, I've got another issue about the iterators. I'll give
> an example with GtkListStore and GtkTreeIter to be clear.
>    The following code is working well except that it has a memory
> leak:
Ok, I've found my mistake and how to properly use the annotations. For
the records and if someone has the same interrogations, the proper
solution is to write:

> /* Returns: (transfer none):*/
> GtkTreeIter* gtk_list_store___iter__(GtkListStore *list)
> {
>    GtkTreeIter *iter = g_malloc(sizeof(GtkTreeIter));
>    return iter;
> }
/* @iter: (out caller-allocates): */
void gtk_list_store___iter__(GtkListStore *list, GtkTreeIter *iter)
{
[...]
}
which will indeed create a Python routine like that:
iter = gtk.list_store.__iter__()

And the Python __iter__() routine on the iter itself
(http://docs.python.org/library/stdtypes.html) should be:
/* @out: (out caller-allocates): */
void gtk_tree_iter___iter__(GtkTreeIter *iter, GtkTreeIter *out)
{
  *out = *iter;
}

Like that, there's no memory leak and the iteration interface in Python
works well (except for the StopIteration issue).

Damien.
_______________________________________________
pygtk mailing list   [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Reply via email to