Raising StopIteration in pygi-invoke


   I'm trying to give Python iterator capabilities to my C objects. I've
got already an object in my C library that is a container and I've got
also some C routines to iterate on that container.
   Using GI, I created a C routine that is named my_object___iter__(),
which only calls my own C iterator creation routine. Then, on this
iterator, I've created two routines called my_object_iter___iter__()
and my_object_iter_next() that gives Python iterator capabilities to
the bindings on my_object.
   It works in Python, except that the _next() routine must raise
StopIteration to fulfill its job. I added then a GError **error
argument to my _next() routine to be able to throw this exception. But
in pygi-invoke, there's currently no way to raise anything else than
PyExc_RuntimeError or PyExc_Exception. A TODO speaks of a way to use
the right domain, so I'm interested with its implementation. Would you
have some suggestions ?

   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:
/* Returns: (transfer none):*/
GtkTreeIter* gtk_list_store___iter__(GtkListStore *list)
   GtkTreeIter *iter = g_malloc(sizeof(GtkTreeIter));
   return iter;
/* Returns: (transfer none):*/
gpointer gtk_tree_iter_next(GtkTreeIter *iter,
                            GError **error)
   gpointer data;

   gtk_tree_model_get(iter->model, iter, 0, &data, NULL);
   if (gtk_tree_model_next(iter->model, iter))
     return data;
     *error = g_error_new(g_quark_from_static_string(StopIteration),
0, "");
   return NULL;
   Would someone may help me how to solve this, or point me to
resources with some information on how to bind C itrerators to Python
one using GI ?

   I can send more information if I'm not clear enough. If this
capability is not possible with current implementation, I'm interested
in providing patches to pygobject to help the project.



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