Some questions about Gobject based classes

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

 



-----BEGIN PGP SIGNED MESSAGE-----Hash: SHA1
Hi,
I'm working on the gobject class model and wanted to implement a (trivial) class based on gobject, but I still have somequestions:
I'm working with the book "GNOME 2.0, Das Entwicklerhandbuch" (Developers manual) by Matthias Warkus (I don't know ifthis book has an english translation) and I've been also reading the GObject Reference Manual as well. I understandalmost everything but there are some issues about freeing memory of objects insied a class structure that I don't really understand at all.
I have a simple class called GtestMedium:
typedef struct _GtestMedium GtestMedium;typedef struct _GtestMediumClass GtestMediumClass;

struct _GtestMedium {    GObject  g_obj;
    GString  *place;    GString  *title;    /* properties */    guint    archiv_nr;    gboolean orig_pack;};

struct _GtestMediumClass {    GObjectClass g_obj_class;
    /* signals */    void (*unpacking)(GtestMedium *medium);    void (*dispose)(GtestMedium *medium,                    gboolean    definitely);};

archiv_nr & orig_pack are already declared as properties, I can set and get them with g_object_set/get without problems.I want to declare 'place' and 'title' as properties as well:
g_object_set(medium, "title", "ABC...", NULL);
'place' and 'title' are GString objects and have to be freed with g_string_free. I don't know where I have to do that.gtest_medium_get_type looks like:
GType gtest_medium_get_type(void){    static GType medium_type = 0;
    if(medium_type == 0)    {        const GTypeInfo medium_info =        {            sizeof(GtestMediumClass),    /* size of MediumClass */            NULL,                        /* base init */            NULL,                        /* base finalize */            (GClassInitFunc)                gtest_medium_class_init, /* class init */            NULL,                        /* class finalize */            NULL,                        /* class data */            sizeof(GtestMedium),         /* size of Medium */            16,                          /* 16 pre allocs */            NULL                         /* instance init */            /* skip value_table */        };
        medium_type = g_type_register_static(G_TYPE_OBJECT,                "GtestMedium",                &medium_info,                0);
        g_printf("DEBUG: Hello GOBJECT World %d\n", medium_type);    }
    return medium_type;}

I've written a trivial gtest_medium_class_finalize function
static void gtest_medium_class_finalize(GtestMediumClass *klass){    g_printf("bye bye\n");}
but if change the class finalize member (of GTypeInfo) from NULL to (GClassFinalizeFunc) gtest_medium_class_finalizethen nothing works afterwards:
$ ./test(process:15609): GLib-GObject-WARNING **: class finalizer specified for static type `GtestMedium'DEBUG: Hello GOBJECT World 0...
So, where can I free the memory of 'place' and 'title'?
* * *
Both in my book and in the GObject Reference Manual the class_init function is declared as  void function_name(Klassname *ptr);although the GClassInitFunc expects two pointers instead of one. Why does this work? I had once something similar: I hada function pointer that took 4 parameters and a couple of functions that could be assigned to but the choice could beonly be made on runtime. After some time one of those functions changed and expcted 5 instead of 4 parameters. I didn'trealize that at first but then my applications crashed and valgrind always told me about branches that were taken onuninitialized variables, after some hours spent with debuggin I realized that the stacked was corruped beacause of thisfunction that execped 5 parameter but got only 4 (through the casted function pointer). This is more or less the samecase, that's why I ask myself: why does it work here?
thankregardsPablo

- --Pablo Yánez Trujillohttp://klingsor.informatik.uni-freiburg.de/My public key: http://klingsor.informatik.uni-freiburg.de/gpg/supertux.asc-----BEGIN PGP SIGNATURE-----Version: GnuPG v2.0.9 (GNU/Linux)
iEYEARECAAYFAkkQ6Y4ACgkQDzf8xo+0xRWzsgCcCZ8KrGEKvPd5F998pzFmfqz0z7QAoJvvdaTW9PbRPNvoEM3ymOzVx5ER=2WYN-----END PGP SIGNATURE-----_______________________________________________gtk-list mailing listgtk-list@xxxxxxxxxxxxx://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux