Re: GtkObject: double destroys



Hi Owen,

        So I guess as a first approximation I get to change all the
destroy overrides to 'finalize' overrides - since finalize can only be
invoked once(?) - and move any suspicious unref logic into a dispose /
destroy handler ?

        How does this sound as a section for the porting document, mostly
snarfed from your explanation, and expanded:

The "destroy" process:

        In Gtk+ 1.4 the object teardown process the "destroy" signal was
heavily overridden to hook up code that released state associated with the
object. This had several disadvantages:

        - It was poorly defined to start with; what could you do
          with a destroyed-but-not-finalized widget? What should
          go in destroy and what should go in finalize?

        - Nobody ever got it right (if a double destroy hurts
          you now, well, then method calls against the object
          in the destroyed state will segfault you.)

        - It was an easy way to segfault a language binding.

        So, in Gtk+ 2.0 the semantics of the destroy signal have been
altered. In the new scheme 'finalize' is called a single time, but destroy
may be called multiple times, as objects release references to each other.

        Consequently as you port to Gtk+ 2.0 you should convert many
GtkObject 'destroy' overrides to GObject 'finalize' overrides. However if
you have reference management code you need to split it out and leave it
in the destroy method.

        This new scheme has many advantages, we:

        - remove the idea of having an "invalid" state for a widget,
          which makes things easier for the user of the widget.

        - remove the need for widget writers to feel guilty about
          not checking GTK_WIDGET_DESTROYED() all over the place.

        In summary, in Gtk+ 2.0

        'destroy'  - reset the state of the widget to the point
                     where it no longer has references to external object
                     leaving the widget in a valid state.

        'finalize' - free all memory.

        Currently all GtkObjects are destroyed twice as a debugging tool
to encourage adoption of the new semantics. Thus the symptoms of not
fixing this will often be a segfault on a 'free' in a destroy method. To
best catch these tty export MALLOC_CHECK_=2 to turn on glibc memory
debugging.

> Yeah, this looks like a leftover comment. The actual ref/unref is in
> g_object_run_dispose. Feel free to commit a removal of the comment.

        Just did that; ta.

> If you want to do a writeup of this, the best place is probably in a
> section about converting GTK+-1.2 widgets in Havoc's 'intro to
> GTK+-2.0' document.

        Would the above be suitable Havoc ? - mainly I wrote it to test my
understanding by fire before I go hack gal a whole lot.

        Thanks,

                Michael.

-- 
 mmeeks gnu org  <><, Pseudo Engineer, itinerant idiot





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