Ticket #3080: shared_ptr_mlt_inh.patch

File shared_ptr_mlt_inh.patch, 2.0 KB (added by Takatoshi Kondo <kondo@…>, 13 years ago)

patch to solve this problem

  • shared_ptr_helper.hpp

     
    126126
    127127        if(it == m_pointers->end()){
    128128            s.reset(r);
    129             m_pointers->insert(collection_type::value_type(od,s));
     129            // make shared_ptr.
     130            // data member pn of shared_ptr sp shared with s,
     131            // but data member px of shared_ptr sp is od.
     132            shared_ptr<void> sp(s, const_cast<void *>(od)); // aliasing
     133            // insert shared_ptr of the most derived object into m_pointers.
     134            m_pointers->insert(collection_type::value_type(od,sp));
    130135        }
    131136        else{
    132             s = static_pointer_cast<T>((*it).second);
     137            const boost::serialization::extended_type_info * true_type
     138                = boost::serialization::type_info_implementation<T>::type
     139                    ::get_const_instance().get_derived_extended_type_info(*r);
     140            if(NULL == true_type)
     141                boost::serialization::throw_exception(
     142                    boost::archive::archive_exception(
     143                        boost::archive::archive_exception::unregistered_class
     144                    )
     145                );
     146            const boost::serialization::extended_type_info * this_type
     147                = & boost::serialization::type_info_implementation<T>::type
     148                        ::get_const_instance();
     149            // get this type pointer from pointer to the most derived object.
     150            void * vp = void_upcast(
     151                *true_type,
     152                *this_type,
     153                (*it).second.get()
     154            );
     155            // make and set shared_ptr.
     156            // data member pn of shared_ptr s shared with (*it).second,
     157            // but data member px of shared_ptr s is vp.
     158            s = shared_ptr<T>((*it).second, static_cast<T *>(vp)); // aliasing
    133159        }
    134160    }
    135161    void append(const boost_132::shared_ptr<void> & t){