Re: [xml] list deallocator problem



Aleksey Sanin wrote:

Hi, All!

I am trying to use xmlList declared in list.h and I found a small
problem with it. The xmlListDeallocator is declared in list.h as follows:
    typedef void (*xmlListDeallocator) (xmlLinkPtr lk);
i.e. it expects a pointer to xmlLink structure. However, the xmlLink structure itself is declared inside list.c and by this it is not accessible to the custom
list data deallocator. I would suggest to do following changes:

    1) change the declaration of xmlListDeallocator in list.h to

    typedef void (*xmlListDeallocator) (void *data);

    2) change the implementation of xmlLinkDeallocator() in link.c
    from

    /**
     * xmlLinkDeallocator:
     * @l:  a list
     * @lk:  a link
     *
     * Unlink and deallocate @lk from list @l
     */
    static void
    xmlLinkDeallocator(xmlListPtr l, xmlLinkPtr lk)
    {
        (lk->prev)->next = lk->next;
        (lk->next)->prev = lk->prev;
        if(l->linkDeallocator)
            l->linkDeallocator(lk);
        xmlFree(lk);
    }

    to

    /**
     * xmlLinkDeallocator:
     * @l:  a list
     * @lk:  a link
     *
     * Unlink and deallocate @lk from list @l
     */
    static void
    xmlLinkDeallocator(xmlListPtr l, xmlLinkPtr lk)
    {
        (lk->prev)->next = lk->next;
        (lk->next)->prev = lk->prev;
        if(l->linkDeallocator && lk->data)
            l->linkDeallocator(lk->data);
        xmlFree(lk);
    }


Aleksey.








Hi,

What's the problem? You can use xmlLinkGetData() to get at the data held by the link and that's all you should need access to. I don't think any changes are required.

e.g.

In your deallocator
{
...
void * data = xmlLinkGetData(lk);
<do whatever you want with data, probably just free it>
}

Gary

--
Gary Pennington
Solaris Kernel Development,
Sun Microsystems
Gary Pennington sun com






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