GObject in GC implementation Plan

Daniel Espinosa esodan at gmail.com
Thu Apr 5 03:55:09 EDT 2007


2007/4/4, Derek Atkins <warlord at mit.edu>:
> "Daniel Espinosa" <esodan at gmail.com> writes:
>
> >> > You need to remove g_free and the end of the object destruction, and
> >> > keep qof_instance_release to call there g_object_unref.
> >>
> >> Why?   Why do we still need qof_instance_release()?  Can't that
> >> work be done in the finalize() call of the GObject?
> >>
> >> I would think that we could just change g_free() to g_object_unref()
> >> and let the qof_instance_release() code get executed from within the
> >> unref calls.  Is this NOT the case?  Why wouldn't that work?
>
> Daniel, could you please answer this question.  I do want to make
> sure that I'm not missing something.
>

You can't if becouse if you want to leave much of the code with out
modification you need to call qof_instance_release() as is. if you
don't do so you must move the code or register a function that made
the work.

More clear: a GObject must register a function for init, class_init
and finalize, then when you call g_object_ref and g_object_unref this
functions will be called; but for the actual code you don't want that
I have done in the gobjec-engine-dev, you want to keep the actual
construction/destruction method, then keep qof_instance_release and at
the end of this function call g_object_unref.

If you want a GObject to be g_object_new and g_object_unref
compatible, you must register this functions and "move" the code you
have now to this functions; but again you don't want to move much code
and change the things I've done.

> >> My next commit to the branch will convert QofInstance to actually
> >> using GObject, but this will break the build until I get everything
> >> converted.
> >>
> >
> > THANKS! If you're working on this project is great and way to advance
> > more quickly.
>
> Indeed.  Take a look at my work so far:
>
> http://svn.gnucash.org/trac/log/gnucash/branches/gobject-engine-dev-warlord
>
> You'll need to follow the link to the originating branch for my
> first few commits.  I put the branch in the wrong place at first.
> But take a look.  I required very few changes to actually get
> QofInstance to use GObject directly..  I required a few more
> changes for QofBook and to get the interactions to work, but once
> I got those worked out I got libqof to build pretty quickly.
>
> > But you know more about QOF that any other in the project; you need to
> > try to do the changes your selft and find why it's so dificult and
> > maybe a lossed time to work in convert QOF in a PURE GObject over
> > time.
>
> I still don't think it's as difficult as you think, which is why
> I'm doing it myself to PROVE to you that I'm right.
>
> > I don't think this is necessary or required, I think this is a
> > convenient way to go.
> >
> > See my next email about the new library.
>
> I agree with Josh in reply to this idea.  I think it's a waste of
> your time.  It's adding an abstraction that we just don't need.
>

I have seen your code in the branch and I found that you aren't
following the code conventions to create a GObject, and let me say if
you don't follow it will be dificult to understand your work for
others that knows some thing about GObject.

You can find an squeleton to create a GObject (taken from the one in
Anjuta) in gobject-engine-dev, each objects define the functions to a
correct construction/destruction, but you don't want to move the code
jet.

Then you must, in order to change a just little code:

Initialization Process:
* Change g_new with g_object_new, and keep the init process for the
object you are working on (i.e. Account)
* Keep qof_instance_init, and call it

Keep in mind that the QofInstance init must be called inmediatly after
called g_object_new in order to keep the same process as if the object
calls the registered function.

Destroying Process:

* Remove g_free
* Keep qof_instance_release and make shure you destroy the QofInstance
in this call and at the end call g_object_unref

Keep in mind that you must destroy the derived class before call
qof_instance_release() and destroy the QofInstance member before call
g_object_unref.

you can the the gobject-engine-dev for examples.

-- 
Trabajar, la mejor arma para tu superación
"de grano en grano, se hace la arena" (R) (entrámite, pero para los
cuates: LIBRE)



More information about the gnucash-devel mailing list