GTK_OBJECT_DESTROYED



Earlier today I was discussing outstanding API issues with Tim and he
mentioned that GTK_OBJECT_DESTROYED() should be at least deprecated
and possible removed entirely.

In GTK+-1.2, GTK_OBJECT_DESTROYED() was used to check whether
gtk_object_destroy() had previously been called. In theory, almost
every widget method should have looked like:

  void
  mywidget_frobate (MyWidget *widget)
  {
    if (GTK_OBJECT_DESTROYED (widget))
      return;
  }

Obviously, almost nobody did this. In GTK+-2.0 the ::destroy signal no
longer should put a widget to a in a "destroyed" state; instead it
resets the widget to a valid, but disconnected state.

GTK+ now internally sets the DESTROYED flag before calling ::destroy
to catch recursie calls to gtk_widget_destroy(), but then clears it
after the emission is done.

Checking the DESTROYED flag is then not useful any more, but worse
uses of GTK_OBJECT_DESTROYED() probably indicates code that is
assuming that it can detect whether the object has been previously
been destroyed with this flag.

Basically, uses of GTK_OBJECT_DESTROYED() probably indicate one of two
things:

 a) The caller wants to make sure they don't accidentally 
    segfault the object by trying to access freed memory
    or other no longer valid state in the widget.

 b) The caller wants to do something different based 
    on whether the object has been destroyed or not.

Just deprecating it works fine if everything was a), but may introduce
subtle, hard to find bugs for cases of b).  If we remove it entirely,
people will have to clean up any uses of this macro, but hopefully
will fix any bugs in the process.

We aren't really talking about many uses -- maybe a 50 total in GNOME
CVS outside of GTK+/GLE/Beast; probably under 20 in GNOME-2.0
components

Unfortunately, these uses usually seem to be in places where people
had reentrancy problems, couldn't figure out what was going on and
added GTK_OBJECT_DESTROYED() as a band-aid. In the few I've looked at,
it is not at all obvious whether GTK_OBJECT_DESTROYED() doing nothing
presents a problem or not.

So, if you've used GTK_OBJECT_DESTROYED(), I'd appreciate it if you'd
take a look back at your code and see what's the case for that usage.

My basic opinion is that we probably should remove this macro
entirely...  I wouldn't trust any code that was using
GTK_OBJECT_DESTROYED() now unless I had carefully checked through it
and figured out why it was being used. Leaving it there and
non-functional is just turning an immediate painful code reading task
into a delayed but even more painful task in debugging.

I'd be interested in hearing other opinions, however.

Regards,
                                        Owen



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