Re: warning about invalid tree model iterators



On Fri, 2006-02-17 at 11:01 -0600, Federico Mena Quintero wrote:
> On Fri, 2006-02-17 at 14:29 +0100, Tim Janik wrote:
> 
> 
> > to help the compiler catch these mistakes, i've prepared a patch that adds
> > G_GNUC_WARN_UNUSED_RESULT to all relevant iterator functions, and intend
> > to commit that next week unless objections pop up. in principle it does:
> 
> This is pretty nice.  It may create a few warnings for code that knows
> that certain operations will succeed, but better help the rest of the
> world :)

Can we see some examples of code that was broken and what it should be
doing? 

It sounds like you are saying that if I do:

 /* prepend a row at the beginning of the list */

 /* prepend another row to the beginning of the list */

 /* Do something with the returned iterator */

 /* Advance the iterator one row */

[ Yes, this is obviously artificial, but I can't think of a real 
  reason for   calling iter_next() not in a loop at the moment ]

You think I should write:

 if ((!gtk_tree_model_iter_next(model, iter)) { 
     /* do something */
 }

But what "do something" could I possibly do? About all I can think
of to insert in there is g_assert_not_reached();

This seems a little similar to making gtk_widget_show() return 
a boolean value that you are supposed to check because you might
have passed in a NULL pointer for the widget.

Regards,
						Owen





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