Re: Raising StopIteration in pygi-invoke


Le 30/08/2010, Damien Caliste <damien caliste cea fr> 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
( 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).


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