[gdome]Re: [Gmetadom-ocamldev] Gdome providing free()



Luca Padovani wrote:
> 
> On Sat, 2003-03-15 at 22:34, Blair Zajac wrote:
> > Shouldn't gdome2 provide its own version of free() to free memory that
> > is allocated in libxml2 and gdome2 and passed to the calling code?
> > This free would basically be wrappers around libxml2's memory
> > allocation routines.
> 
> Gdome2 provides its own mechanism for memory management which is based
> on reference counting. As far as I remember, there is _never_ the need
> to use free on any Gdome2 data structures. You always have to do _unref
> and the structure gets automatically deallocated if that was the last
> live reference to it.
> 
> I don't think there is any piece of libxml2 data that goes through
> Gdome2 directly to the user code.

I'm not too certain about that, but maybe I'm missing something.

Here's gdome_di_saveDocToMemory:

GdomeBoolean
gdome_di_saveDocToMemory (GdomeDOMImplementation *self, GdomeDocument *doc,
char **mem, int *mem_length, GdomeSavingCode mode, GdomeException *exc)
{
        if (self == NULL) {
                *exc = GDOME_NULL_POINTER_ERR;
                return FALSE;
        }
        *exc = 0;
        return ((Gdome_xml_DOMImplementation *)self)->vtab->saveDocToMemory
                 (self, doc, mem, mem_length, mode, exc);
}

This doesn't appear to do anything with the char *mem.

This function calls struct _GdomeDOMImplementationVtab's saveDocToMemory,
which is a function pointer that looks like it's initialized to point to
gdome_xml_di_saveDocToMemory.  This function is pretty short 

GdomeBoolean
gdome_xml_di_saveDocToMemory (GdomeDOMImplementation *self, GdomeDocument *doc,
                              char **mem, int *mem_length,
                              GdomeSavingCode mode, GdomeException *exc)
{
        Gdome_xml_Document *priv_doc = (Gdome_xml_Document *)doc;

        g_return_val_if_fail (self != NULL, FALSE);
        g_return_val_if_fail (doc != NULL, FALSE);
        g_return_val_if_fail (mem != NULL, FALSE);
        g_return_val_if_fail (mem_length != NULL, FALSE);
        g_return_val_if_fail (exc != NULL, FALSE);
        g_assert(self == (GdomeDOMImplementation *)gdome_xml_DOMImplementation);

        xmlDocDumpFormatMemory(priv_doc->n, (xmlChar **)mem, mem_length, mode);
        if ((mem == NULL) && (*mem_length > 0))
                return FALSE;
        else
                return TRUE;
}

Here, there's nothing done to mem.  It's returned directly from
xmlDocDumpFormatMemory, which is from libxml2.

Now, perhaps gdome2 installs its own memory allocator into libxml2, but
that would need to call xmlMemSetup, but doing a recursive grep through
gdome2 doesn't show any calls to it.

Best,
Blair

-- 
Blair Zajac <blair orcaware com>
Plots of your system's performance - http://www.orcaware.com/orca/



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