Boost logo

Boost Users :

From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2006-12-01 19:03:05


alexmark wrote:
> Hi to all!
>
> For the container type
>
> boost::interprocess::list<T, A> I
>
> need the destructor of stored object T be called when erase() is called for a corresponding list item. By default the T destructor is not called, memory only is deallocated. What is the correct way to force boost::interprocess::list to invoke destructors for contained objects while list item or the container itself is deleted?
>
> TYA.

Hi,

I've reviewed the code from the list.hpp CVS and I see that erase is
written as:

    iterator erase(const_iterator position)
    {
       NodePtr next_node = position.get_ptr()->m_next;
       NodePtr prev_node = position.get_ptr()->m_prev;
       NodePtr node = position.get_ptr();
       prev_node->m_next = next_node;
       next_node->m_prev = prev_node;
       AllocHolder::destroy_node(node);
       --this->m_size;
       return iterator(next_node);
    }

And

       AllocHolder::destroy_node(node);

is written as:

    void destroy_node(NodePtr node)
    {
       if(!node_has_trivial_destructor){
          self_t::destroy(node);
       }
       NodeAlloc::deallocate(node, 1);
    }

in theory, if the node has trivial destructor, the destructor shouldn't
be called. but this "node_has_trivial_destructor" is:

    enum {
       node_has_trivial_destructor =
          boost::has_trivial_destructor<NodePtr>::value |
          boost::has_trivial_destructor<T>::value
    };

which I think is wrong since it should be

    enum {
       node_has_trivial_destructor =
          boost::has_trivial_destructor<NodePtr>::value &&
          boost::has_trivial_destructor<T>::value
    };

that is, the node pointer should have trivial destructor AND the value
should have trivial destructor. Otherwise, the destructor is wrongly
ignored.

I've uploaded the change to CVS. You can change your list.hpp code to
see if this works. The same bug is present in slist.hpp. Thanks for the
bug report!

Regards,

Ion


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net