[serialization] save_pointer_type::invoke - possible error

Hello, I'm developing custom polymorphic archive and noticed that virtual function save_null_pointer is never called for my archive. I think the problem is in save_pointer_type::invoke (boost/archive/detail/oserializer.hpp): const basic_pointer_oserializer * bpos_ptr = register_type(ar, * t); if(NULL == t){ basic_oarchive & boa = boost::smart_cast_reference<basic_oarchive &>(ar); boa.save_null_pointer(); save_access::end_preamble(ar); return; } save(ar, * t, bpos_ptr); I see no reasons to use smart_cast here. I think, the code sholud be: const basic_pointer_oserializer * bpos_ptr = register_type(ar, * t); if(NULL == t){ ar.save_null_pointer(); save_access::end_preamble(ar); return; } save(ar, * t, bpos_ptr); Please correct this in the next release of library (or explain).

save_null_pointer is not a virtual function and not meant to be overriden in the derived class. It is an implemenation detail. Hence the cast to the base class reference. You shouldn't have a function called save_null_pointer in your derived class. Look at the other polymorphic archives for examples. Robert Ramey Sergey Skorniakov wrote:
Hello, I'm developing custom polymorphic archive and noticed that virtual function save_null_pointer is never called for my archive.
I think the problem is in save_pointer_type::invoke (boost/archive/detail/oserializer.hpp):
const basic_pointer_oserializer * bpos_ptr = register_type(ar, * t); if(NULL == t){ basic_oarchive & boa = boost::smart_cast_reference<basic_oarchive &>(ar); boa.save_null_pointer(); save_access::end_preamble(ar); return; } save(ar, * t, bpos_ptr);
I see no reasons to use smart_cast here. I think, the code sholud be:
const basic_pointer_oserializer * bpos_ptr = register_type(ar, * t); if(NULL == t){ ar.save_null_pointer(); save_access::end_preamble(ar); return; } save(ar, * t, bpos_ptr);
Please correct this in the next release of library (or explain). _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

save_null_pointer is a pure virtual member function of polymorphic_oarchive and it is overriden in the polymorphic_oarchive_impl (at least, in 1.34.0 version of library). And this function is never called. Its misleading. I think that something should be changed - save_null_pointer should be removed from polymorphic_oarchive or smart_cast_reference from save_pointer_type::invoke, or, may be, both. "Robert Ramey" <ramey@rrsd.com> wrote in message news:fc912i$8m7$1@sea.gmane.org...
save_null_pointer is not a virtual function and not meant to be overriden in the derived class. It is an implemenation detail. Hence the cast to the base class reference. You shouldn't have a function called save_null_pointer in your derived class. Look at the other polymorphic archives for examples.
Robert Ramey
Sergey Skorniakov wrote:
Hello, I'm developing custom polymorphic archive and noticed that virtual function save_null_pointer is never called for my archive.
I think the problem is in save_pointer_type::invoke (boost/archive/detail/oserializer.hpp):
const basic_pointer_oserializer * bpos_ptr = register_type(ar, * t); if(NULL == t){ basic_oarchive & boa = boost::smart_cast_reference<basic_oarchive &>(ar); boa.save_null_pointer(); save_access::end_preamble(ar); return; } save(ar, * t, bpos_ptr);
I see no reasons to use smart_cast here. I think, the code sholud be:
const basic_pointer_oserializer * bpos_ptr = register_type(ar, * t); if(NULL == t){ ar.save_null_pointer(); save_access::end_preamble(ar); return; } save(ar, * t, bpos_ptr);
Please correct this in the next release of library (or explain). _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (2)
-
Robert Ramey
-
Sergey Skorniakov