GTK_WINDOW(NULL) (WAS: more patches)



Owen Taylor <otaylor redhat com> writes:
> > +  if (entry->activate_default)
> > +    {
> > +      window = (GtkWindow *) gtk_widget_get_toplevel (widget);
>
> Here, I agree 100% with Tim that this should be
> GTK_WINDOW (gtk_widget_get_toplevel (widget)).

Havoc Pennington replied:
> That would be wrong, because there's no guarantee that get_toplevel()
> even returns a GtkWindow. ;-) The problem is confusion on my part
> about what get_toplevel() does. I was taking it to be the same as
> get_ancestor(GTK_TYPE_WINDOW) (even though just a couple weeks ago I
> documented get_toplevel() with a special note that it was not
> equivalent to get_ancestor (GTK_TYPE_WINDOW), my memory is short ;-)

> So using (GtkWindow *) there was deliberate, to handle the NULL return
> case I thought existed. The issue is whether the pointer can be NULL,
> not which kind of cast is conventional.

What if GTK_WINDOW() and friends returned NULL when they are passed
NULL?

It seems that passing a NULL in place of a widget pointer is a common
thing. And casting a NULL is generally a safe operation. I realize that
the casting macros also check for the object type, but in many
situations a NULL object is considered to be a member of any type.

Or would such a change break existing code or propogate errors?

Craig M. Buchek




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