[multi_index][serialization] save_construct_data not called for multi_index collection

Hi, Boost.Serialization has support for non-default classes using save_construct_data and load_construct_data overloads. These are called before serialization to save and load information that's important for the construction of the object. Unfortunately, multi_index doesn't call these functions when serializing, so serialization of non-default-constructible classes is impossible with multi_index. I wanted to patch it so that it becomes possible, but to be honest I'm a bit lost in the serialization code for multi_index. collections_save_impl calls boost::serialization::save_construct_data_adl before serializing each item in the collection. I'm using boost 1.38.0, is there anyway to do the same for multi_index? Thanks in advance, -- Felipe Magno de Almeida

Felipe Magno de Almeida escribió:
Hi,
Boost.Serialization has support for non-default classes using save_construct_data and load_construct_data overloads. These are called before serialization to save and load information that's important for the construction of the object. Unfortunately, multi_index doesn't call these functions when serializing, so serialization of non-default-constructible classes is impossible with multi_index.
Hi, seems you spotted a bug here. load_construct_data_adl is actually used (see boost/multi_index/detail/archive_constructed.hpp ), but this is not the case for save_construct_data_adl, which is also necessary. I'll fix this. I'd appreciate if you can file a ticket in the Trac system. Meanwhile you can try your hand patching boost/multi_index_container.hpp: lines 646-647 (in 1.41, some offset might occur in 1.38) look like for(iterator it=super::begin(),it_end=super::end();it!=it_end;++it){ ar<<serialization::make_nvp("item",*it); save_construct_data_adl should be called before "ar<<..." with *it. Please report back about your success or lack of it. Thank you for using Boost.MultiIndex. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

joaquin@tid.es escribió:
Felipe Magno de Almeida escribió:
Hi,
Boost.Serialization has support for non-default classes using save_construct_data and load_construct_data overloads. These are called before serialization to save and load information that's important for the construction of the object. Unfortunately, multi_index doesn't call these functions when serializing, so serialization of non-default-constructible classes is impossible with multi_index.
Hi, seems you spotted a bug here. load_construct_data_adl is actually used (see boost/multi_index/detail/archive_constructed.hpp ), but this is not the case for save_construct_data_adl, which is also necessary.
I'll fix this.
Can you please check whether https://svn.boost.org/trac/boost/changeset/58485/ solves your problem? Thank you, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

On Tue, Dec 22, 2009 at 5:23 AM, <joaquin@tid.es> wrote:
joaquin@tid.es escribió:
[snip]
I'll fix this.
Can you please check whether
https://svn.boost.org/trac/boost/changeset/58485/
solves your problem? Thank you,
Yes it does. Worked flawlessly. Thanks!
Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
-- Felipe Magno de Almeida

On Tue, Dec 22, 2009 at 12:52 PM, Felipe Magno de Almeida <felipe.m.almeida@gmail.com> wrote:
On Tue, Dec 22, 2009 at 5:23 AM, <joaquin@tid.es> wrote:
joaquin@tid.es escribió:
[snip]
I'll fix this.
Can you please check whether
https://svn.boost.org/trac/boost/changeset/58485/
solves your problem? Thank you,
Yes it does. Worked flawlessly.
Sorry, now repatching another version I see your patch doesn't seem right. You're passing the version of multi_index_container serialization to save_construct_data_adl. Which should get boost::serialization::version<T>::value. Where T is iterator::value_type.
Thanks!
Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
Regards, -- Felipe Magno de Almeida

Felipe Magno de Almeida <felipe.m.almeida <at> gmail.com> writes:
On Tue, Dec 22, 2009 at 12:52 PM, Felipe Magno de Almeida <felipe.m.almeida <at> gmail.com> wrote:
On Tue, Dec 22, 2009 at 5:23 AM, <joaquin <at> tid.es> wrote:
joaquin <at> tid.es escribió:
Can you please check whether
https://svn.boost.org/trac/boost/changeset/58485/
solves your problem? Thank you,
Yes it does. Worked flawlessly.
Sorry, now repatching another version I see your patch doesn't seem right. You're passing the version of multi_index_container serialization to save_construct_data_adl. Which should get boost::serialization::version<T>::value. Where T is iterator::value_type.
Yep, you're right. But I've taken a look at the collection serialization code in Boost.Serialization and I don't quite grasp all the stuff there with respect to the version number. I'll post a request for info. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

Joaquin M Lopez Munoz <joaquin <at> tid.es> writes:
Felipe Magno de Almeida <felipe.m.almeida <at> gmail.com> writes:
Sorry, now repatching another version I see your patch doesn't seem right. You're passing the version of multi_index_container serialization to save_construct_data_adl. Which should get boost::serialization::version<T>::value. Where T is iterator::value_type.
Yep, you're right. But I've taken a look at the collection serialization code in Boost.Serialization and I don't quite grasp all the stuff there with respect to the version number. I'll post a request for info.
Hi Felipe, I still haven't received an answer to my question about Boost.Serialization, so, given the sensible nature of serialization code, where you must deal with coding errors even after the code itself has been fixed, I've reverted the change from release for the moment being. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

Joaquin M Lopez Munoz wrote:
Hi Felipe, I still haven't received an answer to my question about Boost.Serialization, so, given the sensible nature of serialization code
lol - thank you for such a charitable characterization. Robert Ramey

Joaquin M Lopez Munoz escribió:
Felipe Magno de Almeida <felipe.m.almeida <at> gmail.com> writes:
On Tue, Dec 22, 2009 at 12:52 PM, Felipe Magno de Almeida <felipe.m.almeida <at> gmail.com> wrote:
On Tue, Dec 22, 2009 at 5:23 AM, <joaquin <at> tid.es> wrote:
joaquin <at> tid.es escribió:
Can you please check whether
https://svn.boost.org/trac/boost/changeset/58485/
solves your problem? Thank you,
Yes it does. Worked flawlessly.
Sorry, now repatching another version I see your patch doesn't seem right. You're passing the version of multi_index_container serialization to save_construct_data_adl. Which should get boost::serialization::version<T>::value. Where T is iterator::value_type.
Yep, you're right. But I've taken a look at the collection serialization code in Boost.Serialization and I don't quite grasp all the stuff there with respect to the version number. I'll post a request for info.
Hi again Felipe, I thoroughly studied the matter and I think I got it right now, value_type serialization class versioning should be handled right now. Could you please take a look at https://svn.boost.org/trac/boost/changeset/59443 and report if everything's now OK on your side? Thank you, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
participants (4)
-
Felipe Magno de Almeida
-
Joaquin M Lopez Munoz
-
joaquin@tid.es
-
Robert Ramey