From: Axel S. <A....@ke...> - 2003-10-26 17:51:03
|
On Sun, Oct 26, 2003 at 01:49:56AM +0100, Duncan Coutts wrote: > On Thu, 2003-10-23 at 09:04, Axel Simon wrote: > > On Wed, Oct 22, 2003 at 02:59:45PM +0100, Duncan Coutts wrote: > > > All, > > > > > > GtkSourceStyleScheme inherits from GInterface. I've not come across this > > > anywhere else. Any ideas? > [snip] > > > I could just ignore the fact that it has a base class. > > > > Yes, ignore. > > Ok, but as far as memory management goes we have to treat it as a > GObject. As far as I can tell anything implementing a GInterface must be > a GObject. On the other hand I've found this bit of code in the > GtkSourceView bindings that doesn't seem to follow this rule. I'm not > sure if this is a bug in their code, or if I haven't understood what's > going on properly. I think that GtkSourceStyleScheme is a normal object that doesn't have any (non-static) members, hence there is no struct representing an instance of this class. So form that point of view GtkSourceStyleScheme is derived form GObject. > Here's the snippet: > > GtkSourceStyleScheme * > gtk_source_style_scheme_get_default (void) > { > if (default_style_scheme == NULL) > { > /* snip - use g_object_new to create default_style_scheme */ > } > else > g_object_ref (default_style_scheme); > > return default_style_scheme; > } > > So, assuming the global var default_style_scheme has been initialised, > then each time we call this function it is going to increment the > reference count. But I thought that when we got a reference to an object > we have to g_object_ref it ourselves - this is what makeNewGObject does. Yes, I would say the C code is buggy. Especially since the "/* snip..." part creates an object and adds a weak reference to it which says "this is an object with refcount 0 that should be kept alive". Perhaps you should report it as a bug. > So if I define: > > sourceStyleSchemeGetDefault :: IO SourceStyleScheme > sourceStyleSchemeGetDefault = > makeNewGObject mkSourceStyleScheme $ > {#call source_style_scheme_get_default#} > > then it is going to leak a reference per call. :-( The C code should be fixed. But of course you can build an autoconf test... Axel. |